|
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\DefaultIO; |
|
15
|
|
|
use CaptainHook\App\Console\IO\NullIO; |
|
16
|
|
|
use CaptainHook\App\Console\Runtime\Resolver; |
|
17
|
|
|
use Exception; |
|
18
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
19
|
|
|
use PHPUnit\Framework\TestCase; |
|
20
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
21
|
|
|
|
|
22
|
|
|
class DisableTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public function testExecuteNoConfig(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$resolver = new Resolver(); |
|
27
|
|
|
$output = new NullOutput(); |
|
28
|
|
|
$input = new ArrayInput( |
|
29
|
|
|
[ |
|
30
|
|
|
'hook' => 'pre-commit', |
|
31
|
|
|
'--configuration' => 'foo' |
|
32
|
|
|
] |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$install = new Disable($resolver); |
|
36
|
|
|
$install->setIO(new NullIO()); |
|
37
|
|
|
$code = $install->run($input, $output); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertEquals(1, $code); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testExecuteEnablePrePush(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$resolver = new Resolver(); |
|
45
|
|
|
$config = sys_get_temp_dir() . '/captainhook-enable.json'; |
|
46
|
|
|
copy(CH_PATH_FILES . '/config/valid.json', $config); |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$add = new Disable($resolver); |
|
50
|
|
|
$output = new NullOutput(); |
|
51
|
|
|
$input = new ArrayInput( |
|
52
|
|
|
[ |
|
53
|
|
|
'hook' => 'pre-commit', |
|
54
|
|
|
'--configuration' => $config |
|
55
|
|
|
] |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$io = $this->getMockBuilder(DefaultIO::class) |
|
59
|
|
|
->disableOriginalConstructor() |
|
60
|
|
|
->getMock(); |
|
61
|
|
|
$io->expects($this->once())->method('write'); |
|
62
|
|
|
|
|
63
|
|
|
$add->setIO($io); |
|
64
|
|
|
$add->run($input, $output); |
|
65
|
|
|
|
|
66
|
|
|
$json = json_decode(file_get_contents($config), true); |
|
67
|
|
|
$this->assertFalse($json['pre-commit']['enabled']); |
|
68
|
|
|
|
|
69
|
|
|
unlink($config); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|