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 Symfony\Component\Console\Input\ArrayInput; |
15
|
|
|
use Symfony\Component\Console\Tests\Fixtures\DummyOutput; |
16
|
|
|
|
17
|
|
|
class InstallTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Tests Install::run |
21
|
|
|
* |
22
|
|
|
* @expectedException \Exception |
23
|
|
|
*/ |
24
|
|
|
public function testExecuteNoConfig() |
25
|
|
|
{ |
26
|
|
|
$input = new ArrayInput( |
27
|
|
|
[ |
28
|
|
|
'hook' => 'pre-commit', |
29
|
|
|
'--configuration' => 'foo', |
30
|
|
|
'--git-directory' => 'bar' |
31
|
|
|
] |
32
|
|
|
); |
33
|
|
|
$output = new DummyOutput(); |
34
|
|
|
$install = new Install(); |
35
|
|
|
$install->setIO(new NullIO()); |
36
|
|
|
$install->run($input, $output); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Tests Install::run |
41
|
|
|
* |
42
|
|
|
* @expectedException \Exception |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function testExecuteInvalidRepository() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$input = new ArrayInput( |
47
|
|
|
[ |
48
|
|
|
'hook' => 'pre-commit', |
49
|
|
|
'--configuration' => HMU_PATH_FILES . '/config/valid.json', |
50
|
|
|
'--git-directory' => 'bar/.git' |
51
|
|
|
] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$output = new DummyOutput(); |
55
|
|
|
$install = new Install(); |
56
|
|
|
$install->setIO(new NullIO()); |
57
|
|
|
$install->run($input, $output); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Tests Install::run |
63
|
|
|
*/ |
64
|
|
|
public function testExecutePreCommit() |
65
|
|
|
{ |
66
|
|
|
$repo = new DummyRepo(); |
67
|
|
|
$repo->setup(); |
68
|
|
|
|
69
|
|
|
$install = new Install(); |
70
|
|
|
$output = new DummyOutput(); |
71
|
|
|
$input = new ArrayInput( |
72
|
|
|
[ |
73
|
|
|
'hook' => 'pre-commit', |
74
|
|
|
'--configuration' => HMU_PATH_FILES . '/config/valid.json', |
75
|
|
|
'--git-directory' => $repo->getGitDir() |
76
|
|
|
] |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$install->setIO(new NullIO()); |
80
|
|
|
$install->run($input, $output); |
81
|
|
|
|
82
|
|
|
// make sure the file is installed |
83
|
|
|
$this->assertTrue( |
84
|
|
|
file_exists( |
85
|
|
|
$repo->getGitDir() . DIRECTORY_SEPARATOR . 'hooks' . DIRECTORY_SEPARATOR . 'pre-commit' |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$repo->cleanup(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.