diff --git a/ChangeLog-9.6.md b/ChangeLog-9.6.md index f8c71a0e21a..1dfb1d129cd 100644 --- a/ChangeLog-9.6.md +++ b/ChangeLog-9.6.md @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 9.6 release series are documented in this fil ### Changed +* [#5062](https://github.com/sebastianbergmann/phpunit/issues/5062): Deprecate `expectDeprecation()`, `expectDeprecationMessage()`, `expectDeprecationMessageMatches()`, `expectError()`, `expectErrorMessage()`, `expectErrorMessageMatches()`, `expectNotice()`, `expectNoticeMessage()`, `expectNoticeMessageMatches()`, `expectWarning()`, `expectWarningMessage()`, and `expectWarningMessageMatches()` * [#5064](https://github.com/sebastianbergmann/phpunit/issues/5064): Deprecate `PHPUnit\Framework\TestCase::getMockClass()` * [#5132](https://github.com/sebastianbergmann/phpunit/issues/5132): Deprecate `Test` suffix for abstract test case classes diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index cd242609cfd..2d83fe0182d 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -599,22 +599,22 @@ public function expectException(string $exception): void // @codeCoverageIgnoreStart switch ($exception) { case Deprecated::class: - $this->addWarning('Support for using expectException() with PHPUnit\Framework\Error\Deprecated is deprecated and will be removed in PHPUnit 10. Use expectDeprecation() instead.'); + $this->addWarning('Expecting E_DEPRECATED and E_USER_DEPRECATED is deprecated and will no longer be possible in PHPUnit 10.'); break; case Error::class: - $this->addWarning('Support for using expectException() with PHPUnit\Framework\Error\Error is deprecated and will be removed in PHPUnit 10. Use expectError() instead.'); + $this->addWarning('Expecting E_ERROR and E_USER_ERROR is deprecated and will no longer be possible in PHPUnit 10.'); break; case Notice::class: - $this->addWarning('Support for using expectException() with PHPUnit\Framework\Error\Notice is deprecated and will be removed in PHPUnit 10. Use expectNotice() instead.'); + $this->addWarning('Expecting E_STRICT, E_NOTICE, and E_USER_NOTICE is deprecated and will no longer be possible in PHPUnit 10.'); break; case WarningError::class: - $this->addWarning('Support for using expectException() with PHPUnit\Framework\Error\Warning is deprecated and will be removed in PHPUnit 10. Use expectWarning() instead.'); + $this->addWarning('Expecting E_WARNING and E_USER_WARNING is deprecated and will no longer be possible in PHPUnit 10.'); break; } @@ -658,63 +658,123 @@ public function expectNotToPerformAssertions(): void $this->doesNotPerformAssertions = true; } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectDeprecation(): void { + $this->addWarning('Expecting E_DEPRECATED and E_USER_DEPRECATED is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectedException = Deprecated::class; } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectDeprecationMessage(string $message): void { + $this->addWarning('Expecting E_DEPRECATED and E_USER_DEPRECATED is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessage($message); } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectDeprecationMessageMatches(string $regularExpression): void { + $this->addWarning('Expecting E_DEPRECATED and E_USER_DEPRECATED is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessageMatches($regularExpression); } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectNotice(): void { + $this->addWarning('Expecting E_STRICT, E_NOTICE, and E_USER_NOTICE is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectedException = Notice::class; } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectNoticeMessage(string $message): void { + $this->addWarning('Expecting E_STRICT, E_NOTICE, and E_USER_NOTICE is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessage($message); } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectNoticeMessageMatches(string $regularExpression): void { + $this->addWarning('Expecting E_STRICT, E_NOTICE, and E_USER_NOTICE is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessageMatches($regularExpression); } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectWarning(): void { + $this->addWarning('Expecting E_WARNING and E_USER_WARNING is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectedException = WarningError::class; } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectWarningMessage(string $message): void { + $this->addWarning('Expecting E_WARNING and E_USER_WARNING is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessage($message); } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectWarningMessageMatches(string $regularExpression): void { + $this->addWarning('Expecting E_WARNING and E_USER_WARNING is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessageMatches($regularExpression); } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectError(): void { + $this->addWarning('Expecting E_ERROR and E_USER_ERROR is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectedException = Error::class; } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectErrorMessage(string $message): void { + $this->addWarning('Expecting E_ERROR and E_USER_ERROR is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessage($message); } + /** + * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5062 + */ public function expectErrorMessageMatches(string $regularExpression): void { + $this->addWarning('Expecting E_ERROR and E_USER_ERROR is deprecated and will no longer be possible in PHPUnit 10.'); + $this->expectExceptionMessageMatches($regularExpression); } diff --git a/tests/end-to-end/regression/4663.phpt b/tests/end-to-end/regression/4663.phpt deleted file mode 100644 index c3cf6ae5ce7..00000000000 --- a/tests/end-to-end/regression/4663.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -https://github.com/sebastianbergmann/phpunit/issues/4663 ---FILE-- - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -use PHPUnit\Framework\TestCase; - -final class Issue4663Test extends TestCase -{ - public function testTestThatExpectsAnErrorPassesWhenTheErrorOccurs(): void - { - $this->expectError(); - - \implode('', [new stdClass]); - } -} diff --git a/tests/unit/Framework/TestCaseTest.php b/tests/unit/Framework/TestCaseTest.php index 9d2169f7813..0baed217be0 100644 --- a/tests/unit/Framework/TestCaseTest.php +++ b/tests/unit/Framework/TestCaseTest.php @@ -9,10 +9,6 @@ */ namespace PHPUnit\Framework; -use const E_USER_DEPRECATED; -use const E_USER_ERROR; -use const E_USER_NOTICE; -use const E_USER_WARNING; use const PHP_EOL; use function array_map; use function get_class; @@ -20,7 +16,6 @@ use function ini_get; use function ini_set; use function sprintf; -use function trigger_error; use DependencyInputTest; use InvalidArgumentException; use PHPUnit\Framework\MockObject\MockObject; @@ -1267,42 +1262,6 @@ public function testHasOutputReturnsTrueWhenTestGeneratesOutput(): void $this->assertTrue($test->hasOutput()); } - public function testDeprecationCanBeExpected(): void - { - $this->expectDeprecation(); - $this->expectDeprecationMessage('foo'); - $this->expectDeprecationMessageMatches('/foo/'); - - trigger_error('foo', E_USER_DEPRECATED); - } - - public function testNoticeCanBeExpected(): void - { - $this->expectNotice(); - $this->expectNoticeMessage('foo'); - $this->expectNoticeMessageMatches('/foo/'); - - trigger_error('foo', E_USER_NOTICE); - } - - public function testWarningCanBeExpected(): void - { - $this->expectWarning(); - $this->expectWarningMessage('foo'); - $this->expectWarningMessageMatches('/foo/'); - - trigger_error('foo', E_USER_WARNING); - } - - public function testErrorCanBeExpected(): void - { - $this->expectError(); - $this->expectErrorMessage('foo'); - $this->expectErrorMessageMatches('/foo/'); - - trigger_error('foo', E_USER_ERROR); - } - public function testSetDependencyInput(): void { $test = new DependencyInputTest('testDependencyInputAsParameter');