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\NullIO; |
13
|
|
|
use CaptainHook\App\Git\DummyRepo; |
14
|
|
|
use CaptainHook\App\Hook\Template; |
15
|
|
|
use Exception; |
16
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
17
|
|
|
use Symfony\Component\Console\Tests\Fixtures\DummyOutput; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
class InstallTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Tests Install::run |
24
|
|
|
*/ |
25
|
|
|
public function testExecuteNoConfig(): void |
26
|
|
|
{ |
27
|
|
|
$this->expectException(Exception::class); |
28
|
|
|
|
29
|
|
|
$install = new Install(); |
30
|
|
|
$output = new DummyOutput(); |
31
|
|
|
$input = new ArrayInput( |
32
|
|
|
[ |
33
|
|
|
'hook' => 'pre-commit', |
34
|
|
|
'--configuration' => 'foo', |
35
|
|
|
'--git-directory' => 'bar' |
36
|
|
|
] |
37
|
|
|
); |
38
|
|
|
$install->setIO(new NullIO()); |
39
|
|
|
$install->run($input, $output); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Tests Install::run |
44
|
|
|
*/ |
45
|
|
|
public function testExecuteInvalidRepository(): void |
46
|
|
|
{ |
47
|
|
|
$this->expectException(Exception::class); |
48
|
|
|
|
49
|
|
|
$install = new Install(); |
50
|
|
|
$output = new DummyOutput(); |
51
|
|
|
$input = new ArrayInput( |
52
|
|
|
[ |
53
|
|
|
'hook' => 'pre-commit', |
54
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid.json', |
55
|
|
|
'--git-directory' => 'bar/.git' |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$install->setIO(new NullIO()); |
60
|
|
|
$install->run($input, $output); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Tests Install::run |
66
|
|
|
*/ |
67
|
|
|
public function testExecuteMissingRunExec(): void |
68
|
|
|
{ |
69
|
|
|
if (\defined('PHP_WINDOWS_VERSION_MAJOR')) { |
70
|
|
|
$this->markTestSkipped('not tested on windows'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$repo = new DummyRepo(); |
74
|
|
|
$repo->setup(); |
75
|
|
|
|
76
|
|
|
try { |
77
|
|
|
$install = new Install(); |
78
|
|
|
$output = new DummyOutput(); |
79
|
|
|
$input = new ArrayInput( |
80
|
|
|
[ |
81
|
|
|
'hook' => 'pre-commit', |
82
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid.json', |
83
|
|
|
'--git-directory' => $repo->getGitDir(), |
84
|
|
|
'--run-mode' => Template::DOCKER |
85
|
|
|
] |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$install->setIO(new NullIO()); |
89
|
|
|
$install->run($input, $output); |
90
|
|
|
} catch (Exception $e) { |
91
|
|
|
$this->assertEquals('Option "run-exec" missing for run-mode docker.', $e->getMessage()); |
92
|
|
|
$this->assertTrue(true, 'Exception should be thrown'); |
93
|
|
|
} finally { |
94
|
|
|
$repo->cleanup(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Tests Install::run |
101
|
|
|
*/ |
102
|
|
|
public function testExecutePreCommit(): void |
103
|
|
|
{ |
104
|
|
|
if (\defined('PHP_WINDOWS_VERSION_MAJOR')) { |
105
|
|
|
$this->markTestSkipped('not tested on windows'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$repo = new DummyRepo(); |
109
|
|
|
$repo->setup(); |
110
|
|
|
|
111
|
|
|
$install = new Install(); |
112
|
|
|
$output = new DummyOutput(); |
113
|
|
|
$input = new ArrayInput( |
114
|
|
|
[ |
115
|
|
|
'hook' => 'pre-commit', |
116
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid.json', |
117
|
|
|
'--git-directory' => $repo->getGitDir() |
118
|
|
|
] |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$install->setIO(new NullIO()); |
122
|
|
|
$install->run($input, $output); |
123
|
|
|
|
124
|
|
|
// make sure the file is installed |
125
|
|
|
$this->assertFileExists($repo->getGitDir() . DIRECTORY_SEPARATOR . 'hooks' . DIRECTORY_SEPARATOR . 'pre-commit'); |
126
|
|
|
|
127
|
|
|
$repo->cleanup(); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|