@@ -89,17 +89,12 @@ public function register(Container $container): void
89
89
return strpos ($ a ->getName (), '_test ' ) !== false ? 10 : 0 ;
90
90
});
91
91
$ this ->themeData = $ extensionDiscovery ->scan ('theme ' );
92
- $ this ->addTestNamespaces ();
92
+ $ this ->addCoreTestNamespaces ();
93
93
$ this ->addModuleNamespaces ();
94
94
$ this ->addThemeNamespaces ();
95
95
$ this ->registerPs4Namespaces ($ this ->namespaces );
96
96
$ this ->loadLegacyIncludes ();
97
97
98
- // @todo stop requiring the bootstrap.php and just copy what is needed.
99
- if (interface_exists (\PHPUnit \Framework \Test::class)) {
100
- require $ this ->drupalRoot . '/core/tests/bootstrap.php ' ;
101
- }
102
-
103
98
foreach ($ this ->moduleData as $ extension ) {
104
99
$ this ->loadExtension ($ extension );
105
100
@@ -196,6 +191,11 @@ class: Drupal\jsonapi\Routing\JsonApiParamEnhancer
196
191
197
192
$ service_map = $ container ->getByType (ServiceMap::class);
198
193
$ service_map ->setDrupalServices ($ this ->serviceMap );
194
+
195
+ if (interface_exists (\PHPUnit \Framework \Test::class)
196
+ && class_exists ('Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter ' )) {
197
+ \Drupal \TestTools \PhpUnitCompatibility \PhpUnit8 \ClassWriter::mutateTestBase ($ this ->autoloader );
198
+ }
199
199
}
200
200
201
201
protected function loadLegacyIncludes (): void
@@ -206,7 +206,7 @@ protected function loadLegacyIncludes(): void
206
206
}
207
207
}
208
208
209
- protected function addTestNamespaces (): void
209
+ protected function addCoreTestNamespaces (): void
210
210
{
211
211
// Add core test namespaces.
212
212
$ core_tests_dir = $ this ->drupalRoot . '/core/tests/Drupal ' ;
@@ -246,13 +246,38 @@ protected function addModuleNamespaces(): void
246
246
$ this ->serviceClassProviders [$ module_name ] = $ class ;
247
247
$ serviceId = "service_provider. $ module_name.service_provider " ;
248
248
$ this ->serviceMap [$ serviceId ] = ['class ' => $ class ];
249
+
250
+ $ this ->registerExtensionTestNamespace ($ module );
249
251
}
250
252
}
251
253
protected function addThemeNamespaces (): void
252
254
{
253
255
foreach ($ this ->themeData as $ theme_name => $ theme ) {
254
256
$ theme_dir = $ this ->drupalRoot . '/ ' . $ theme ->getPath ();
255
257
$ this ->namespaces ["Drupal \\$ theme_name " ] = $ theme_dir . '/src ' ;
258
+ $ this ->registerExtensionTestNamespace ($ theme );
259
+ }
260
+ }
261
+
262
+ protected function registerExtensionTestNamespace (Extension $ extension ): void
263
+ {
264
+ $ suite_names = ['Unit ' , 'Kernel ' , 'Functional ' , 'Build ' , 'FunctionalJavascript ' ];
265
+ $ dir = $ this ->drupalRoot . '/ ' . $ extension ->getPath ();
266
+ $ test_dir = $ dir . '/tests/src ' ;
267
+ if (is_dir ($ test_dir )) {
268
+ foreach ($ suite_names as $ suite_name ) {
269
+ $ suite_dir = $ test_dir . '/ ' . $ suite_name ;
270
+ if (is_dir ($ suite_dir )) {
271
+ // Register the PSR-4 directory for PHPUnit-based suites.
272
+ $ this ->namespaces ['Drupal \\Tests \\' . $ extension ->getName () . '\\' . $ suite_name . '\\' ][] = $ suite_dir ;
273
+ }
274
+ }
275
+ // Extensions can have a \Drupal\Tests\extension\Traits namespace for
276
+ // cross-suite trait code.
277
+ $ trait_dir = $ test_dir . '/Traits ' ;
278
+ if (is_dir ($ trait_dir )) {
279
+ $ this ->namespaces ['Drupal \\Tests \\' . $ extension ->getName () . '\\Traits \\' ][] = $ trait_dir ;
280
+ }
256
281
}
257
282
}
258
283
0 commit comments