MessageTestCase::testConfigure()   F
last analyzed

Complexity

Conditions 14
Paths 577

Size

Total Lines 39
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
rs 2.9238
cc 14
eloc 30
nc 577
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace BaleenTest\Cli\CommandBus;
21
22
use BaleenTest\Cli\BaseTestCase;
23
use Mockery as m;
24
use Symfony\Component\Console\Command\Command;
25
26
/**
27
 * Class MessageTestCase
28
 * @author Gabriel Somoza <[email protected]>
29
 */
30
abstract class MessageTestCase extends BaseTestCase
31
{
32
    /**
33
     * testConfigure
34
     */
35
    public function testConfigure() {
36
        /** @var m\Mock|Command $command */
37
        $command = m::mock(Command::class);
38
39
        $expectations = $this->getExpectations();
40
        foreach ($expectations as $func => $expectation) {
41
            $func = isset($expectation['name']) ? $expectation['name'] : $func;
42
            $times = isset($expectation['times']) ? $expectation['times'] : 1;
43
            $with = !empty($expectation['with']) ? $expectation['with'] : null;
44
            $return = isset($expectations['return']) ? $expectations['return'] : '!self';
45
            $exp = $command->shouldReceive($func);
46
            if (null !== $times) {
47
                $exp = $exp->times($times);
48
            }
49
            if (null !== $with) {
50
                if (!is_array($with)) {
51
                    $with = [$with];
52
                }
53
                $exp = call_user_func_array([$exp, 'with'], $with);
54
            }
55
            switch ($return) {
56
                case '!self':
57
                    $exp->andReturnSelf();
58
                    break;
59
                case '!null':
60
                case null:
61
                    $exp->andReturnNull();
62
                    break;
63
                default:
64
                    if (is_array($return)) {
65
                        $exp->andReturnValues($return);
66
                    } elseif (is_callable($return)) {
67
                        $exp->andReturnUsing($return);
68
                    }
69
                    break;
70
            }
71
        }
72
        forward_static_call([$this->getClassName(), 'configure'], $command);
73
    }
74
75
    /**
76
     * Must test the constructor and assert implemented interfaces
77
     */
78
    abstract public function testConstructor();
79
80
    /**
81
     * getClassName must return a string with the FQN of the command class being tested
82
     * @return string
83
     */
84
    abstract protected function getClassName();
85
86
    /**
87
     * Must return an array in the format:
88
     *
89
     *      [
90
     *          'name' => 'functionName', // required
91
     *          'with' => [arguments for with] // optional
92
     *          'return' => return value // optional, defaults to return self
93
     *          'times' => number of times it will be invoked
94
     *      ]
95
     *
96
     * @return array
97
     */
98
    abstract protected function getExpectations();
99
}
100