Skip to content

Test suite running only partially since PHPUnit 9.1.3 (?) when PHPUnit called with file name to test suite setup file #4460

@jrfnl

Description

@jrfnl
Q A
PHPUnit version 9.1.3 - 9.3.10
PHP version 7.3 + 7.4
Installation Method Composer / PHAR - both

Summary

This is a bit of an awkward one to explain, so please bear with me. I will also include a solution which solved the issue for us.

With that in mind, feel free to close this issue if you deem this an acceptable BC-break, but I figured it would be helpful to document the issue anyway in case other people run into the same thing.

TL;DR: Calling PHPUnit with a file name pointing to a file which sets up a test suite, doesn't run the complete test suite anymore, but only part of it.

I suspect the issue is a regression related to issue #4232

Current behavior

Given the following config:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="tests/bootstrap.php">
    <testsuites>
        <testsuite name="PHP_CodeSniffer Test Suite">
            <file>tests/AllTests.php</file>
        </testsuite>
    </testsuites>
</phpunit>

Where the tests/AllTests.php file contains a TestSuite setup along the following lines:

namespace PHP_CodeSniffer\Tests;

class PHP_CodeSniffer_AllTests
{
    public static function suite()
    {
        $suite = new TestSuite('PHP CodeSniffer');
        $suite->addTest(Core\AllTests::suite());
        $suite->addTest(Standards\AllSniffs::suite());
        return $suite;
    }
}

And running PHPUnit with the following command:

phpunit ./tests/AllTests.php

Only 368 tests are run instead of the expected 567 tests.

Basically, the tests added via $suite->addTest(Core\AllTests::suite()); are run and those added via $suite->addTest(Standards\AllSniffs::suite()); are not, or rather are not even added.

(and please don't look at me for how the rest of the test suite is set up... not my code .. legacy project ... etc etc)

How to reproduce

  1. Clone the PHP_CodeSniffer repo - git clone [email protected]:squizlabs/PHP_CodeSniffer.git
  2. Switch to the 4.0 branch - git checkout 4.0
  3. Using PHPUnit 9.1.2, run phpunit tests/AllTests.php and see a test count at the bottom of 567 tests having run.
  4. Using a later PHPUnit release, run phpunit tests/AllTests.php and see a test count of 368 tests having run.

The solution I found to fix this was to run the tests without the filename, so just running them with a plain phpunit call.

So:
5. Run the following on any PHPUnit version to see the correct number of 567 tests being run: phpunit (without the tests/AllTests.php)

The fact the file name was still part of the default command is a project legacy from a time it was necessary, just don't ask me when that was 😉

Expected behavior

The test count to be the same cross-version.

External references:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions