|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Pantheon\Terminus\Tests\Functional; |
| 4 | + |
| 5 | +use Pantheon\Terminus\Hooks\Interacter; |
| 6 | +use Symfony\Component\Console\Input\ArgvInput; |
| 7 | +use Pantheon\Terminus\Config\TerminusConfig; |
| 8 | + |
| 9 | + |
| 10 | +/** |
| 11 | + * Class InteracterHookTest |
| 12 | + * |
| 13 | + * @package Pantheon\Terminus\Tests\Functional |
| 14 | + */ |
| 15 | +class InteracterHookTest extends TerminusTestBase |
| 16 | +{ |
| 17 | + |
| 18 | + /** |
| 19 | + * @var Pantheon\Terminus\Hooks\Interacter |
| 20 | + */ |
| 21 | + protected $interacter; |
| 22 | + |
| 23 | + /** |
| 24 | + * @inheritdoc |
| 25 | + * |
| 26 | + * @throws \Exception |
| 27 | + */ |
| 28 | + protected function setUp(): void |
| 29 | + { |
| 30 | + $this->interacter = new Interacter(); |
| 31 | + $config = new TerminusConfig(); |
| 32 | + $this->interacter->setConfig($config); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @test |
| 37 | + * @covers \Pantheon\Terminus\Hooks\Interacter |
| 38 | + * |
| 39 | + * @group interacter |
| 40 | + * @group short |
| 41 | + */ |
| 42 | + public function testIsInteractive() |
| 43 | + { |
| 44 | + $input = new ArgvInput(['--interactive']); |
| 45 | + $interactive = $this->interacter->isInteractive($input); |
| 46 | + $this->assertTrue($interactive, 'The input should be interactive.'); |
| 47 | + |
| 48 | + $config = new TerminusConfig(); |
| 49 | + $config->set('disable_interactive', true); |
| 50 | + $this->interacter->setConfig($config); |
| 51 | + $input = new ArgvInput(); |
| 52 | + $interactive = $this->interacter->isInteractive($input); |
| 53 | + $this->assertFalse($interactive, 'The input should not be interactive.'); |
| 54 | + |
| 55 | + // Reset the config to default |
| 56 | + $config->set('disable_interactive', false); |
| 57 | + $input = new ArgvInput(); |
| 58 | + $this->interacter->setConfig($config); |
| 59 | + $interactive = $this->interacter->isInteractive($input); |
| 60 | + $this->assertTrue($interactive, 'The input should be interactive.'); |
| 61 | + |
| 62 | + putenv("CI=true"); |
| 63 | + $input = new ArgvInput(); |
| 64 | + $interactive = $this->interacter->isInteractive($input); |
| 65 | + $this->assertFalse($interactive, 'The input should not be interactive.'); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @test |
| 70 | + * @covers \Pantheon\Terminus\Hooks\Interacter |
| 71 | + * |
| 72 | + * @group interacter |
| 73 | + * @group short |
| 74 | + */ |
| 75 | + public function testInferTypeFromName() |
| 76 | + { |
| 77 | + $name = 'password'; |
| 78 | + $type = $this->interacter->inferTypeFromName($name); |
| 79 | + $this->assertEquals('password', $type, 'The type should be "password".'); |
| 80 | + |
| 81 | + $name = 'username'; |
| 82 | + $type = $this->interacter->inferTypeFromName($name); |
| 83 | + $this->assertEquals('string', $type, 'The type should be "string".'); |
| 84 | + |
| 85 | + $name = 'email'; |
| 86 | + $type = $this->interacter->inferTypeFromName($name); |
| 87 | + $this->assertEquals('string', $type, 'The type should be "string".'); |
| 88 | + |
| 89 | + $name = "upstream_id"; |
| 90 | + $type = $this->interacter->inferTypeFromName($name); |
| 91 | + $this->assertEquals('upstream', $type, 'The type should be "upstream".'); |
| 92 | + |
| 93 | + $name = "org"; |
| 94 | + $type = $this->interacter->inferTypeFromName($name); |
| 95 | + $this->assertEquals('organization', $type, 'The type should be "organization".'); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * @test |
| 100 | + * @covers \Pantheon\Terminus\Hooks\Interacter |
| 101 | + * |
| 102 | + * @group interacter |
| 103 | + * @group short |
| 104 | + */ |
| 105 | + public function testGetRegionList() |
| 106 | + { |
| 107 | + $regions = $this->interacter->getRegionList(); |
| 108 | + $this->assertIsArray($regions, 'The regions should be an array.'); |
| 109 | + $this->assertNotEmpty($regions, 'The regions array should not be empty.'); |
| 110 | + |
| 111 | + $empty_found = false; |
| 112 | + foreach ($regions as $key => $region) { |
| 113 | + if (empty($key)) { |
| 114 | + $empty_found = true; |
| 115 | + break; |
| 116 | + } |
| 117 | + } |
| 118 | + $this->assertFalse($empty_found, 'The regions array should NOT contain an empty key.'); |
| 119 | + |
| 120 | + $regions = $this->interacter->getRegionList(true); |
| 121 | + $this->assertIsArray($regions, 'The regions should be an array.'); |
| 122 | + $this->assertNotEmpty($regions, 'The regions array should not be empty.'); |
| 123 | + $empty_found = false; |
| 124 | + foreach ($regions as $key => $region) { |
| 125 | + if (empty($key)) { |
| 126 | + $empty_found = true; |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | + $this->assertTrue($empty_found, 'The regions array should contain an empty key.'); |
| 131 | + } |
| 132 | +} |
0 commit comments