|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Smartbox\CoreBundle\Tests\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Smartbox\CoreBundle\Utils\SmokeTest\Output\SmokeTestOutputInterface; |
|
8
|
|
|
use Smartbox\CoreBundle\Utils\SmokeTest\SmokeTestInterface; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
10
|
|
|
use Smartbox\CoreBundle\Command\SmokeTestRunCommand; |
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
12
|
|
|
use Symfony\Component\Console\Command\Command; |
|
13
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
14
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
15
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @group smoke-test |
|
19
|
|
|
*/ |
|
20
|
|
|
class SmokeTestRunCommandTest extends KernelTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var Application |
|
24
|
|
|
*/ |
|
25
|
|
|
private $application; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $commandConfiguration = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var Command |
|
34
|
|
|
*/ |
|
35
|
|
|
private $command; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var CommandTester |
|
39
|
|
|
*/ |
|
40
|
|
|
private $commandTester; |
|
41
|
|
|
|
|
42
|
|
|
public function setUp() |
|
43
|
|
|
{ |
|
44
|
|
|
$kernel = $this->createKernel(); |
|
45
|
|
|
$kernel->boot(); |
|
46
|
|
|
|
|
47
|
|
|
$this->application = new Application($kernel); |
|
48
|
|
|
$this->application->add(new SmokeTestRunCommand()); |
|
49
|
|
|
|
|
50
|
|
|
$this->command = $this->application->find('smartbox:smoke-test'); |
|
51
|
|
|
$this->commandTester = new CommandTester($this->command); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function tearDown() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->application = null; |
|
57
|
|
|
$this->command = null; |
|
58
|
|
|
$this->commandTester = null; |
|
59
|
|
|
$this->commandConfiguration = null; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
public function testSmokeTestCommandNoLabels() |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
$smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
|
65
|
|
|
$smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
|
66
|
|
|
$smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
|
67
|
|
|
|
|
68
|
|
|
$smokeTest1 = $this->createMock(SmokeTestInterface::class); |
|
69
|
|
|
$smokeTest1->expects($this->never())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
70
|
|
|
$smokeTest1->expects($this->never())->method('getDescription'); |
|
71
|
|
|
|
|
72
|
|
|
$smokeTest2 = $this->createMock(SmokeTestInterface::class); |
|
73
|
|
|
$smokeTest2->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
74
|
|
|
$smokeTest2->expects($this->once())->method('getDescription'); |
|
75
|
|
|
|
|
76
|
|
|
$smokeTestRunCommand = new SmokeTestRunCommand(); |
|
77
|
|
|
$smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
|
78
|
|
|
$smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
|
79
|
|
|
|
|
80
|
|
|
$smokeTestRunCommand->run(new ArrayInput(['--label' => []]), new NullOutput()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
View Code Duplication |
public function testMockSmokeTestCommandWipLabel() |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
|
86
|
|
|
$smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
|
87
|
|
|
$smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
|
88
|
|
|
|
|
89
|
|
|
$smokeTest1 = $this->createMock(SmokeTestInterface::class); |
|
90
|
|
|
$smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
91
|
|
|
$smokeTest1->expects($this->once())->method('getDescription'); |
|
92
|
|
|
|
|
93
|
|
|
$smokeTest2 = $this->createMock(SmokeTestInterface::class); |
|
94
|
|
|
$smokeTest2->expects($this->never())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
95
|
|
|
$smokeTest2->expects($this->never())->method('getDescription'); |
|
96
|
|
|
|
|
97
|
|
|
$smokeTestRunCommand = new SmokeTestRunCommand(); |
|
98
|
|
|
$smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
|
99
|
|
|
$smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
|
100
|
|
|
|
|
101
|
|
|
$smokeTestRunCommand->run(new ArrayInput(['--label' => ['wip']]), new NullOutput()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
public function testMockSmokeTestCommandAllTests() |
|
|
|
|
|
|
105
|
|
|
{ |
|
106
|
|
|
$smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class); |
|
107
|
|
|
$smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true)); |
|
108
|
|
|
$smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([])); |
|
109
|
|
|
|
|
110
|
|
|
$smokeTest1 = $this->createMock(SmokeTestInterface::class); |
|
111
|
|
|
$smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
112
|
|
|
$smokeTest1->expects($this->once())->method('getDescription'); |
|
113
|
|
|
|
|
114
|
|
|
$smokeTest2 = $this->createMock(SmokeTestInterface::class); |
|
115
|
|
|
$smokeTest2->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput)); |
|
116
|
|
|
$smokeTest2->expects($this->once())->method('getDescription'); |
|
117
|
|
|
|
|
118
|
|
|
$smokeTestRunCommand = new SmokeTestRunCommand(); |
|
119
|
|
|
$smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']); |
|
120
|
|
|
$smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']); |
|
121
|
|
|
|
|
122
|
|
|
$smokeTestRunCommand->run(new ArrayInput(['--all' => true]), new NullOutput()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testExecute() |
|
126
|
|
|
{ |
|
127
|
|
|
$output = $this->execute(); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertInternalType('string', $output); |
|
130
|
|
|
$this->assertContains('Smoke Tests', $output); |
|
131
|
|
|
$this->assertNotContains('Error', $output); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function testFilterByLabels() |
|
135
|
|
|
{ |
|
136
|
|
|
$label = ['-l' => 'important']; |
|
137
|
|
|
|
|
138
|
|
|
$this->setCommandConfiguration($label); |
|
139
|
|
|
$output = $this->execute(); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertInternalType('string', $output); |
|
142
|
|
|
$this->assertContains('Smoke Tests', $output); |
|
143
|
|
|
$this->assertNotContains('Error', $output); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
private function execute() |
|
147
|
|
|
{ |
|
148
|
|
|
$this->commandTester->execute([ |
|
149
|
|
|
'command' => $this->command->getName(), |
|
150
|
|
|
], |
|
151
|
|
|
$this->commandConfiguration |
|
152
|
|
|
); |
|
153
|
|
|
|
|
154
|
|
|
return $this->commandTester->getDisplay(); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
private function setCommandConfiguration($options = []) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->commandConfiguration = $options; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
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..