1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace CaptainHook\App\Console\Command; |
11
|
|
|
|
12
|
|
|
use CaptainHook\App\Console\IO\DefaultIO; |
13
|
|
|
use CaptainHook\App\Console\IO\NullIO; |
14
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
15
|
|
|
use Symfony\Component\Console\Tests\Fixtures\DummyOutput; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
|
18
|
|
|
class EnableTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Tests Enable::run |
22
|
|
|
*/ |
23
|
|
|
public function testExecuteNoConfig(): void |
24
|
|
|
{ |
25
|
|
|
$this->expectException(\Exception::class); |
26
|
|
|
|
27
|
|
|
$input = new ArrayInput( |
28
|
|
|
[ |
29
|
|
|
'hook' => 'pre-commit', |
30
|
|
|
'--configuration' => 'foo' |
31
|
|
|
] |
32
|
|
|
); |
33
|
|
|
$output = new DummyOutput(); |
34
|
|
|
$install = new Enable(); |
35
|
|
|
$install->setIO(new NullIO()); |
36
|
|
|
$install->run($input, $output); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Tests Enable::run |
41
|
|
|
*/ |
42
|
|
|
public function testExecuteEnablePrePush(): void |
43
|
|
|
{ |
44
|
|
|
$config = sys_get_temp_dir() . '/captainhook-enable.json'; |
45
|
|
|
copy(CH_PATH_FILES . '/config/valid.json', $config); |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
$add = new Enable(); |
49
|
|
|
$output = new DummyOutput(); |
50
|
|
|
$input = new ArrayInput( |
51
|
|
|
[ |
52
|
|
|
'hook' => 'pre-push', |
53
|
|
|
'--configuration' => $config |
54
|
|
|
] |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$io = $this->getMockBuilder(DefaultIO::class) |
58
|
|
|
->disableOriginalConstructor() |
59
|
|
|
->getMock(); |
60
|
|
|
$io->expects($this->once())->method('write'); |
61
|
|
|
|
62
|
|
|
$add->setIO($io); |
63
|
|
|
$add->run($input, $output); |
64
|
|
|
|
65
|
|
|
$json = json_decode(file_get_contents($config), true); |
66
|
|
|
$this->assertTrue($json['pre-push']['enabled']); |
67
|
|
|
|
68
|
|
|
unlink($config); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|