Passed
Push — master ( b649b5...b34030 )
by Sebastian
04:07
created

HookTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 89
Duplicated Lines 19.1 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 17
loc 89
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetHook() 8 8 1
A testRunHookEnabled() 0 17 1
A testRunHookEnabledDisabled() 0 16 1
A testGetRunner() 0 13 1
A testGetRunnerFailure() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Runner;
11
12
class HookTest extends BaseTestRunner
13
{
14
    /**
15
     * Tests Installer::setHook
16
     *
17
     * @expectedException \Exception
18
     */
19 View Code Duplication
    public function testSetHook()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $io     = $this->getIOMock();
22
        $config = $this->getConfigMock();
23
        $repo   = $this->getRepositoryMock();
24
        $runner = new Hook($io, $config, $repo);
25
        $runner->setHook('iDonExist');
26
    }
27
28
    /**
29
     * Tests Installer::run
30
     */
31
    public function testRunHookEnabled()
32
    {
33
        $io           = $this->getIOMock();
34
        $config       = $this->getConfigMock();
35
        $hookConfig   = $this->getHookConfigMock();
36
        $actionConfig = $this->getActionConfigMock();
37
        $repo         = $this->getRepositoryMock();
38
        $actionConfig->method('getType')->willReturn('cli');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\Config\Action>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        $hookConfig->expects($this->once())->method('isEnabled')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\Config\Hook>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        $hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\Config\Hook>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        $config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\Config>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
        $io->expects($this->exactly(3))->method('write');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\Console\IO\DefaultIO>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
44
        $runner = new Hook($io, $config, $repo);
45
        $runner->setHook('pre-commit');
46
        $runner->run();
47
    }
48
49
    /**
50
     * Tests Installer::run
51
     */
52
    public function testRunHookEnabledDisabled()
53
    {
54
        $io           = $this->getIOMock();
55
        $config       = $this->getConfigMock();
56
        $hookConfig   = $this->getHookConfigMock();
57
        $actionConfig = $this->getActionConfigMock();
58
        $repo         = $this->getRepositoryMock();
59
        $actionConfig->method('getType')->willReturn('cli');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\Config\Action>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
        $hookConfig->expects($this->once())->method('isEnabled')->willReturn(false);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\Config\Hook>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        $config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\Config>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        $io->expects($this->once())->method('write');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\Console\IO\DefaultIO>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
64
        $runner = new Hook($io, $config, $repo);
65
        $runner->setHook('pre-commit');
66
        $runner->run();
67
    }
68
69
    /**
70
     * Tests Hook::getActionRunner
71
     */
72
    public function testGetRunner()
73
    {
74
        $io           = $this->getIOMock();
75
        $config       = $this->getConfigMock();
76
        $repo         = $this->getRepositoryMock();
77
78
        $hook   = new Hook($io, $config, $repo);
79
        $php    = $hook->getActionRunner('php');
80
        $cli    = $hook->getActionRunner('cli');
81
82
        $this->assertTrue(is_a($php, '\\CaptainHook\\Runner\\Action\\PHP'));
83
        $this->assertTrue(is_a($cli, '\\CaptainHook\\Runner\\Action\\Cli'));
84
    }
85
86
    /**
87
     * Tests Hook::getActionRunner
88
     *
89
     * @expectedException \Exception
90
     */
91 View Code Duplication
    public function testGetRunnerFailure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93
        $io           = $this->getIOMock();
94
        $config       = $this->getConfigMock();
95
        $repo         = $this->getRepositoryMock();
96
97
        $hook   = new Hook($io, $config, $repo);
98
        $hook->getActionRunner('foo');
99
    }
100
}
101