InfoCommandTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 8

Importance

Changes 0
Metric Value
wmc 2
cbo 8
dl 0
loc 114
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 27 1
A testCommand() 0 57 1
1
<?php
2
3
/**
4
 * This file is part of Bldr.io
5
 *
6
 * (c) Aaron Scherer <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE
10
 */
11
12
namespace Bldr\Test\Command\Task;
13
14
use Bldr\Block\Core\Command\Task\InfoCommand;
15
use Bldr\Registry\TaskRegistry;
16
use Bldr\Test\Mock\MockApplication;
17
use Mockery\MockInterface;
18
use Symfony\Component\Console\Tester\CommandTester;
19
20
/**
21
 * @author Wouter J <[email protected]>
22
 */
23
class InfoCommandTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @type MockInterface
27
     */
28
    protected $container;
29
30
    /**
31
     * @type InfoCommand
32
     */
33
    protected $command;
34
35
    /**
36
     * @type MockInterface
37
     */
38
    protected $task1;
39
40
    /**
41
     * @type MockInterface
42
     */
43
    protected $task2;
44
45
    /**
46
     *
47
     */
48
    public function setUp()
49
    {
50
        $this->container = \Mockery::mock('Symfony\Component\DependencyInjection\Container');
51
52
        $this->command = new InfoCommand();
53
        $this->command->setContainer($this->container);
54
55
        $this->task1 = \Mockery::mock('Bldr\Block\Core\Task\AbstractTask');
56
        $this->task1->shouldReceive('configure');
57
        $this->task1->shouldReceive('validate');
58
        $this->task1->shouldReceive('setEventDispatcher');
59
        $this->task1->shouldReceive('getName')->andReturn('Name 1');
60
61
        $this->task2 = \Mockery::mock('Bldr\Task\TaskInterface');
62
        $this->task2->shouldReceive('configure');
63
        $this->task2->shouldReceive('validate');
64
        $this->task2->shouldReceive('getName')->andReturn('Name 2');
65
66
        $registry = new TaskRegistry(
67
            \Mockery::mock('Symfony\Component\EventDispatcher\EventDispatcherInterface'), [$this->task1, $this->task2]
0 ignored issues
show
Documentation introduced by
array($this->task1, $this->task2) is of type array<integer,object<Moc...kery\\MockInterface>"}>, but the function expects a array<integer,object<Bldr\Task\TaskInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
        );
69
70
        $this->container
71
            ->shouldReceive('get')
72
            ->with('bldr.registry.task')
73
            ->andReturn($registry);
74
    }
75
76
    /**
77
     *
78
     */
79
    public function testCommand()
80
    {
81
        $this->task1->shouldReceive('getDescription')->andReturn('A first description.');
82
        $this->task1->shouldReceive('getParameterDefinition')->andReturn(
83
            [
84
                ['name' => 'option1', 'default' => null, 'description' => '', 'required' => false],
85
                [
86
                    'name'        => 'option2',
87
                    'default'     => 'bldr!',
88
                    'description' => 'Option 2 description',
89
                    'required'    => true
90
                ],
91
                ['name' => 'option3', 'default' => true, 'description' => '', 'required' => false],
92
            ]
93
        );
94
95
        $this->task2->shouldReceive('getDescription')->andReturnNull();
96
97
        $application = new MockApplication();
98
        $application->add($this->command);
99
100
        $tester = new CommandTester($application->find('task:info'));
101
        $tester->execute(['task' => 'Name 1']);
102
103
        $this->assertEquals(
104
            <<<EOO
105
106
Task Name: Name 1
107
Task Description: A first description.
108
109
Options:
110
+---------+----------------------+----------+---------+
111
| Option  | Description          | Required | Default |
112
+---------+----------------------+----------+---------+
113
| option1 | No Description       | No       | null    |
114
| option2 | Option 2 description | Yes      | "bldr!" |
115
| option3 | No Description       | No       | true    |
116
+---------+----------------------+----------+---------+
117
118
EOO
119
            ,
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
120
            $tester->getDisplay()
121
        );
122
123
        $tester = new CommandTester($application->find('task:info'));
124
        $tester->execute(['task' => 'Name 2']);
125
126
        $this->assertEquals(
127
            <<<EOO
128
129
Task Name: Name 2
130
131
EOO
132
            ,
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
133
            $tester->getDisplay()
134
        );
135
    }
136
}
137