|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of CaptainHook |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Console\Command; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IO\NullIO; |
|
15
|
|
|
use CaptainHook\App\Console\Runtime\Resolver; |
|
16
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
17
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
18
|
|
|
use PHPUnit\Framework\TestCase; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
|
|
21
|
|
|
class ConfigurationTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
public function testExecute(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$resolver = new Resolver(); |
|
26
|
|
|
$config = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(mt_rand(0, 9999)) . '.json'; |
|
27
|
|
|
$output = new NullOutput(); |
|
28
|
|
|
$input = new ArrayInput(['--configuration' => $config]); |
|
29
|
|
|
|
|
30
|
|
|
$configure = new Configuration($resolver); |
|
31
|
|
|
$configure->setIO(new NullIO()); |
|
32
|
|
|
$configure->run($input, $output); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertFileExists($config); |
|
35
|
|
|
|
|
36
|
|
|
unlink($config); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testConfigFailure(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$resolver = new Resolver(); |
|
42
|
|
|
$config = '/foo/bar/fiz/baz/config.json'; |
|
43
|
|
|
$input = new ArrayInput(['--configuration' => $config]); |
|
44
|
|
|
$output = $this->getMockBuilder(OutputInterface::class) |
|
45
|
|
|
->disableOriginalConstructor() |
|
46
|
|
|
->getMock(); |
|
47
|
|
|
$output->method('isVerbose')->willReturn(true); |
|
48
|
|
|
|
|
49
|
|
|
$configure = new Configuration($resolver); |
|
50
|
|
|
$configure->setIO(new NullIO()); |
|
51
|
|
|
$code = $configure->run($input, $output); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertEquals(1, $code); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|