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 committed Jul 26, 2022
1 parent 943adbe commit a6b188e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Runner/TestSuiteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,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 a6b188e

Please sign in to comment.