|
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\Runner\Hook; |
|
11
|
|
|
|
|
12
|
|
|
use CaptainHook\App\Config; |
|
13
|
|
|
use CaptainHook\App\Runner\BaseTestRunner; |
|
14
|
|
|
|
|
15
|
|
|
class PostCommitTest extends BaseTestRunner |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Tests PreCommit::run |
|
19
|
|
|
*/ |
|
20
|
|
|
public function testRunHookEnabled(): void |
|
21
|
|
|
{ |
|
22
|
|
|
if (\defined('PHP_WINDOWS_VERSION_MAJOR')) { |
|
23
|
|
|
$this->markTestSkipped('not tested on windows'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$io = $this->getIOMock(); |
|
27
|
|
|
$config = $this->getConfigMock(); |
|
28
|
|
|
$repo = $this->getRepositoryMock(); |
|
29
|
|
|
$hookConfig = $this->getHookConfigMock(); |
|
30
|
|
|
$actionConfig = $this->getActionConfigMock(); |
|
31
|
|
|
$actionConfig->method('getAction')->willReturn(CH_PATH_FILES . '/bin/success'); |
|
32
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(true); |
|
33
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]); |
|
34
|
|
|
$config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig); |
|
35
|
|
|
$io->expects($this->exactly(3))->method('write'); |
|
36
|
|
|
|
|
37
|
|
|
$args = new Config\Options([]); |
|
38
|
|
|
$runner = new PostCommit($io, $config, $repo, $args); |
|
|
|
|
|
|
39
|
|
|
$runner->run(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Tests PreCommit::run |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testRunHookDisabled(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$io = $this->getIOMock(); |
|
48
|
|
|
$config = $this->getConfigMock(); |
|
49
|
|
|
$hookConfig = $this->getHookConfigMock(); |
|
50
|
|
|
$repo = $this->getRepositoryMock(); |
|
51
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(false); |
|
52
|
|
|
$config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig); |
|
53
|
|
|
$io->expects($this->once())->method('write'); |
|
54
|
|
|
|
|
55
|
|
|
$args = new Config\Options([]); |
|
56
|
|
|
$runner = new PostCommit($io, $config, $repo, $args); |
|
|
|
|
|
|
57
|
|
|
$runner->run(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.