diff --git a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php index 2924074..64dddb5 100644 --- a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php +++ b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php @@ -66,13 +66,15 @@ protected function findPhpClasses($dir) { * The full path to the class that should be checked. */ protected function assertNoCoreUsage($class_path) { - foreach (new \SplFileObject($class_path) as $line_number => $line) { - // Allow linking to Core files with @see docs. Its harmless and boosts DX - // because even outside projects can treat those links as examples. - if ($line && (strpos($line, '@see ') === FALSE)) { - $this->assertSame(FALSE, strpos($line, 'Drupal\\Core'), "Illegal reference to 'Drupal\\Core' namespace in $class_path at line $line_number"); + $contents = file_get_contents($class_path); + if (preg_match_all('/^.*Drupal\\\Core.*$/m', $contents, $matches)) { + foreach ($matches[0] as $line) { + if ((strpos($line, '@see ') === FALSE)) { + $this->fail( + "Illegal reference to 'Drupal\\Core' namespace in $class_path" + ); + } } } } - }