Skip to content

Commit

Permalink
Drop support for PHPUnit < 6.4 [2]
Browse files Browse the repository at this point in the history
Even though the TestListener implementation is not (yet) compatible with PHPUnit 10 (nor 11), we should still drop support for PHPUnit < 6.4 from the existing implementation.
  • Loading branch information
jrfnl committed Jul 17, 2024
1 parent c2caca1 commit 335fbaa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 204 deletions.
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class MyTest extends XTestCase {
>
> If you need the TestListener polyfill, it is recommended to stay on the PHPUnit Polyfills 1.x series for the time being and to watch and upvote the [related ticket][polyfill-ticket].
>
> The below documentation is for the PHPUnit 5.x-9.x TestListener polyfill implementation.
> The below documentation is for the PHPUnit 6.x-9.x TestListener polyfill implementation.
[polyfill-ticket]: https://github.com/Yoast/PHPUnit-Polyfills/issues/128

Expand All @@ -598,24 +598,21 @@ This `TestListenerDefaultImplementation` trait overcomes the signature mismatche

Similar to the `TestCase` implementation, snake_case methods without type declarations are used to get round the signature mismatches. The snake_case methods will automatically be called.

| PHPUnit native method name | Replacement | Notes |
| -------------------------- | --------------------------------------- | ----------------------------------------- |
| `addError()` | `add_error($test, $e, $time)` | |
| `addWarning()` | `add_warning($test, $e, $time)` | Introduced in PHPUnit 6. |
| `addFailure()` | `add_failure($test, $e, $time)` | |
| `addIncompleteTest()` | `add_incomplete_test($test, $e, $time)` | |
| `addRiskyTest()` | `add_risky_test($test, $e, $time)` | Support appears to be flaky on PHPUnit 5. |
| `addSkippedTest()` | `add_skipped_test($test, $e, $time)` | |
| `startTestSuite()` | `start_test_suite($suite)` | |
| `endTestSuite()` | `end_test_suite($suite)` | |
| `startTest()` | `start_test($test)` | |
| `endTest()` | `end_test($test, $time)` | |
| PHPUnit native method name | Replacement |
| -------------------------- | --------------------------------------- |
| `addError()` | `add_error($test, $e, $time)` |
| `addWarning()` | `add_warning($test, $e, $time)` |
| `addFailure()` | `add_failure($test, $e, $time)` |
| `addIncompleteTest()` | `add_incomplete_test($test, $e, $time)` |
| `addRiskyTest()` | `add_risky_test($test, $e, $time)` |
| `addSkippedTest()` | `add_skipped_test($test, $e, $time)` |
| `startTestSuite()` | `start_test_suite($suite)` |
| `endTestSuite()` | `end_test_suite($suite)` |
| `startTest()` | `start_test($test)` |
| `endTest()` | `end_test($test, $time)` |

Implementations of the `TestListener` interface may be using any of the following patterns:
```php
// PHPUnit < 6.
class MyTestListener extends \PHPUnit_Framework_BaseTestListener {}

// PHPUnit 6.
class MyTestListener extends \PHPUnit\Framework\BaseTestListener {}

Expand Down
23 changes: 1 addition & 22 deletions phpunitpolyfills-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,29 +337,8 @@ public static function loadTestCase() {
* @return void
*/
public static function loadTestListenerDefaultImplementation() {
if ( \version_compare( self::getPHPUnitVersion(), '6.0.0', '<' ) ) {
/*
* Alias one particular PHPUnit 5.x class to its PHPUnit >= 6 name.
*
* All other classes needed are part of the forward-compatibility layer.
*
* {@internal The `class_exists` wrappers are needed to play nice with
* PHPUnit bootstrap files of test suites implementing this library
* which may be creating cross-version compatibility in a similar manner.}}
*/
if ( \class_exists( 'PHPUnit_Framework_Warning' ) === true
&& \class_exists( 'PHPUnit\Framework\Warning' ) === false
) {
\class_alias( 'PHPUnit_Framework_Warning', 'PHPUnit\Framework\Warning' );
}

// PHPUnit < 6.0.0.
require_once __DIR__ . '/src/TestListeners/TestListenerDefaultImplementationPHPUnitLte5.php';
return;
}

if ( \version_compare( PHPUnit_Version::id(), '7.0.0', '<' ) ) {
// PHPUnit 6.0.0 < 7.0.0.
// PHPUnit 6.4.0 < 7.0.0.
require_once __DIR__ . '/src/TestListeners/TestListenerDefaultImplementationPHPUnit6.php';
return;
}
Expand Down
155 changes: 0 additions & 155 deletions src/TestListeners/TestListenerDefaultImplementationPHPUnitLte5.php

This file was deleted.

11 changes: 0 additions & 11 deletions tests/TestListeners/TestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,8 @@ public function testError() {
/**
* Test that the TestListener add_warning() method is called.
*
* Note: Prior to PHPUnit 6, PHPUnit did not have `addWarning()` support.
* Interestingly enough, it does seem to work on PHPUnit 5, just don't ask me how.
*
* @requires PHPUnit 5
*
* @return void
*/
#[RequiresPhpunit( '5' )]
public function testWarning() {
$test = $this->getTestObject( 'Warning' );
$test->run( $this->result );
Expand Down Expand Up @@ -116,13 +110,8 @@ public function testIncomplete() {
/**
* Test that the TestListener add_risky_test() method is called.
*
* Note: It appears that the PHPUnit native recording of risky tests prior to PHPUnit 6 is buggy.
*
* @requires PHPUnit 6
*
* @return void
*/
#[RequiresPhpunit( '6' )]
public function testRisky() {
$test = $this->getTestObject( 'Risky' );
$test->run( $this->result );
Expand Down

0 comments on commit 335fbaa

Please sign in to comment.