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

PostMergeTest::testRunHookWithConditionsFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 17
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
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 PostMergeTest extends BaseTestRunner
16
{
17
    /**
18
     * Tests PostMerge::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
        $hookConfig->expects($this->once())->method('isEnabled')->willReturn(true);
32
        $hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]);
33
        $config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig);
34
        $io->expects($this->exactly(3))->method('write');
35
36
        $args   = new Config\Options([]);
37
        $runner = new PostMerge($io, $config, $repo, $args);
0 ignored issues
show
Unused Code introduced by
The call to CaptainHook\App\Runner\H...ostMerge::__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

37
        $runner = /** @scrutinizer ignore-call */ new PostMerge($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...
38
        $runner->run();
39
    }
40
41
    /**
42
     * Tests PostMerge::run
43
     */
44
    public function testRunHookWithConditionsApply(): void
45
    {
46
        $io              = $this->getIOMock();
47
        $config          = $this->getConfigMock();
48
        $repo            = $this->getRepositoryMock();
49
        $hookConfig      = $this->getHookConfigMock();
50
        $conditionConfig = new Config\Condition(CH_PATH_FILES . '/bin/phpunit');
51
        $actionConfig    = $this->getActionConfigMock();
52
        $actionConfig->expects($this->once())->method('getConditions')->willReturn([$conditionConfig]);
53
        $hookConfig->expects($this->once())->method('isEnabled')->willReturn(true);
54
        $hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]);
55
        $config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig);
56
        $io->expects($this->exactly(3))->method('write');
57
58
        $args   = new Config\Options([]);
59
        $runner = new PostMerge($io, $config, $repo, $args);
0 ignored issues
show
Unused Code introduced by
The call to CaptainHook\App\Runner\H...ostMerge::__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

59
        $runner = /** @scrutinizer ignore-call */ new PostMerge($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...
60
        $runner->run();
61
    }
62
63
64
    /**
65
     * Tests PostMerge::run
66
     */
67
    public function testRunHookWithConditionsFail()
68
    {
69
        $io              = $this->getIOMock();
70
        $config          = $this->getConfigMock();
71
        $repo            = $this->getRepositoryMock();
72
        $hookConfig      = $this->getHookConfigMock();
73
        $conditionConfig = new Config\Condition(CH_PATH_FILES . '/bin/failure');
74
        $actionConfig    = $this->getActionConfigMock();
75
        $actionConfig->expects($this->once())->method('getConditions')->willReturn([$conditionConfig]);
76
        $hookConfig->expects($this->once())->method('isEnabled')->willReturn(true);
77
        $hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]);
78
        $config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig);
79
        $io->expects($this->exactly(3))->method('write');
80
81
        $args   = new Config\Options([]);
82
        $runner = new PostMerge($io, $config, $repo, $args);
0 ignored issues
show
Unused Code introduced by
The call to CaptainHook\App\Runner\H...ostMerge::__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

82
        $runner = /** @scrutinizer ignore-call */ new PostMerge($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...
83
        $runner->run();
84
    }
85
86
    /**
87
     * Tests PostMerge::run
88
     */
89
    public function testRunHookDisabled()
90
    {
91
        $io           = $this->getIOMock();
92
        $config       = $this->getConfigMock();
93
        $hookConfig   = $this->getHookConfigMock();
94
        $repo         = $this->getRepositoryMock();
95
        $hookConfig->expects($this->once())->method('isEnabled')->willReturn(false);
96
        $config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig);
97
        $io->expects($this->once())->method('write');
98
99
        $args   = new Config\Options([]);
100
        $runner = new PostMerge($io, $config, $repo, $args);
0 ignored issues
show
Unused Code introduced by
The call to CaptainHook\App\Runner\H...ostMerge::__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

100
        $runner = /** @scrutinizer ignore-call */ new PostMerge($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...
101
        $runner->run();
102
    }
103
}
104