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

PHPUnit 10 | Remove support for expecting PHP notices/exceptions #108

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,32 +233,6 @@ These methods were introduced in PHPUnit 7.5.0 as alternatives to using `Assert:
[`Assert::assertEqualsWithDelta()`]: https://docs.phpunit.de/en/9.6/assertions.html#assertequalswithdelta
[`Assert::assertNotEqualsWithDelta()`]: https://docs.phpunit.de/en/9.6/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 (will be) removed in PHPUnit 10.0.0.

[`expectError()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectErrorMessage()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectErrorMessageMatches()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectWarning()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectWarningMessage()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectWarningMessageMatches()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectNotice()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectNoticeMessage()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectNoticeMessageMatches()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectDeprecation()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectDeprecationMessage()`]: https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices
[`expectDeprecationMessageMatches()`]: https://docs.phpunit.de/en/9.6/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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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