|
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\ListCommand; |
|
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 ListCommandTest extends \PHPUnit_Framework_TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @type MockInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $container; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @type ListCommand |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $command; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @type MockInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $task1; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @type MockInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $task2; |
|
44
|
|
|
|
|
45
|
|
|
public function setUp() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->container = \Mockery::mock('Symfony\Component\DependencyInjection\Container'); |
|
48
|
|
|
|
|
49
|
|
|
$this->command = new ListCommand(); |
|
50
|
|
|
$this->command->setContainer($this->container); |
|
51
|
|
|
|
|
52
|
|
|
$this->task1 = \Mockery::mock('Bldr\Block\Core\Task\AbstractTask'); |
|
53
|
|
|
$this->task1->shouldReceive('configure'); |
|
54
|
|
|
$this->task1->shouldReceive('validate'); |
|
55
|
|
|
$this->task1->shouldReceive('setEventDispatcher'); |
|
56
|
|
|
$this->task1->shouldReceive('getName')->andReturn('Name 1'); |
|
57
|
|
|
|
|
58
|
|
|
$this->task2 = \Mockery::mock('Bldr\Task\TaskInterface'); |
|
59
|
|
|
$this->task2->shouldReceive('configure'); |
|
60
|
|
|
$this->task2->shouldReceive('validate'); |
|
61
|
|
|
$this->task2->shouldReceive('getName')->andReturn('Name 2'); |
|
62
|
|
|
|
|
63
|
|
|
$registry = new TaskRegistry( |
|
64
|
|
|
\Mockery::mock('Symfony\Component\EventDispatcher\EventDispatcherInterface'), [$this->task1, $this->task2] |
|
|
|
|
|
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$this->container |
|
68
|
|
|
->shouldReceive('get') |
|
69
|
|
|
->with('bldr.registry.task') |
|
70
|
|
|
->andReturn($registry); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testCommand() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->task1->shouldReceive('getName')->andReturn('Name 1'); |
|
76
|
|
|
$this->task1->shouldReceive('getDescription')->andReturn('A first description.'); |
|
77
|
|
|
|
|
78
|
|
|
$this->task2->shouldReceive('getName')->andReturn('Name 2'); |
|
79
|
|
|
$this->task2->shouldReceive('getDescription')->andReturn('A second description.'); |
|
80
|
|
|
|
|
81
|
|
|
$application = new MockApplication(); |
|
82
|
|
|
$application->add($this->command); |
|
83
|
|
|
|
|
84
|
|
|
$tester = new CommandTester($application->find('task:list')); |
|
85
|
|
|
$tester->execute([]); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals( |
|
88
|
|
|
<<<EOO |
|
89
|
|
|
+--------+-----------------------+ |
|
90
|
|
|
| Name | Description | |
|
91
|
|
|
+--------+-----------------------+ |
|
92
|
|
|
| Name 1 | A first description. | |
|
93
|
|
|
| Name 2 | A second description. | |
|
94
|
|
|
+--------+-----------------------+ |
|
95
|
|
|
|
|
96
|
|
|
EOO |
|
97
|
|
|
, |
|
|
|
|
|
|
98
|
|
|
$tester->getDisplay() |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
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: