Passed
Push — master ( 21c505...12ca40 )
by Sebastian
02:34
created

DummyPHPSuccess   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 16
c 1
b 0
f 1
rs 10
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
    public function testExecuteSuccess()
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);
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
    public function testExecuteFailure()
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);
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
    public function testExecuteError()
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);
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
    public function testExecuteNoAction()
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);
93
94
        $php = new PHP();
95
        $php->execute($config, $io, $repo, $action);
96
    }
97
}
98
99
class DummyPHPSuccess implements ActionInterface
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
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
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
151
{
152
    /**
153
     * Barish
154
     */
155
    public function dummy()
156
    {
157
        // do something barish
158
    }
159
}
160