|
5 | 5 | namespace Deployer\Import; |
6 | 6 |
|
7 | 7 | use Deployer\Deployer; |
| 8 | +use Deployer\Exception\Exception; |
8 | 9 | use PHPUnit\Framework\TestCase; |
| 10 | +use Symfony\Component\Console\Application; |
| 11 | +use Symfony\Component\Console\Input\Input; |
| 12 | +use Symfony\Component\Console\Output\Output; |
9 | 13 |
|
10 | 14 | class ImportTest extends TestCase |
11 | 15 | { |
12 | | - private $previousInput; |
13 | | - private $previousOutput; |
| 16 | + private Deployer $deployer; |
14 | 17 |
|
15 | 18 | public function setUp(): void |
16 | 19 | { |
17 | | - $deployer = Deployer::get(); |
18 | | - $this->previousInput = $deployer->input; |
19 | | - $this->previousOutput = $deployer->output; |
| 20 | + $console = new Application(); |
| 21 | + $input = $this->createStub(Input::class); |
| 22 | + $output = $this->createStub(Output::class); |
| 23 | + |
| 24 | + $this->deployer = new Deployer($console); |
| 25 | + $this->deployer['input'] = $input; |
| 26 | + $this->deployer['output'] = $output; |
20 | 27 | } |
21 | 28 |
|
22 | 29 | public function tearDown(): void |
23 | 30 | { |
24 | | - Deployer::get()->input = $this->previousInput; |
25 | | - Deployer::get()->output = $this->previousOutput; |
| 31 | + unset($this->deployer); |
26 | 32 | } |
27 | 33 |
|
28 | | - public function testImporterIgnoresYamlHiddenKeys(): void |
| 34 | + public function testUnknownFileFormatThrows(): void |
29 | 35 | { |
30 | | - $data = <<<EOL |
31 | | - .base: &base |
32 | | - remote_user: foo |
33 | | - labels: |
34 | | - stage: production |
35 | | -
|
36 | | - hosts: |
37 | | - acceptance: |
38 | | - <<: *base |
39 | | - labels: |
40 | | - stage: acceptance |
41 | | -
|
42 | | - production: |
43 | | - <<: *base |
44 | | - remote_user: bar |
45 | | - |
46 | | - production.beta: |
47 | | - <<: *base |
48 | | - # test.yaml |
49 | | - EOL; |
50 | | - |
51 | | - Import::import("data:text/yaml,$data"); |
52 | | - self::assertTrue(Deployer::get()->hosts->has('production')); |
53 | | - self::assertTrue(Deployer::get()->hosts->has('acceptance')); |
54 | | - self::assertTrue(Deployer::get()->hosts->has('production.beta')); |
55 | | - self::assertEquals('acceptance', Deployer::get()->hosts->get('acceptance')->getLabels()['stage']); |
56 | | - self::assertEquals('production', Deployer::get()->hosts->get('production')->getLabels()['stage']); |
57 | | - self::assertEquals('foo', Deployer::get()->hosts->get('acceptance')->getRemoteUser()); |
58 | | - self::assertEquals('bar', Deployer::get()->hosts->get('production')->getRemoteUser()); |
| 36 | + $this->expectException(Exception::class); |
| 37 | + $this->expectExceptionMessage('Unknown file format'); |
| 38 | + |
| 39 | + Import::import('file.txt'); |
59 | 40 | } |
60 | 41 | } |
0 commit comments