|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Tests\Functional\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Paraunit\Command\ParallelCommand; |
|
8
|
|
|
use Paraunit\Configuration\ParallelConfiguration; |
|
9
|
|
|
use Symfony\Component\Console\Application; |
|
10
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
11
|
|
|
use Tests\BaseTestCase; |
|
12
|
|
|
use Tests\Stub\MissingProviderTestStub; |
|
13
|
|
|
use Tests\Stub\MySQLDeadLockTestStub; |
|
14
|
|
|
use Tests\Stub\RaisingDeprecationTestStub; |
|
15
|
|
|
use Tests\Stub\RaisingNoticeTestStub; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class ParallelCommandTest |
|
19
|
|
|
* @package Tests\Functional\Command |
|
20
|
|
|
*/ |
|
21
|
|
|
class ParallelCommandTest extends BaseTestCase |
|
22
|
|
|
{ |
|
23
|
|
View Code Duplication |
public function testExecutionAllGreen() |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
$configurationPath = $this->getConfigForStubs(); |
|
26
|
|
|
$application = new Application(); |
|
27
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
28
|
|
|
|
|
29
|
|
|
$command = $application->find('run'); |
|
30
|
|
|
$commandTester = new CommandTester($command); |
|
31
|
|
|
$exitCode = $commandTester->execute([ |
|
32
|
|
|
'command' => $command->getName(), |
|
33
|
|
|
'--configuration' => $configurationPath, |
|
34
|
|
|
'stringFilter' => 'green', |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
$output = $commandTester->getDisplay(); |
|
38
|
|
|
$this->assertNotContains('NO TESTS EXECUTED', $output); |
|
39
|
|
|
$this->assertNotContains('Executed: 0 test classes', $output); |
|
40
|
|
|
$this->assertNotContains('ABNORMAL TERMINATIONS', $output); |
|
41
|
|
|
$this->assertEquals(0, $exitCode); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
View Code Duplication |
public function testExecutionAllGreenWithRepeatOption() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$configurationPath = $this->getConfigForStubs(); |
|
47
|
|
|
$application = new Application(); |
|
48
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
49
|
|
|
|
|
50
|
|
|
$command = $application->find('run'); |
|
51
|
|
|
$commandTester = new CommandTester($command); |
|
52
|
|
|
$exitCode = $commandTester->execute([ |
|
53
|
|
|
'command' => $command->getName(), |
|
54
|
|
|
'--configuration' => $configurationPath, |
|
55
|
|
|
'--repeat' => '1', |
|
56
|
|
|
'stringFilter' => 'green', |
|
57
|
|
|
]); |
|
58
|
|
|
|
|
59
|
|
|
$output = $commandTester->getDisplay(); |
|
60
|
|
|
$this->assertNotContains('NO TESTS EXECUTED', $output); |
|
61
|
|
|
$this->assertNotContains('Executed: 0 test classes', $output); |
|
62
|
|
|
$this->assertNotContains('ABNORMAL TERMINATIONS', $output); |
|
63
|
|
|
$this->assertEquals(0, $exitCode); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testExecution() |
|
67
|
|
|
{ |
|
68
|
|
|
$configurationPath = $this->getConfigForStubs(); |
|
69
|
|
|
$application = new Application(); |
|
70
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
71
|
|
|
|
|
72
|
|
|
$command = $application->find('run'); |
|
73
|
|
|
$commandTester = new CommandTester($command); |
|
74
|
|
|
$exitCode = $commandTester->execute([ |
|
75
|
|
|
'command' => $command->getName(), |
|
76
|
|
|
'--configuration' => $configurationPath, |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
|
|
$output = $commandTester->getDisplay(); |
|
80
|
|
|
$this->assertNotContains('BBBBbBBBBBBB', $output, 'Shark logo shown but not required'); |
|
81
|
|
|
$this->assertNotContains('NO TESTS EXECUTED', $output); |
|
82
|
|
|
$this->assertNotContains('Executed: 0 test classes', $output); |
|
83
|
|
|
$this->assertContains('ABNORMAL TERMINATIONS', $output); |
|
84
|
|
|
$this->assertContains('ParseErrorTestStub.php', $output); |
|
85
|
|
|
$this->assertContains(RaisingNoticeTestStub::class, $output); |
|
86
|
|
|
$this->assertContains(MissingProviderTestStub::class, $output); |
|
87
|
|
|
$this->assertContains(MySQLDeadLockTestStub::class, $output); |
|
88
|
|
|
$this->assertNotEquals(0, $exitCode); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertContains('Executed: 13 test classes (18 retried), 23 tests', $output); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
View Code Duplication |
public function testExecutionWithLogo() |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
$configurationPath = $this->getConfigForStubs(); |
|
96
|
|
|
$application = new Application(); |
|
97
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
98
|
|
|
|
|
99
|
|
|
$command = $application->find('run'); |
|
100
|
|
|
$commandTester = new CommandTester($command); |
|
101
|
|
|
$commandTester->execute([ |
|
102
|
|
|
'command' => $command->getName(), |
|
103
|
|
|
'--logo' => $configurationPath, |
|
104
|
|
|
'--filter' => 'doNotExecuteAnyTestSoItsFaster', |
|
105
|
|
|
]); |
|
106
|
|
|
|
|
107
|
|
|
$output = $commandTester->getDisplay(); |
|
108
|
|
|
$this->assertContains('BBBBbBBBBBBB', $output, 'Shark logo missing'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testExecutionWithDebugEnabled() |
|
112
|
|
|
{ |
|
113
|
|
|
$configurationPath = $this->getConfigForStubs(); |
|
114
|
|
|
$application = new Application(); |
|
115
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
116
|
|
|
|
|
117
|
|
|
$command = $application->find('run'); |
|
118
|
|
|
$commandTester = new CommandTester($command); |
|
119
|
|
|
$exitCode = $commandTester->execute([ |
|
120
|
|
|
'command' => $command->getName(), |
|
121
|
|
|
'--configuration' => $configurationPath, |
|
122
|
|
|
'--debug' => true, |
|
123
|
|
|
]); |
|
124
|
|
|
|
|
125
|
|
|
$output = $commandTester->getDisplay(); |
|
126
|
|
|
$this->assertNotEquals(0, $exitCode); |
|
127
|
|
|
|
|
128
|
|
|
$classExecuted = 13; |
|
129
|
|
|
$processRetried = 18; |
|
130
|
|
|
$processesCount = $classExecuted + $processRetried; |
|
131
|
|
|
$this->assertContains( |
|
132
|
|
|
sprintf('Executed: %d test classes (%d retried), 23 tests', $classExecuted, $processRetried), |
|
133
|
|
|
$output, |
|
134
|
|
|
'Precondition failed' |
|
135
|
|
|
); |
|
136
|
|
|
$this->assertSame($processesCount, substr_count($output, 'PROCESS STARTED')); |
|
137
|
|
|
$this->assertSame($processesCount, substr_count($output, 'PROCESS TERMINATED')); |
|
138
|
|
|
$this->assertSame($classExecuted, substr_count($output, 'PROCESS PARSING COMPLETED')); |
|
139
|
|
|
$this->assertSame($processRetried, substr_count($output, 'PROCESS TO BE RETRIED')); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
View Code Duplication |
public function testExecutionWithParametersWithoutValue() |
|
|
|
|
|
|
143
|
|
|
{ |
|
144
|
|
|
$configurationPath = $this->getConfigForStubs(); |
|
145
|
|
|
$application = new Application(); |
|
146
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
147
|
|
|
|
|
148
|
|
|
$command = $application->find('run'); |
|
149
|
|
|
$commandTester = new CommandTester($command); |
|
150
|
|
|
$exitCode = $commandTester->execute([ |
|
151
|
|
|
'command' => $command->getName(), |
|
152
|
|
|
'--configuration' => $configurationPath, |
|
153
|
|
|
'stringFilter' => 'green', |
|
154
|
|
|
'--dont-report-useless-tests' => true, |
|
155
|
|
|
]); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertSame(0, $exitCode); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
View Code Duplication |
public function testExecutionWithoutConfiguration() |
|
|
|
|
|
|
161
|
|
|
{ |
|
162
|
|
|
$application = new Application(); |
|
163
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
164
|
|
|
|
|
165
|
|
|
$command = $application->find('run'); |
|
166
|
|
|
$commandTester = new CommandTester($command); |
|
167
|
|
|
$exitCode = $commandTester->execute([ |
|
168
|
|
|
'command' => $command->getName(), |
|
169
|
|
|
'--filter' => 'do_not_execute_anything', |
|
170
|
|
|
]); |
|
171
|
|
|
|
|
172
|
|
|
$output = $commandTester->getDisplay(); |
|
173
|
|
|
$this->assertContains('NO TESTS EXECUTED', $output); |
|
174
|
|
|
$this->assertContains('0 tests', $output); |
|
175
|
|
|
$this->assertSame(0, $exitCode); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function testExecutionWithDeprecationListener() |
|
179
|
|
|
{ |
|
180
|
|
|
$application = new Application(); |
|
181
|
|
|
$application->add(new ParallelCommand(new ParallelConfiguration())); |
|
182
|
|
|
|
|
183
|
|
|
$command = $application->find('run'); |
|
184
|
|
|
$commandTester = new CommandTester($command); |
|
185
|
|
|
$exitCode = $commandTester->execute([ |
|
186
|
|
|
'command' => $command->getName(), |
|
187
|
|
|
'--configuration' => $this->getConfigForDeprecationListener(), |
|
188
|
|
|
]); |
|
189
|
|
|
|
|
190
|
|
|
$output = $commandTester->getDisplay(); |
|
191
|
|
|
$this->assertNotEquals(0, $exitCode); |
|
192
|
|
|
$this->assertContains('Executed: 1 test classes, 3 tests', $output, 'Precondition failed'); |
|
193
|
|
|
$this->assertContains('1 files with DEPRECATION WARNINGS:', $output); |
|
194
|
|
|
$this->assertContains(RaisingDeprecationTestStub::DEPRECATION_MESSAGE, $output); |
|
195
|
|
|
$this->assertContains('RaisingDeprecationTestStub::testDeprecation', $output); |
|
196
|
|
|
$this->assertNotContains('2)', $output, 'Deprecations are shown more than once per test file'); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.