Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
created

PHPTest::testExecuteNoAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 9
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 sebastianfeldmann\CaptainHook\Runner\Action;
11
12
use sebastianfeldmann\CaptainHook\Config;
13
use sebastianfeldmann\CaptainHook\Console\IO;
14
use sebastianfeldmann\CaptainHook\Git\Repository;
15
use sebastianfeldmann\CaptainHook\Hook\Action as ActionInterface;
16
use sebastianfeldmann\CaptainHook\Runner\BaseTestRunner;
17
18
class PHPTest extends BaseTestRunner
19
{
20
    /**
21
     * Tests PHP::execute
22
     */
23 View Code Duplication
    public function testExecuteSuccess()
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...
24
    {
25
        $config = $this->getConfigMock();
26
        $io     = $this->getIOMock();
27
        $repo   = $this->getRepositoryMock();
28
        $action = $this->getActionConfigMock();
29
30
        $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyPHPSuccess';
31
32
        $action->expects($this->once())->method('getAction')->willReturn($class);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<sebastianfeldmann...tainHook\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...
33
34
        $php = new PHP();
35
        $php->execute($config, $io, $repo, $action);
36
    }
37
38
    /**
39
     * Tests PHP::execute
40
     *
41
     * @expectedException \Exception
42
     */
43 View Code Duplication
    public function testExecuteFailure()
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...
44
    {
45
        $config = $this->getConfigMock();
46
        $io     = $this->getIOMock();
47
        $repo   = $this->getRepositoryMock();
48
        $action = $this->getActionConfigMock();
49
50
        $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyPHPFailure';
51
52
        $action->expects($this->once())->method('getAction')->willReturn($class);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<sebastianfeldmann...tainHook\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...
53
54
        $php = new PHP();
55
        $php->execute($config, $io, $repo, $action);
56
    }
57
58
    /**
59
     * Tests PHP::execute
60
     *
61
     * @expectedException \Exception
62
     */
63 View Code Duplication
    public function testExecuteError()
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...
64
    {
65
        $config = $this->getConfigMock();
66
        $io     = $this->getIOMock();
67
        $repo   = $this->getRepositoryMock();
68
        $action = $this->getActionConfigMock();
69
70
        $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyPHPError';
71
72
        $action->expects($this->once())->method('getAction')->willReturn($class);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<sebastianfeldmann...tainHook\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...
73
74
        $php = new PHP();
75
        $php->execute($config, $io, $repo, $action);
76
    }
77
78
    /**
79
     * Tests PHP::execute
80
     *
81
     * @expectedException \Exception
82
     */
83 View Code Duplication
    public function testExecuteNoAction()
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...
84
    {
85
        $config = $this->getConfigMock();
86
        $io     = $this->getIOMock();
87
        $repo   = $this->getRepositoryMock();
88
        $action = $this->getActionConfigMock();
89
90
        $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyNoAction';
91
92
        $action->expects($this->once())->method('getAction')->willReturn($class);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<sebastianfeldmann...tainHook\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...
93
94
        $php = new PHP();
95
        $php->execute($config, $io, $repo, $action);
96
    }
97
}
98
99
class DummyPHPSuccess implements ActionInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
100
{
101
    /**
102
     * Execute the configured action.
103
     *
104
     * @param  \sebastianfeldmann\CaptainHook\Config         $config
105
     * @param  \sebastianfeldmann\CaptainHook\Console\IO     $io
106
     * @param  \sebastianfeldmann\CaptainHook\Git\Repository $repository
107
     * @param  \sebastianfeldmann\CaptainHook\Config\Action  $action
108
     * @throws \sebastianfeldmann\CaptainHook\Exception\ActionExecution
109
     */
110
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
111
    {
112
        // do something fooish
113
    }
114
}
115
116
class DummyPHPFailure implements ActionInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
117
{
118
    /**
119
     * Execute the configured action.
120
     *
121
     * @param  \sebastianfeldmann\CaptainHook\Config         $config
122
     * @param  \sebastianfeldmann\CaptainHook\Console\IO     $io
123
     * @param  \sebastianfeldmann\CaptainHook\Git\Repository $repository
124
     * @param  \sebastianfeldmann\CaptainHook\Config\Action  $action
125
     * @throws \sebastianfeldmann\CaptainHook\Exception\ActionExecution
126
     */
127
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
128
    {
129
        throw new \RuntimeException('Execution failed');
130
    }
131
}
132
133
class DummyPHPError implements ActionInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
134
{
135
    /**
136
     * Execute the configured action.
137
     *
138
     * @param  \sebastianfeldmann\CaptainHook\Config         $config
139
     * @param  \sebastianfeldmann\CaptainHook\Console\IO     $io
140
     * @param  \sebastianfeldmann\CaptainHook\Git\Repository $repository
141
     * @param  \sebastianfeldmann\CaptainHook\Config\Action  $action
142
     * @throws \sebastianfeldmann\CaptainHook\Exception\ActionExecution
143
     */
144
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
145
    {
146
        str_pos();
147
    }
148
}
149
150
class DummyNoAction
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
151
{
152
    /**
153
     * Barish
154
     */
155
    public function dummy()
156
    {
157
        // do something barish
158
    }
159
}
160