Skip to content

Commit

Permalink
Closes #5062
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 14, 2023
1 parent e1ab7d5 commit 3812fd7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 84 deletions.
1 change: 1 addition & 0 deletions ChangeLog-9.6.md
Expand Up @@ -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

Expand Down
68 changes: 64 additions & 4 deletions src/Framework/TestCase.php
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
19 changes: 0 additions & 19 deletions tests/end-to-end/regression/4663.phpt

This file was deleted.

20 changes: 0 additions & 20 deletions tests/end-to-end/regression/4663/Issue4663Test.php

This file was deleted.

41 changes: 0 additions & 41 deletions tests/unit/Framework/TestCaseTest.php
Expand Up @@ -9,18 +9,13 @@
*/
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;
use function getcwd;
use function ini_get;
use function ini_set;
use function sprintf;
use function trigger_error;
use DependencyInputTest;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 3812fd7

Please sign in to comment.