diff --git a/core/tests/TestSuites/TestSuiteBase.php b/core/tests/TestSuites/TestSuiteBase.php index e5925debb9..41ed61622b 100644 --- a/core/tests/TestSuites/TestSuiteBase.php +++ b/core/tests/TestSuites/TestSuiteBase.php @@ -42,10 +42,11 @@ protected function addTestsBySuiteNamespace($root, $suite_namespace) { // to this is Unit tests for historical reasons. if ($suite_namespace == 'Unit') { $tests = TestDiscovery::scanDirectory("Drupal\\Tests\\", "$root/core/tests/Drupal/Tests"); - $tests = array_filter($tests, function ($test) use ($root) { - // The Listeners directory does not contain tests. - return !preg_match("@^$root/core/tests/Drupal/Tests/Listeners(/|$)@", dirname($test)); - }); + $tests = array_flip(array_filter(array_flip($tests), function ($test_class) { + // The Listeners directory does not contain tests. Use the class name + // to be compatible with all operating systems. + return !preg_match('/^Drupal\\\\Tests\\\\Listeners\\\\/', $test_class); + })); $this->addTestFiles($tests); } else {