|
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 sebastianfeldmann\CaptainHook\Console\Application; |
|
11
|
|
|
|
|
12
|
|
|
use sebastianfeldmann\CaptainHook\Config; |
|
13
|
|
|
use sebastianfeldmann\CaptainHook\Git\DummyRepo; |
|
14
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
15
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
16
|
|
|
|
|
17
|
|
|
class HookTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Tests Hook::run |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testRun() |
|
23
|
|
|
{ |
|
24
|
|
|
$config = new Config(HMU_PATH_FILES . '/config/valid.json'); |
|
25
|
|
|
$repo = new DummyRepo(); |
|
26
|
|
|
$output = new NullOutput(); |
|
27
|
|
|
$input = new ArrayInput([ |
|
28
|
|
|
'file' => HMU_PATH_FILES . '/git/message/valid.txt', |
|
29
|
|
|
]); |
|
30
|
|
|
$app = new Hook(); |
|
31
|
|
|
$app->setConfigFile($config); |
|
|
|
|
|
|
32
|
|
|
$app->setRepositoryPath($repo->getPath()); |
|
33
|
|
|
$app->setHook('commit-msg'); |
|
34
|
|
|
$app->setAutoExit(false); |
|
35
|
|
|
$app->run($input, $output); |
|
36
|
|
|
|
|
37
|
|
|
$repo->cleanup(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Tests Hook::executeHook |
|
42
|
|
|
* |
|
43
|
|
|
* @expectedException \Exception |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testRunInvalidHook() |
|
46
|
|
|
{ |
|
47
|
|
|
$app = new Hook(); |
|
48
|
|
|
$app->setHook('pre-foo'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Tests Hook::executeHook |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testRunNoHook() |
|
55
|
|
|
{ |
|
56
|
|
|
$input = new ArrayInput([]); |
|
57
|
|
|
$output = new NullOutput(); |
|
58
|
|
|
$app = new Hook(); |
|
59
|
|
|
$app->setAutoExit(false); |
|
60
|
|
|
$exit = $app->run($input, $output); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertTrue($exit != 0); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Tests Hook::getRepositoryPath |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testGetRepositoryPath() |
|
69
|
|
|
{ |
|
70
|
|
|
$app = new Hook(); |
|
71
|
|
|
$this->assertEquals(getcwd(), $app->getRepositoryPath()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Tests Hook::getConfigFile |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testGetConfigFile() |
|
78
|
|
|
{ |
|
79
|
|
|
$app = new Hook(); |
|
80
|
|
|
$this->assertEquals(getcwd() . '/captainhook.json', $app->getConfigFile()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Tests Application::getHelp |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testGetHelp() |
|
87
|
|
|
{ |
|
88
|
|
|
$hook = new Hook(); |
|
89
|
|
|
$help = $hook->getHelp(); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertTrue( |
|
92
|
|
|
(bool)strpos( |
|
93
|
|
|
$help, |
|
94
|
|
|
'$$$$b ^ceeeee. 4$$ECL.F*$$$$$$$' |
|
95
|
|
|
) |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: