|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Smartbox\CoreBundle\Tests\Command; |
|
4
|
|
|
|
|
5
|
|
|
use JMS\Serializer\SerializerInterface; |
|
6
|
|
|
use Smartbox\CoreBundle\Utils\SmokeTest\Output\SmokeTestOutputInterface; |
|
7
|
|
|
use Smartbox\CoreBundle\Utils\SmokeTest\SmokeTestInterface; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
9
|
|
|
use Smartbox\CoreBundle\Command\SmokeTestRunCommand; |
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
11
|
|
|
use Symfony\Component\Console\Command\Command; |
|
12
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
13
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
14
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @group smoke-test |
|
20
|
|
|
*/ |
|
21
|
|
|
class SmokeTestRunCommandTest extends KernelTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Application |
|
26
|
|
|
*/ |
|
27
|
|
|
private $application; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var SerializerInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $serializer; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var Container |
|
36
|
|
|
*/ |
|
37
|
|
|
private $container; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private $commandConfiguration = []; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var Command |
|
46
|
|
|
*/ |
|
47
|
|
|
private $command; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var CommandTester |
|
51
|
|
|
*/ |
|
52
|
|
|
private $commandTester; |
|
53
|
|
|
|
|
54
|
|
|
public function setUp() |
|
55
|
|
|
{ |
|
56
|
|
|
$kernel = $this->createKernel(); |
|
57
|
|
|
$kernel->boot(); |
|
58
|
|
|
|
|
59
|
|
|
$this->application = new Application($kernel); |
|
60
|
|
|
$this->application->add(new SmokeTestRunCommand()); |
|
61
|
|
|
|
|
62
|
|
|
$this->container = $kernel->getContainer(); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$this->serializer = $this->container->get('jms_serializer'); |
|
65
|
|
|
|
|
66
|
|
|
$this->command = $this->application->find('smartbox:smoke-test'); |
|
67
|
|
|
$this->commandTester = new CommandTester($this->command); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function tearDown() |
|
71
|
|
|
{ |
|
72
|
|
|
parent::tearDown(); // TODO: Change the autogenerated stub |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
View Code Duplication |
public function testSmokeTestCommandNoLabels() |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
$smokeTestInput = $this->createMock(InputInterface::class); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
|
80
|
|
|
$smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
|
81
|
|
|
$smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
|
82
|
|
|
|
|
83
|
|
|
$smokeTest1 = $this->createMock(SmokeTestInterface::class); |
|
84
|
|
|
$smokeTest1->expects($this->never())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
85
|
|
|
$smokeTest1->expects($this->never())->method('getDescription'); |
|
86
|
|
|
|
|
87
|
|
|
$smokeTest2 = $this->createMock(SmokeTestInterface::class); |
|
88
|
|
|
$smokeTest2->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
89
|
|
|
$smokeTest2->expects($this->once())->method('getDescription'); |
|
90
|
|
|
|
|
91
|
|
|
$smokeTestRunCommand = new SmokeTestRunCommand(); |
|
92
|
|
|
$smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
|
93
|
|
|
$smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
|
94
|
|
|
|
|
95
|
|
|
$smokeTestRunCommand->run(new ArrayInput(['--label' => []]), new NullOutput()); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
View Code Duplication |
public function testMockSmokeTestCommandWipLabel() |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
$smokeTestInput = $this->createMock(InputInterface::class); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
$smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
|
103
|
|
|
$smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
|
104
|
|
|
$smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
|
105
|
|
|
|
|
106
|
|
|
$smokeTest1 = $this->createMock(SmokeTestInterface::class); |
|
107
|
|
|
$smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
108
|
|
|
$smokeTest1->expects($this->once())->method('getDescription'); |
|
109
|
|
|
|
|
110
|
|
|
$smokeTest2 = $this->createMock(SmokeTestInterface::class); |
|
111
|
|
|
$smokeTest2->expects($this->never())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
112
|
|
|
$smokeTest2->expects($this->never())->method('getDescription'); |
|
113
|
|
|
|
|
114
|
|
|
$smokeTestRunCommand = new SmokeTestRunCommand(); |
|
115
|
|
|
$smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
|
116
|
|
|
$smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
|
117
|
|
|
|
|
118
|
|
|
$smokeTestRunCommand->run(new ArrayInput(['--label' => ['wip']]), new NullOutput()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
View Code Duplication |
public function testMockSmokeTestCommandAllTests() |
|
|
|
|
|
|
122
|
|
|
{ |
|
123
|
|
|
$smokeTestInput = $this->createMock(InputInterface::class); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
$smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
|
126
|
|
|
$smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
|
127
|
|
|
$smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
|
128
|
|
|
|
|
129
|
|
|
$smokeTest1 = $this->createMock(SmokeTestInterface::class); |
|
130
|
|
|
$smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
131
|
|
|
$smokeTest1->expects($this->once())->method('getDescription'); |
|
132
|
|
|
|
|
133
|
|
|
$smokeTest2 = $this->createMock(SmokeTestInterface::class); |
|
134
|
|
|
$smokeTest2->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
135
|
|
|
$smokeTest2->expects($this->once())->method('getDescription'); |
|
136
|
|
|
|
|
137
|
|
|
$smokeTestRunCommand = new SmokeTestRunCommand(); |
|
138
|
|
|
$smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
|
139
|
|
|
$smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
|
140
|
|
|
|
|
141
|
|
|
$smokeTestRunCommand->run(new ArrayInput(['--all' => true]), new NullOutput()); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
private function setCommandConfiguration($options = []) |
|
145
|
|
|
{ |
|
146
|
|
|
$this->commandConfiguration = $options; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function execute($options = []) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->commandTester->execute([ |
|
152
|
|
|
'command' => $this->command->getName(), |
|
153
|
|
|
], |
|
154
|
|
|
$this->commandConfiguration |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
return $this->commandTester->getDisplay(); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @group smoke-test-label |
|
162
|
|
|
*/ |
|
163
|
|
|
public function testExecute() |
|
164
|
|
|
{ |
|
165
|
|
|
$output = $this->execute(); |
|
166
|
|
|
$this->assertContains('Smoke Tests', $output); |
|
167
|
|
|
$this->assertTrue(is_string($output)); |
|
168
|
|
|
$this->assertNotContains('Error', $output); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @group smoke-test-label |
|
173
|
|
|
*/ |
|
174
|
|
|
public function testFilterByLabels() |
|
175
|
|
|
{ |
|
176
|
|
|
$label = ['-l' => 'important']; |
|
177
|
|
|
$this->setCommandConfiguration($label); |
|
178
|
|
|
$output = $this->execute(); |
|
179
|
|
|
$this->assertContains('Smoke Tests', $output); |
|
180
|
|
|
$this->assertTrue(is_string($output)); |
|
181
|
|
|
$this->assertNotContains('Error', $output); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @group smoke-test-silent |
|
186
|
|
|
*/ |
|
187
|
|
|
/*public function testSilentOption() |
|
188
|
|
|
{ |
|
189
|
|
|
$options = ['-q']; |
|
190
|
|
|
$this->commandConfiguration = $options; |
|
191
|
|
|
$output = $this->execute(); |
|
192
|
|
|
var_dump($output);die; |
|
193
|
|
|
|
|
194
|
|
|
$this->assertContains('Smoke Tests', $output); |
|
195
|
|
|
$this->assertTrue(is_string($output)); |
|
196
|
|
|
$this->assertNotContains('Error', $output); |
|
197
|
|
|
}*/ |
|
198
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..