Passed
Push — master ( 7bee4d...457c92 )
by Sebastian
01:54
created

PostCommitTest::testRunHookEnabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 20
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
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);
0 ignored issues
show
Unused Code introduced by
The call to CaptainHook\App\Runner\H...stCommit::__construct() has too many arguments starting with $args. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        $runner = /** @scrutinizer ignore-call */ new PostCommit($io, $config, $repo, $args);

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.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
The call to CaptainHook\App\Runner\H...stCommit::__construct() has too many arguments starting with $args. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $runner = /** @scrutinizer ignore-call */ new PostCommit($io, $config, $repo, $args);

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.

Loading history...
57
        $runner->run();
58
    }
59
}
60