Skip to content

Commit

Permalink
PHPUnit 10 | Remove support for expecting PHP notices/exceptions
Browse files Browse the repository at this point in the history
Remove the `ExpectPHPException` polyfill and all references to it as support for expecting PHP native and user added deprecations, notices, warnings and errors has been dropped in PHPUnit 10.0.

PHP native Exceptions can still be tested using the `expectException()` method with the name of the PHP native Exception.

Refs:
* https://phpunit.de/announcements/phpunit-10.html
* https://github.com/sebastianbergmann/phpunit/blob/main/ChangeLog-10.0.md#1000---2023-02-03
* sebastianbergmann/phpunit#3775
* sebastianbergmann/phpunit#5062
* sebastianbergmann/phpunit@a2c784c
  • Loading branch information
jrfnl committed Mar 29, 2023
1 parent 3072338 commit c56081a
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 322 deletions.
26 changes: 0 additions & 26 deletions README.md
Expand Up @@ -232,32 +232,6 @@ These methods were introduced in PHPUnit 7.5.0 as alternatives to using `Assert:
[`Assert::assertEqualsWithDelta()`]: https://docs.phpunit.de/en/main/assertions.html#assertequalswithdelta
[`Assert::assertNotEqualsWithDelta()`]: https://docs.phpunit.de/en/main/assertions.html#assertequalswithdelta

#### PHPUnit < 8.4.0: `Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException`

Polyfills the following methods:
| | | |
|-------------------------------------|--------------------------------|---------------------------------------|
| `TestCase::`[`expectError()`] | [`expectErrorMessage()`] | [`expectErrorMessageMatches()`] |
| `TestCase::`[`expectWarning()`] | [`expectWarningMessage()`] | [`expectWarningMessageMatches()`] |
| `TestCase::`[`expectNotice()`] | [`expectNoticeMessage()`] | [`expectNoticeMessageMatches()`] |
| `TestCase::`[`expectDeprecation()`] | [`expectDeprecationMessage()`] | [`expectDeprecationMessageMatches()`] |

These methods were introduced in PHPUnit 8.4.0 as alternatives to using `TestCase::expectException()` et al for expecting PHP native errors, warnings and notices.
Using `TestCase::expectException*()` for testing PHP native notices was soft deprecated in PHPUnit 8.4.0, hard deprecated (warning) in PHPUnit 9.0.0 and removed in PHPUnit 10.0.0.

[`expectError()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectErrorMessage()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectErrorMessageMatches()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectWarning()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectWarningMessage()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectWarningMessageMatches()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectNotice()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectNoticeMessage()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectNoticeMessageMatches()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectDeprecation()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectDeprecationMessage()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectDeprecationMessageMatches()`]: https://docs.phpunit.de/en/main/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices

#### PHPUnit < 8.4.0: `Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches`

Polyfills the [`TestCase::expectExceptionMessageMatches()`] method.
Expand Down
55 changes: 0 additions & 55 deletions phpunitpolyfills-autoload.php
Expand Up @@ -67,10 +67,6 @@ public static function load( $className ) {
self::loadAssertEqualsSpecializations();
return true;

case 'Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException':
self::loadExpectPHPException();
return true;

case 'Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches':
self::loadExpectExceptionMessageMatches();
return true;
Expand Down Expand Up @@ -191,57 +187,6 @@ public static function loadAssertEqualsSpecializations() {
require_once __DIR__ . '/src/Polyfills/AssertEqualsSpecializations_Empty.php';
}

/**
* Load the ExpectPHPException polyfill or an empty trait with the same name
* if a PHPUnit version is used which already contains this functionality.
*
* Includes aliasing any PHPUnit native classes needed for this functionality
* which aren't available under their namespaced name in PHPUnit 5.x.
*
* @return void
*/
public static function loadExpectPHPException() {
/*
* Alias the PHPUnit 5.x Error classes to their PHPUnit >= 6 name.
*
* {@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_Error' ) === true
&& \class_exists( 'PHPUnit\Framework\Error\Error' ) === false
) {
\class_alias( 'PHPUnit_Framework_Error', 'PHPUnit\Framework\Error\Error' );
}

if ( \class_exists( 'PHPUnit_Framework_Error_Warning' ) === true
&& \class_exists( 'PHPUnit\Framework\Error\Warning' ) === false
) {
\class_alias( 'PHPUnit_Framework_Error_Warning', 'PHPUnit\Framework\Error\Warning' );
}

if ( \class_exists( 'PHPUnit_Framework_Error_Notice' ) === true
&& \class_exists( 'PHPUnit\Framework\Error\Notice' ) === false
) {
\class_alias( 'PHPUnit_Framework_Error_Notice', 'PHPUnit\Framework\Error\Notice' );
}

if ( \class_exists( 'PHPUnit_Framework_Error_Deprecated' ) === true
&& \class_exists( 'PHPUnit\Framework\Error\Deprecated' ) === false
) {
\class_alias( 'PHPUnit_Framework_Error_Deprecated', 'PHPUnit\Framework\Error\Deprecated' );
}

if ( \method_exists( TestCase::class, 'expectErrorMessage' ) === false ) {
// PHPUnit < 8.4.0.
require_once __DIR__ . '/src/Polyfills/ExpectPHPException.php';
return;
}

// PHPUnit >= 8.4.0.
require_once __DIR__ . '/src/Polyfills/ExpectPHPException_Empty.php';
}

/**
* Load the ExpectExceptionMessageMatches polyfill or an empty trait with the same name
* if a PHPUnit version is used which already contains this functionality.
Expand Down
148 changes: 0 additions & 148 deletions src/Polyfills/ExpectPHPException.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Polyfills/ExpectPHPException_Empty.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/TestCases/TestCasePHPUnitGte8.php
Expand Up @@ -10,7 +10,6 @@
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals;
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;

/**
* Basic test case for use with PHPUnit >= 8.
Expand All @@ -30,7 +29,6 @@ abstract class TestCase extends PHPUnit_TestCase {
use AssertObjectEquals;
use EqualToSpecializations;
use ExpectExceptionMessageMatches;
use ExpectPHPException;

/**
* This method is called before the first test of this test class is run.
Expand Down
2 changes: 0 additions & 2 deletions src/TestCases/TestCasePHPUnitLte7.php
Expand Up @@ -14,7 +14,6 @@
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;

/**
* Basic test case for use with PHPUnit <= 7.
Expand All @@ -38,7 +37,6 @@ abstract class TestCase extends PHPUnit_TestCase {
use EqualToSpecializations;
use ExpectExceptionMessageMatches;
use ExpectExceptionObject;
use ExpectPHPException;

/**
* This method is called before the first test of this test class is run.
Expand Down
2 changes: 0 additions & 2 deletions src/TestCases/XTestCase.php
Expand Up @@ -14,7 +14,6 @@
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;

/**
* Basic test case for use with PHPUnit cross-version.
Expand All @@ -40,7 +39,6 @@ abstract class XTestCase extends PHPUnit_TestCase {
use EqualToSpecializations;
use ExpectExceptionMessageMatches;
use ExpectExceptionObject;
use ExpectPHPException;

/**
* This method is called before the first test of this test class is run.
Expand Down
68 changes: 0 additions & 68 deletions tests/Polyfills/ExpectPHPExceptionTest.php

This file was deleted.

11 changes: 0 additions & 11 deletions tests/TestCases/TestCaseTestTrait.php
Expand Up @@ -65,17 +65,6 @@ final public function testAvailabilityAssertEqualsSpecializationsTrait() {
static::assertEqualsIgnoringCase( 'a', 'A' );
}

/**
* Test availability of trait polyfilled PHPUnit methods [5].
*
* @return void
*/
final public function testAvailabilityExpectPHPExceptionTrait() {
$this->expectDeprecation();

\trigger_error( 'foo', \E_USER_DEPRECATED );
}

/**
* Test availability of trait polyfilled PHPUnit methods [6].
*
Expand Down

0 comments on commit c56081a

Please sign in to comment.