Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Tests\simpletest\Unit; | 3 namespace Drupal\Tests\simpletest\Unit; |
4 | 4 |
5 use Composer\Autoload\ClassLoader; | 5 use Composer\Autoload\ClassLoader; |
6 use Drupal\Core\DependencyInjection\Container; | |
7 use Drupal\Core\DrupalKernel; | |
6 use Drupal\Core\Extension\Extension; | 8 use Drupal\Core\Extension\Extension; |
7 use Drupal\Core\Extension\ModuleHandlerInterface; | 9 use Drupal\Core\Extension\ModuleHandlerInterface; |
8 use Drupal\simpletest\Exception\MissingGroupException; | 10 use Drupal\simpletest\Exception\MissingGroupException; |
9 use Drupal\simpletest\TestDiscovery; | 11 use Drupal\simpletest\TestDiscovery; |
10 use Drupal\Tests\UnitTestCase; | 12 use Drupal\Tests\UnitTestCase; |
28 public function infoParserProvider() { | 30 public function infoParserProvider() { |
29 // A module provided unit test. | 31 // A module provided unit test. |
30 $tests[] = [ | 32 $tests[] = [ |
31 // Expected result. | 33 // Expected result. |
32 [ | 34 [ |
33 'name' => 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest', | 35 'name' => static::class, |
34 'group' => 'simpletest', | 36 'group' => 'simpletest', |
37 'groups' => ['simpletest'], | |
35 'description' => 'Tests \Drupal\simpletest\TestDiscovery.', | 38 'description' => 'Tests \Drupal\simpletest\TestDiscovery.', |
36 'type' => 'PHPUnit-Unit', | 39 'type' => 'PHPUnit-Unit', |
37 ], | 40 ], |
38 // Classname. | 41 // Classname. |
39 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest', | 42 static::class, |
40 ]; | 43 ]; |
41 | 44 |
42 // A core unit test. | 45 // A core unit test. |
43 $tests[] = [ | 46 $tests[] = [ |
44 // Expected result. | 47 // Expected result. |
45 [ | 48 [ |
46 'name' => 'Drupal\Tests\Core\DrupalTest', | 49 'name' => 'Drupal\Tests\Core\DrupalTest', |
47 'group' => 'DrupalTest', | 50 'group' => 'DrupalTest', |
51 'groups' => ['DrupalTest'], | |
48 'description' => 'Tests \Drupal.', | 52 'description' => 'Tests \Drupal.', |
49 'type' => 'PHPUnit-Unit', | 53 'type' => 'PHPUnit-Unit', |
50 ], | 54 ], |
51 // Classname. | 55 // Classname. |
52 'Drupal\Tests\Core\DrupalTest', | 56 'Drupal\Tests\Core\DrupalTest', |
56 $tests[] = [ | 60 $tests[] = [ |
57 // Expected result. | 61 // Expected result. |
58 [ | 62 [ |
59 'name' => 'Drupal\FunctionalTests\BrowserTestBaseTest', | 63 'name' => 'Drupal\FunctionalTests\BrowserTestBaseTest', |
60 'group' => 'browsertestbase', | 64 'group' => 'browsertestbase', |
65 'groups' => ['browsertestbase'], | |
61 'description' => 'Tests BrowserTestBase functionality.', | 66 'description' => 'Tests BrowserTestBase functionality.', |
62 'type' => 'PHPUnit-Functional', | 67 'type' => 'PHPUnit-Functional', |
63 ], | 68 ], |
64 // Classname. | 69 // Classname. |
65 'Drupal\FunctionalTests\BrowserTestBaseTest', | 70 'Drupal\FunctionalTests\BrowserTestBaseTest', |
69 $tests['phpunit-kernel'] = [ | 74 $tests['phpunit-kernel'] = [ |
70 // Expected result. | 75 // Expected result. |
71 [ | 76 [ |
72 'name' => '\Drupal\Tests\file\Kernel\FileItemValidationTest', | 77 'name' => '\Drupal\Tests\file\Kernel\FileItemValidationTest', |
73 'group' => 'file', | 78 'group' => 'file', |
79 'groups' => ['file'], | |
74 'description' => 'Tests that files referenced in file and image fields are always validated.', | 80 'description' => 'Tests that files referenced in file and image fields are always validated.', |
75 'type' => 'PHPUnit-Kernel', | 81 'type' => 'PHPUnit-Kernel', |
76 ], | 82 ], |
77 // Classname. | 83 // Classname. |
78 '\Drupal\Tests\file\Kernel\FileItemValidationTest', | 84 '\Drupal\Tests\file\Kernel\FileItemValidationTest', |
83 $tests[] = [ | 89 $tests[] = [ |
84 // Expected result. | 90 // Expected result. |
85 [ | 91 [ |
86 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | 92 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', |
87 'group' => 'simpletest', | 93 'group' => 'simpletest', |
94 'groups' => ['simpletest'], | |
88 'description' => 'Tests the Simpletest UI internal browser.', | 95 'description' => 'Tests the Simpletest UI internal browser.', |
89 'type' => 'Simpletest', | 96 'type' => 'Simpletest', |
90 ], | 97 ], |
91 // Classname. | 98 // Classname. |
92 'Drupal\simpletest\Tests\ExampleSimpleTest', | 99 'Drupal\simpletest\Tests\ExampleSimpleTest', |
103 $tests[] = [ | 110 $tests[] = [ |
104 // Expected result. | 111 // Expected result. |
105 [ | 112 [ |
106 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | 113 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', |
107 'group' => 'simpletest', | 114 'group' => 'simpletest', |
115 'groups' => ['simpletest'], | |
108 'description' => 'Tests the Simpletest UI internal browser.', | 116 'description' => 'Tests the Simpletest UI internal browser.', |
109 'type' => 'Simpletest', | 117 'type' => 'Simpletest', |
110 ], | 118 ], |
111 // Classname. | 119 // Classname. |
112 'Drupal\simpletest\Tests\ExampleSimpleTest', | 120 'Drupal\simpletest\Tests\ExampleSimpleTest', |
125 $tests[] = [ | 133 $tests[] = [ |
126 // Expected result. | 134 // Expected result. |
127 [ | 135 [ |
128 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | 136 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', |
129 'group' => 'simpletest', | 137 'group' => 'simpletest', |
138 'groups' => ['simpletest'], | |
130 'description' => 'Tests the Simpletest UI internal browser. * @', | 139 'description' => 'Tests the Simpletest UI internal browser. * @', |
131 'type' => 'Simpletest', | 140 'type' => 'Simpletest', |
132 ], | 141 ], |
133 // Classname. | 142 // Classname. |
134 'Drupal\simpletest\Tests\ExampleSimpleTest', | 143 'Drupal\simpletest\Tests\ExampleSimpleTest', |
145 $tests[] = [ | 154 $tests[] = [ |
146 // Expected result. | 155 // Expected result. |
147 [ | 156 [ |
148 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | 157 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', |
149 'group' => 'Test', | 158 'group' => 'Test', |
159 'groups' => ['Test', 'simpletest'], | |
150 'description' => 'Tests the Simpletest UI internal browser.', | 160 'description' => 'Tests the Simpletest UI internal browser.', |
151 'type' => 'Simpletest', | 161 'type' => 'Simpletest', |
152 ], | 162 ], |
153 // Classname. | 163 // Classname. |
154 'Drupal\simpletest\Tests\ExampleSimpleTest', | 164 'Drupal\simpletest\Tests\ExampleSimpleTest', |
160 * @group simpletest | 170 * @group simpletest |
161 */ | 171 */ |
162 ", | 172 ", |
163 ]; | 173 ]; |
164 | 174 |
175 // A great number of @group annotations. | |
176 $tests['many-group-annotations'] = [ | |
177 // Expected result. | |
178 [ | |
179 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | |
180 'group' => 'Test', | |
181 'groups' => ['Test', 'simpletest', 'another', 'more', 'many', 'enough', 'whoa'], | |
182 'description' => 'Tests the Simpletest UI internal browser.', | |
183 'type' => 'Simpletest', | |
184 ], | |
185 // Classname. | |
186 'Drupal\simpletest\Tests\ExampleSimpleTest', | |
187 // Doc block. | |
188 "/** | |
189 * Tests the Simpletest UI internal browser. | |
190 * | |
191 * @group Test | |
192 * @group simpletest | |
193 * @group another | |
194 * @group more | |
195 * @group many | |
196 * @group enough | |
197 * @group whoa | |
198 */ | |
199 ", | |
200 ]; | |
201 | |
165 // @dependencies annotation. | 202 // @dependencies annotation. |
166 $tests[] = [ | 203 $tests[] = [ |
167 // Expected result. | 204 // Expected result. |
168 [ | 205 [ |
169 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | 206 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', |
170 'description' => 'Tests the Simpletest UI internal browser.', | 207 'description' => 'Tests the Simpletest UI internal browser.', |
171 'type' => 'Simpletest', | 208 'type' => 'Simpletest', |
172 'requires' => ['module' => ['test']], | 209 'requires' => ['module' => ['test']], |
173 'group' => 'simpletest', | 210 'group' => 'simpletest', |
211 'groups' => ['simpletest'], | |
174 ], | 212 ], |
175 // Classname. | 213 // Classname. |
176 'Drupal\simpletest\Tests\ExampleSimpleTest', | 214 'Drupal\simpletest\Tests\ExampleSimpleTest', |
177 // Doc block. | 215 // Doc block. |
178 "/** | 216 "/** |
191 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | 229 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', |
192 'description' => 'Tests the Simpletest UI internal browser.', | 230 'description' => 'Tests the Simpletest UI internal browser.', |
193 'type' => 'Simpletest', | 231 'type' => 'Simpletest', |
194 'requires' => ['module' => ['test', 'test1', 'test2']], | 232 'requires' => ['module' => ['test', 'test1', 'test2']], |
195 'group' => 'simpletest', | 233 'group' => 'simpletest', |
234 'groups' => ['simpletest'], | |
196 ], | 235 ], |
197 // Classname. | 236 // Classname. |
198 'Drupal\simpletest\Tests\ExampleSimpleTest', | 237 'Drupal\simpletest\Tests\ExampleSimpleTest', |
199 // Doc block. | 238 // Doc block. |
200 "/** | 239 "/** |
212 [ | 251 [ |
213 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', | 252 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', |
214 'description' => 'Tests the Simpletest UI internal browser. And the summary line continues an there is no gap to the annotation.', | 253 'description' => 'Tests the Simpletest UI internal browser. And the summary line continues an there is no gap to the annotation.', |
215 'type' => 'Simpletest', | 254 'type' => 'Simpletest', |
216 'group' => 'simpletest', | 255 'group' => 'simpletest', |
256 'groups' => ['simpletest'], | |
217 ], | 257 ], |
218 // Classname. | 258 // Classname. |
219 'Drupal\simpletest\Tests\ExampleSimpleTest', | 259 'Drupal\simpletest\Tests\ExampleSimpleTest', |
220 // Doc block. | 260 // Doc block. |
221 "/** | 261 "/** |
266 /** | 306 /** |
267 * Test description | 307 * Test description |
268 * @group example | 308 * @group example |
269 */ | 309 */ |
270 class FunctionalExampleTest {} | 310 class FunctionalExampleTest {} |
311 EOF; | |
312 | |
313 $test_profile_info = <<<EOF | |
314 name: Testing | |
315 type: profile | |
316 core: 8.x | |
317 EOF; | |
318 | |
319 $test_module_info = <<<EOF | |
320 name: Testing | |
321 type: module | |
322 core: 8.x | |
271 EOF; | 323 EOF; |
272 | 324 |
273 vfsStream::create([ | 325 vfsStream::create([ |
274 'modules' => [ | 326 'modules' => [ |
275 'test_module' => [ | 327 'test_module' => [ |
278 'Functional' => [ | 330 'Functional' => [ |
279 'FunctionalExampleTest.php' => $test_file, | 331 'FunctionalExampleTest.php' => $test_file, |
280 'FunctionalExampleTest2.php' => str_replace(['FunctionalExampleTest', '@group example'], ['FunctionalExampleTest2', '@group example2'], $test_file), | 332 'FunctionalExampleTest2.php' => str_replace(['FunctionalExampleTest', '@group example'], ['FunctionalExampleTest2', '@group example2'], $test_file), |
281 ], | 333 ], |
282 'Kernel' => [ | 334 'Kernel' => [ |
283 'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', '@group example2'], $test_file), | 335 'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', "@group example2\n * @group kernel\n"], $test_file), |
284 'KernelExampleTestBase.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTestBase', '@group example2'], $test_file), | 336 'KernelExampleTestBase.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTestBase', '@group example2'], $test_file), |
285 'KernelExampleTrait.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTrait', '@group example2'], $test_file), | 337 'KernelExampleTrait.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTrait', '@group example2'], $test_file), |
286 'KernelExampleInterface.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleInterface', '@group example2'], $test_file), | 338 'KernelExampleInterface.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleInterface', '@group example2'], $test_file), |
287 ], | 339 ], |
288 ], | 340 ], |
289 ], | 341 ], |
290 ], | 342 ], |
291 ], | 343 ], |
344 'profiles' => [ | |
345 'test_profile' => [ | |
346 'test_profile.info.yml' => $test_profile_info, | |
347 'modules' => [ | |
348 'test_profile_module' => [ | |
349 'test_profile_module.info.yml' => $test_module_info, | |
350 'tests' => [ | |
351 'src' => [ | |
352 'Kernel' => [ | |
353 'KernelExampleTest4.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest4', '@group example3'], $test_file), | |
354 ], | |
355 ], | |
356 ], | |
357 ], | |
358 ], | |
359 ], | |
360 ], | |
292 ]); | 361 ]); |
293 } | 362 } |
294 | 363 |
295 /** | 364 /** |
296 * @covers ::getTestClasses | 365 * @covers ::getTestClasses |
305 $extensions = [ | 374 $extensions = [ |
306 'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'), | 375 'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'), |
307 ]; | 376 ]; |
308 $test_discovery->setExtensions($extensions); | 377 $test_discovery->setExtensions($extensions); |
309 $result = $test_discovery->getTestClasses(); | 378 $result = $test_discovery->getTestClasses(); |
310 $this->assertCount(2, $result); | 379 $this->assertCount(3, $result); |
311 $this->assertEquals([ | 380 $this->assertEquals([ |
312 'example' => [ | 381 'example' => [ |
313 'Drupal\Tests\test_module\Functional\FunctionalExampleTest' => [ | 382 'Drupal\Tests\test_module\Functional\FunctionalExampleTest' => [ |
314 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest', | 383 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest', |
315 'description' => 'Test description', | 384 'description' => 'Test description', |
316 'group' => 'example', | 385 'group' => 'example', |
386 'groups' => ['example'], | |
317 'type' => 'PHPUnit-Functional', | 387 'type' => 'PHPUnit-Functional', |
318 ], | 388 ], |
319 ], | 389 ], |
320 'example2' => [ | 390 'example2' => [ |
321 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2' => [ | 391 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2' => [ |
322 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2', | 392 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2', |
323 'description' => 'Test description', | 393 'description' => 'Test description', |
324 'group' => 'example2', | 394 'group' => 'example2', |
395 'groups' => ['example2'], | |
325 'type' => 'PHPUnit-Functional', | 396 'type' => 'PHPUnit-Functional', |
326 ], | 397 ], |
327 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ | 398 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ |
328 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', | 399 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', |
329 'description' => 'Test description', | 400 'description' => 'Test description', |
330 'group' => 'example2', | 401 'group' => 'example2', |
402 'groups' => ['example2', 'kernel'], | |
403 'type' => 'PHPUnit-Kernel', | |
404 ], | |
405 ], | |
406 'kernel' => [ | |
407 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ | |
408 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', | |
409 'description' => 'Test description', | |
410 'group' => 'example2', | |
411 'groups' => ['example2', 'kernel'], | |
331 'type' => 'PHPUnit-Kernel', | 412 'type' => 'PHPUnit-Kernel', |
332 ], | 413 ], |
333 ], | 414 ], |
334 ], $result); | 415 ], $result); |
335 } | 416 } |
344 | 425 |
345 $test_discovery = new TestTestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal()); | 426 $test_discovery = new TestTestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal()); |
346 | 427 |
347 $extensions = [ | 428 $extensions = [ |
348 'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'), | 429 'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'), |
430 'test_profile_module' => new Extension('vfs://drupal', 'profile', 'profiles/test_profile/modules/test_profile_module/test_profile_module.info.yml'), | |
349 ]; | 431 ]; |
350 $test_discovery->setExtensions($extensions); | 432 $test_discovery->setExtensions($extensions); |
351 $result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); | 433 $result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); |
352 $this->assertCount(2, $result); | 434 $this->assertCount(4, $result); |
353 $this->assertEquals([ | 435 $this->assertEquals([ |
354 'example' => [], | 436 'example' => [], |
355 'example2' => [ | 437 'example2' => [ |
356 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ | 438 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ |
357 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', | 439 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', |
358 'description' => 'Test description', | 440 'description' => 'Test description', |
359 'group' => 'example2', | 441 'group' => 'example2', |
442 'groups' => ['example2', 'kernel'], | |
360 'type' => 'PHPUnit-Kernel', | 443 'type' => 'PHPUnit-Kernel', |
361 ], | 444 ], |
362 ], | 445 ], |
446 'kernel' => [ | |
447 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ | |
448 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', | |
449 'description' => 'Test description', | |
450 'group' => 'example2', | |
451 'groups' => ['example2', 'kernel'], | |
452 'type' => 'PHPUnit-Kernel', | |
453 ], | |
454 ], | |
455 'example3' => [ | |
456 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ | |
457 'name' => 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4', | |
458 'description' => 'Test description', | |
459 'group' => 'example3', | |
460 'groups' => ['example3'], | |
461 'type' => 'PHPUnit-Kernel', | |
462 ], | |
463 ], | |
363 ], $result); | 464 ], $result); |
465 } | |
466 | |
467 /** | |
468 * @covers ::getTestClasses | |
469 */ | |
470 public function testGetTestsInProfiles() { | |
471 $this->setupVfsWithTestClasses(); | |
472 $class_loader = $this->prophesize(ClassLoader::class); | |
473 $module_handler = $this->prophesize(ModuleHandlerInterface::class); | |
474 | |
475 $container = new Container(); | |
476 $container->set('kernel', new DrupalKernel('prod', new ClassLoader())); | |
477 $container->set('site.path', 'sites/default'); | |
478 \Drupal::setContainer($container); | |
479 | |
480 $test_discovery = new TestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal()); | |
481 | |
482 $result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); | |
483 $expected = [ | |
484 'example3' => [ | |
485 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ | |
486 'name' => 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4', | |
487 'description' => 'Test description', | |
488 'group' => 'example3', | |
489 'groups' => ['example3'], | |
490 'type' => 'PHPUnit-Kernel', | |
491 ], | |
492 ], | |
493 ]; | |
494 $this->assertEquals($expected, $result); | |
364 } | 495 } |
365 | 496 |
366 /** | 497 /** |
367 * @covers ::getPhpunitTestSuite | 498 * @covers ::getPhpunitTestSuite |
368 * @dataProvider providerTestGetPhpunitTestSuite | 499 * @dataProvider providerTestGetPhpunitTestSuite |
437 protected function getExtensions() { | 568 protected function getExtensions() { |
438 return $this->extensions; | 569 return $this->extensions; |
439 } | 570 } |
440 | 571 |
441 } | 572 } |
442 | |
443 namespace Drupal\simpletest\Tests; | |
444 | |
445 use Drupal\simpletest\WebTestBase; | |
446 | |
447 /** | |
448 * Tests the Simpletest UI internal browser. | |
449 * | |
450 * @group simpletest | |
451 */ | |
452 class ExampleSimpleTest extends WebTestBase { | |
453 } |