Skip to content

Commit

Permalink
Add more comments about namespace detection (10.x variant)
Browse files Browse the repository at this point in the history
  • Loading branch information
totten authored and sebastianbergmann committed Aug 13, 2022
1 parent 7b686fe commit e2ad67d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Runner/TestSuiteLoader.php
Expand Up @@ -71,15 +71,17 @@ public function load(string $suiteClassFile): ReflectionClass
}

if (!class_exists($suiteClassName, false)) {
// this block will handle namespaced classes
// Perhaps this file defines a class inside a namespace? Let's check...
$offset = 0 - strlen($suiteClassName);

foreach (self::$loadedClasses as $loadedClass) {
// Detect modern namespace (eg './tests/Foo/Bar/WhizBangTest.php' <=> 'Foo\Bar\WhizBangTest')
if (stripos(substr($loadedClass, $offset - 1), '\\' . $suiteClassName) === 0) {
$suiteClassName = $loadedClass;

break;
}
// Detect old-school namespace (eg 'tests/Foo/Bar/WhizBangTest.php' <=> 'Foo_Bar_WhizBangTest'; #5020)
if (stripos(substr($loadedClass, $offset - 1), '_' . $suiteClassName) === 0) {
$suiteClassName = $loadedClass;

Expand Down

0 comments on commit e2ad67d

Please sign in to comment.