1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* File:GetModelDetailsCommandTest.php |
6
|
|
|
* |
7
|
|
|
* @author Maciej Sławik <[email protected]> |
8
|
|
|
* @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace MSlwk\Otomoto\Cli\Test\Unit\Command; |
12
|
|
|
|
13
|
|
|
use MSlwk\Otomoto\App\Manufacturer\Data\ManufacturerDTOInterface; |
14
|
|
|
use MSlwk\Otomoto\App\Model\Data\ModelDTOInterface; |
15
|
|
|
use MSlwk\Otomoto\App\Stats\Data\StatsDTOInterface; |
16
|
|
|
use MSlwk\Otomoto\App\Stats\Filter\FilterFactory; |
17
|
|
|
use MSlwk\Otomoto\App\Stats\Filter\FilterInterface; |
18
|
|
|
use MSlwk\Otomoto\Cli\Command\GetModelDetailsCommand; |
19
|
|
|
use MSlwk\Otomoto\Middleware\App\Stats\Stats; |
20
|
|
|
use MSlwk\Otomoto\Middleware\App\Stats\StatsFactory; |
21
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
22
|
|
|
use PHPUnit\Framework\TestCase; |
23
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
24
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
25
|
|
|
use Symfony\Component\Console\Input\InputOption; |
26
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class GetModelDetailsCommandTest |
30
|
|
|
* @package MSlwk\Otomoto\Cli\Test\Unit\Command |
31
|
|
|
*/ |
32
|
|
|
class GetModelDetailsCommandTest extends TestCase |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var MockObject|StatsFactory |
36
|
|
|
*/ |
37
|
|
|
private $statsFactory; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var MockObject|FilterFactory |
41
|
|
|
*/ |
42
|
|
|
private $filterFactory; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var MockObject|GetModelDetailsCommand |
46
|
|
|
*/ |
47
|
|
|
private $command; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var MockObject|InputInterface |
51
|
|
|
*/ |
52
|
|
|
private $input; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var MockObject|OutputInterface |
56
|
|
|
*/ |
57
|
|
|
private $output; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
protected function setUp() |
63
|
|
|
{ |
64
|
|
|
$this->statsFactory = $this->getMockBuilder(StatsFactory::class) |
65
|
|
|
->disableOriginalConstructor() |
66
|
|
|
->getMock(); |
67
|
|
|
$this->filterFactory = $this->getMockBuilder(FilterFactory::class) |
68
|
|
|
->disableOriginalConstructor() |
69
|
|
|
->getMock(); |
70
|
|
|
$this->input = $this->getMockBuilder(InputInterface::class) |
71
|
|
|
->getMock(); |
72
|
|
|
$this->output = $this->getMockBuilder(OutputInterface::class) |
73
|
|
|
->getMock(); |
74
|
|
|
|
75
|
|
|
$this->command = new GetModelDetailsCommand( |
76
|
|
|
$this->statsFactory, |
77
|
|
|
$this->filterFactory |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @test |
83
|
|
|
*/ |
84
|
|
|
public function testCommandHasCorrectName() |
85
|
|
|
{ |
86
|
|
|
$this->assertEquals(GetModelDetailsCommand::COMMAND_NAME, $this->command->getName()); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @test |
91
|
|
|
*/ |
92
|
|
|
public function testCommandHasCorrectDescription() |
93
|
|
|
{ |
94
|
|
|
$this->assertEquals(GetModelDetailsCommand::COMMAND_DESC, $this->command->getDescription()); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @test |
99
|
|
|
*/ |
100
|
|
|
public function testCommandHasCorrectParams() |
101
|
|
|
{ |
102
|
|
|
$expectedArgumentCount = 2; |
103
|
|
|
$expectedOptionCount = 2; |
104
|
|
|
$expectedArgumentType = InputArgument::class; |
105
|
|
|
$expectedOptionType = InputOption::class; |
106
|
|
|
|
107
|
|
|
$commandDefinition = $this->command->getDefinition(); |
|
|
|
|
108
|
|
|
|
109
|
|
|
$this->assertEquals($expectedArgumentCount, $commandDefinition->getArgumentCount()); |
110
|
|
|
$this->assertInstanceOf( |
111
|
|
|
$expectedArgumentType, |
112
|
|
|
$commandDefinition->getArgument(GetModelDetailsCommand::MANUFACTURER_ARG_NAME) |
113
|
|
|
); |
114
|
|
|
$this->assertInstanceOf( |
115
|
|
|
$expectedArgumentType, |
116
|
|
|
$commandDefinition->getArgument(GetModelDetailsCommand::MODEL_ARG_NAME) |
117
|
|
|
); |
118
|
|
|
$this->assertEquals( |
119
|
|
|
GetModelDetailsCommand::MANUFACTURER_ARG_DESC, |
120
|
|
|
$commandDefinition->getArgument(GetModelDetailsCommand::MANUFACTURER_ARG_NAME)->getDescription() |
121
|
|
|
); |
122
|
|
|
$this->assertEquals( |
123
|
|
|
GetModelDetailsCommand::MODEL_ARG_DESC, |
124
|
|
|
$commandDefinition->getArgument(GetModelDetailsCommand::MODEL_ARG_NAME)->getDescription() |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$this->assertEquals($expectedOptionCount, count($commandDefinition->getOptions())); |
128
|
|
|
$this->assertInstanceOf( |
129
|
|
|
$expectedOptionType, |
130
|
|
|
$commandDefinition->getOption(GetModelDetailsCommand::FROM_YEAR_OPTION_NAME) |
131
|
|
|
); |
132
|
|
|
$this->assertInstanceOf( |
133
|
|
|
$expectedOptionType, |
134
|
|
|
$commandDefinition->getOption(GetModelDetailsCommand::TO_YEAR_OPTION_NAME) |
135
|
|
|
); |
136
|
|
|
$this->assertEquals( |
137
|
|
|
GetModelDetailsCommand::FROM_YEAR_OPTION_DESC, |
138
|
|
|
$commandDefinition->getOption(GetModelDetailsCommand::FROM_YEAR_OPTION_NAME)->getDescription() |
139
|
|
|
); |
140
|
|
|
$this->assertEquals( |
141
|
|
|
GetModelDetailsCommand::FROM_YEAR_OPTION_SHORTCUT, |
142
|
|
|
$commandDefinition->getOption(GetModelDetailsCommand::FROM_YEAR_OPTION_NAME)->getShortcut() |
143
|
|
|
); |
144
|
|
|
$this->assertEquals( |
145
|
|
|
GetModelDetailsCommand::TO_YEAR_OPTION_DESC, |
146
|
|
|
$commandDefinition->getOption(GetModelDetailsCommand::TO_YEAR_OPTION_NAME)->getDescription() |
147
|
|
|
); |
148
|
|
|
$this->assertEquals( |
149
|
|
|
GetModelDetailsCommand::TO_YEAR_OPTION_SHORTCUT, |
150
|
|
|
$commandDefinition->getOption(GetModelDetailsCommand::TO_YEAR_OPTION_NAME)->getShortcut() |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @test |
156
|
|
|
*/ |
157
|
|
|
public function testExecuteWithFilters() |
158
|
|
|
{ |
159
|
|
|
$this->input->expects($this->exactly(2)) |
|
|
|
|
160
|
|
|
->method('getArgument') |
161
|
|
|
->willReturnOnConsecutiveCalls('BMW', 'M3'); |
162
|
|
|
$this->input->expects($this->once()) |
163
|
|
|
->method('getOptions') |
164
|
|
|
->will( |
165
|
|
|
$this->returnValue( |
166
|
|
|
[ |
167
|
|
|
'from' => 2015 |
168
|
|
|
] |
169
|
|
|
) |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
$filter = $this->getMockBuilder(FilterInterface::class) |
173
|
|
|
->getMock(); |
174
|
|
|
|
175
|
|
|
$this->filterFactory->expects($this->once()) |
|
|
|
|
176
|
|
|
->method('create') |
177
|
|
|
->with('from', 2015) |
178
|
|
|
->will($this->returnValue($filter)); |
179
|
|
|
|
180
|
|
|
$statsMiddleware = $this->getMockBuilder(Stats::class) |
181
|
|
|
->disableOriginalConstructor() |
182
|
|
|
->getMock(); |
183
|
|
|
$this->statsFactory->expects($this->once()) |
|
|
|
|
184
|
|
|
->method('create') |
185
|
|
|
->will($this->returnValue($statsMiddleware)); |
186
|
|
|
|
187
|
|
|
$stats = $this->getMockBuilder(StatsDTOInterface::class) |
188
|
|
|
->disableOriginalConstructor() |
189
|
|
|
->getMock(); |
190
|
|
|
$statsMiddleware->expects($this->once()) |
191
|
|
|
->method('getStats') |
192
|
|
|
->will($this->returnValue($stats)); |
193
|
|
|
|
194
|
|
|
$stats->expects($this->once()) |
195
|
|
|
->method('getAverageMileage') |
196
|
|
|
->will($this->returnValue(300.21)); |
197
|
|
|
$stats->expects($this->once()) |
198
|
|
|
->method('getAveragePrice') |
199
|
|
|
->will($this->returnValue(300.21)); |
200
|
|
|
$stats->expects($this->once()) |
201
|
|
|
->method('getAverageYear') |
202
|
|
|
->will($this->returnValue(300.21)); |
203
|
|
|
|
204
|
|
|
$this->output->expects($this->exactly(6)) |
|
|
|
|
205
|
|
|
->method('writeln'); |
206
|
|
|
|
207
|
|
|
$reflection = new \ReflectionClass(get_class($this->command)); |
208
|
|
|
$method = $reflection->getMethod('execute'); |
209
|
|
|
$method->setAccessible(true); |
210
|
|
|
|
211
|
|
|
$method->invokeArgs($this->command, [$this->input, $this->output]); |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
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.