Skip to content

Test suite loader produces warning and does not run any tests if the test class name is partially similar to the parent test case name #4232

@mbessolov

Description

@mbessolov
Q A
PHPUnit version 9.1.4
PHP version 7.3
Installation Method Both Composer and PHAR

Summary

When the current test class (e.g. FooTest) extends the parent class with a partially matching name (ending with FooTest, for example ParentFooTest, AbstractFooTest or similar), the testsuite loader does not run any tests and produces a warning:

<?php
class FooTest extends ParentFooTest
{
    public function testSomething()
    {
        static::assertTrue(true);
    }
}
$ vendor/bin/phpunit tests/FooTest.php
PHPUnit 9.1.4 by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 00:00.026, Memory: 6.00 MB

There was 1 warning:

1) Warning
No tests found in class "App\Tests\ParentFooTest".

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.

Current behavior

$offset = 0 - \strlen($suiteClassName);
foreach ($loadedClasses as $loadedClass) {
if (\substr($loadedClass, $offset) === $suiteClassName) {
$suiteClassName = $loadedClass;
- the purpose of this is not clear to me, so I cannot comment on whether it does what it is supposed to do or not, but it produces the bug I described.

How to reproduce

Here is the reproducer - https://github.com/mbessolov/phpunit-loader-bug

Expected behavior

It should not matter if there is any partial similary between the names of the current test class and any of its parents.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions