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

Use PHPUnit Extension system instead of Listener #83

Merged
merged 18 commits into from
Oct 17, 2022
Merged

Conversation

johnkary
Copy link
Owner

@johnkary johnkary commented Mar 14, 2021

PHPUnit 8 introduced the Hooks Extension system which deprecated the Listener system.

This PR completes the work started by @vlaurier in #67 to implement the Hooks Extension system, and will close issue #60.

New minimum version constraints

PHPUnit 8.0+
PHP 7.2+ (required by PHPUnit 8)

New namespace and method signatures

The SpeedTrap class has moved:

Old: JohnKary\PHPUnit\Listener\SpeedTrapListener
New: JohnKary\PHPUnit\Extension\SpeedTrap

Various method signature within the SpeedTrap class have also been changed. Updates are required if you have extended SpeedTrap for other uses.

New way to register SpeedTrap with phpunit.xml

PHPUnit extensions are registered slightly differently in phpunit.xml:

<phpunit bootstrap="vendor/autoload.php">
...
    <extensions>
        <extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
    </extensions>
</phpunit>

Remove option stopOnSlow

Prior to this PR SpeedTrap supported an option stopOnSlow to prematurely stop the test runner after encountering a slow test.

The PHPUnit Extension system does not allow Extensions to alter the test runner. The test runner cannot be stopped without killing the current PHP process. So the stopOnSlow feature had to be removed.

TODO

  • Document upgrade path in UPGRADE.md

vincentlaurier and others added 14 commits February 14, 2020 11:15
Class PHPUnit\Framework\TestCase implements interface PHPUnit\Framework\SelfDescribing
which allows the test to return a string describing itself, including its data.
However, including the data in the test output renders it incompatible with
PHPUnit's --filter CLI flag.

When upgrading to PHPUnit's Hook system, SpeedTrap methods had to switch from accepting
object TestClass to string $test. The new $test variable reports the class name with an
argument list enclosed in parens:

    JohnKary\PHPUnit\Listener\Tests\SomeSlowTest::testWithDataProvider with data set "Rock" (800)

This format is not currently compatible with PHPUnit's --filter argument:

    # Does not run intended test case with dataProvider "Rock"
    vendor/bin/phpunit --filter='JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock" (800)'

This commit assumes the vast majority of test suites will use PHPUnit's default TestCase class,
thus their test will report with the data enclosed in parens. We will filter out the ` (800)`
part from all test outputs and allows SpeedTrap to continue outputting a test format compatible with --filter:

    You should really speed up these slow tests (>500ms)...
     1. 802ms to run JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"

    vendor/bin/phpunit --filter='JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"'
PHPUnit Extensions and Hooks no longer allow manipulating the Test Runner
because they no longer have access to the TestCase class. Extensions are
instead only given the string of the current test class, method and data.

Without access to the Test Runner an Extension cannot stop further tests
from running in a responsible way without terminating the PHP process.
PHPUnit 8.0.0 requires this as a minimum PHP version, so we must match it.
@fchastanet
Copy link

Hello, what is the status of this PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants