PostCheckoutTest::testRunHookDisabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Runner\Hook;
13
14
use CaptainHook\App\Config\Mockery as ConfigMockery;
15
use CaptainHook\App\Console\IO\Mockery as IOMockery;
16
use CaptainHook\App\Git\DummyRepo;
17
use CaptainHook\App\Mockery as CHMockery;
18
use PHPUnit\Framework\TestCase;
19
20
class PostCheckoutTest extends TestCase
21
{
22
    use ConfigMockery;
23
    use IOMockery;
24
    use CHMockery;
25
26
    public function testRunHookEnabled(): void
27
    {
28
        $io     = $this->createIOMock();
29
        $config = $this->createConfigMock();
30
31
        $dummy = new DummyRepo(['hooks' => ['post-checkout' => '# hook script']]);
32
        $repo  = $this->createRepositoryMock($dummy->getRoot());
33
        $repo->method('getHooksDir')->willReturn($dummy->getHookDir());
34
35
        $hookConfig    = $this->createHookConfigMock();
36
        $actionConfig1 = $this->createActionConfigMock();
37
        $actionConfig2 = $this->createActionConfigMock();
38
        $hookConfig->method('isEnabled')->willReturn(true);
39
        $hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig1, $actionConfig2]);
40
        $config->expects($this->once())->method('getHookConfigToExecute')->willReturn($hookConfig);
41
        $config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(true);
42
        $io->expects($this->atLeast(1))->method('write');
43
44
        // Ensure that our actions are processed.
45
        $actionConfig1->expects($this->atLeast(1))->method('getAction');
46
        $actionConfig1->expects($this->atLeast(1))->method('getConditions');
47
        $actionConfig2->expects($this->atLeast(1))->method('getAction');
48
        $actionConfig2->expects($this->atLeast(1))->method('getConditions');
49
50
        $runner = new PostCheckout($io, $config, $repo);
51
        $runner->run();
52
    }
53
54
    public function testRunHookDisabled(): void
55
    {
56
        $io           = $this->createIOMock();
57
        $config       = $this->createConfigMock();
58
        $repo         = $this->createRepositoryMock();
59
        $config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(false);
60
        $io->expects($this->atLeast(1))->method('write');
61
62
        $runner = new PostCheckout($io, $config, $repo);
63
        $runner->run();
64
    }
65
}
66