Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore support for PSR-0-style test-classes (main/10.x) #5030

Merged
merged 3 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Runner/TestSuiteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,20 @@ 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;

break;
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/end-to-end/regression/5020.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-5020: Load PSR-0 tests
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/5020/Under/Score/Issue5020Test.php';

require_once __DIR__ . '/../../bootstrap.php';
PHPUnit\TextUI\Application::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

OK (1 test, 1 assertion)
16 changes: 16 additions & 0 deletions tests/end-to-end/regression/5020/Under/Score/Issue5020Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Under_Score_Issue5020Test extends PHPUnit\Framework\TestCase
{
public function testTrue(): void
{
$this->assertTrue(true);
}
}