Skip to content

Commit

Permalink
Closes #3775
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 3, 2019
1 parent 4991d62 commit 1ba2e3e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog-8.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ All notable changes of the PHPUnit 8.4 release series are documented in this fil

## [8.4.0] - 2019-10-04

### Added

* Implemented [#3775](https://github.com/sebastianbergmann/phpunit/issues/3775): Explicit API for expecting PHP errors, warnings, and notices

[8.4.0]: https://github.com/sebastianbergmann/phpunit/compare/8.3...8.4.0

64 changes: 64 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
use PHPUnit\Framework\Constraint\ExceptionCode;
use PHPUnit\Framework\Constraint\ExceptionMessage;
use PHPUnit\Framework\Constraint\ExceptionMessageRegularExpression;
use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\Error\Warning as WarningError;
use PHPUnit\Framework\MockObject\Generator as MockGenerator;
use PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount as AnyInvokedCountMatcher;
use PHPUnit\Framework\MockObject\Matcher\InvokedAtIndex as InvokedAtIndexMatcher;
Expand Down Expand Up @@ -511,6 +515,66 @@ public function expectNotToPerformAssertions(): void
$this->doesNotPerformAssertions = true;
}

public function expectDeprecation(): void
{
$this->expectException(Deprecated::class);
}

public function expectDeprecationMessage(string $message): void
{
$this->expectExceptionMessage($message);
}

public function expectDeprecationMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
}

public function expectNotice(): void
{
$this->expectException(Notice::class);
}

public function expectNoticeMessage(string $message): void
{
$this->expectExceptionMessage($message);
}

public function expectNoticeMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
}

public function expectWarning(): void
{
$this->expectException(WarningError::class);
}

public function expectWarningMessage(string $message): void
{
$this->expectExceptionMessage($message);
}

public function expectWarningMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
}

public function expectError(): void
{
$this->expectException(Error::class);
}

public function expectErrorMessage(string $message): void
{
$this->expectExceptionMessage($message);
}

public function expectErrorMessageMatches(string $regularExpression): void
{
$this->expectExceptionMessageRegExp($regularExpression);
}

public function getStatus(): int
{
return $this->status;
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/Framework/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,42 @@ 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);
}

/**
* @return array<string, array>
*/
Expand Down

0 comments on commit 1ba2e3e

Please sign in to comment.