Skip to content

Commit

Permalink
Remove expectDeprecation*(), expectError*(), expectNotice*(), and exp…
Browse files Browse the repository at this point in the history
…ectWarning*()
  • Loading branch information
sebastianbergmann committed Sep 8, 2022
1 parent 687b6ab commit a2c784c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 515 deletions.
24 changes: 1 addition & 23 deletions .psalm/baseline.xml
Expand Up @@ -328,19 +328,7 @@
<InvalidReturnType occurrences="1">
<code>MockObject&amp;RealInstanceType</code>
</InvalidReturnType>
<MissingThrowsDocblock occurrences="29">
<code>Facade::ignoredEvent()</code>
<code>Facade::ignoredEvent()</code>
<code>Facade::ignoredEvent()</code>
<code>Facade::ignoredEvent()</code>
<code>assertThat</code>
<code>assertThat</code>
<code>assertThat</code>
<code>assertThat</code>
<code>assertThat</code>
<code>assertThat</code>
<code>assertThat</code>
<code>assertThat</code>
<MissingThrowsDocblock occurrences="13">
<code>assertThat</code>
<code>assertThat</code>
<code>assertThat</code>
Expand All @@ -354,17 +342,7 @@
<code>getMockForTrait</code>
<code>getObjectForTrait</code>
<code>onlyMethods</code>
<code>throw new AssertionFailedError('Failed asserting that a deprecation is triggered');</code>
<code>throw new AssertionFailedError('Failed asserting that a notice is triggered');</code>
<code>throw new AssertionFailedError('Failed asserting that a warning is triggered');</code>
<code>throw new AssertionFailedError('Failed asserting that an error is triggered');</code>
</MissingThrowsDocblock>
<PossiblyNullArgument occurrences="4">
<code>$this-&gt;expectedDeprecationMessage</code>
<code>$this-&gt;expectedErrorMessage</code>
<code>$this-&gt;expectedNoticeMessage</code>
<code>$this-&gt;expectedWarningMessage</code>
</PossiblyNullArgument>
<PropertyNotSetInConstructor occurrences="1">
<code>$outputBufferingLevel</code>
</PropertyNotSetInConstructor>
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog-10.0.md
Expand Up @@ -77,6 +77,10 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
* [#4564](https://github.com/sebastianbergmann/phpunit/issues/4564): Remove `withConsecutive()`
* [#4567](https://github.com/sebastianbergmann/phpunit/issues/4567): Remove support for generators in `assertCount()` and `Count` constraint
* [#4601](https://github.com/sebastianbergmann/phpunit/issues/4601): Remove assertions that operate on class/object properties
* Removed the `expectDeprecation()`, `expectDeprecationMessage()`, and `expectDeprecationMessageMatches()` methods
* Removed the `expectError()`, `expectErrorMessage()`, and `expectErrorMessageMatches()` methods
* Removed the `expectNotice()`, `expectNoticeMessage()`, and `expectNoticeMessageMatches()` methods
* Removed the `expectWarning()`, `expectWarningMessage()`, and `expectWarningMessageMatches()` methods
* Removed the `PHPUnit\Runner\TestSuiteLoader` interface
* Removed the `<listeners>` XML configuration element and its children
* Removed the `groups` attribute on the `<test>` element in the TestDox XML report
Expand Down
284 changes: 9 additions & 275 deletions src/Framework/TestCase.php
Expand Up @@ -58,13 +58,6 @@
use AssertionError;
use DeepCopy\DeepCopy;
use PHPUnit\Event;
use PHPUnit\Event\Test\DeprecationTriggered;
use PHPUnit\Event\Test\ErrorTriggered;
use PHPUnit\Event\Test\NoticeTriggered;
use PHPUnit\Event\Test\PhpDeprecationTriggered;
use PHPUnit\Event\Test\PhpNoticeTriggered;
use PHPUnit\Event\Test\PhpWarningTriggered;
use PHPUnit\Event\Test\WarningTriggered;
use PHPUnit\Framework\Constraint\Exception as ExceptionConstraint;
use PHPUnit\Framework\Constraint\ExceptionCode;
use PHPUnit\Framework\Constraint\MessageIsOrContains;
Expand Down Expand Up @@ -183,21 +176,9 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
/**
* @psalm-var list<Comparator>
*/
private array $customComparators = [];
private ?Event\Code\TestMethod $testValueObjectForEvents = null;
private bool $wasPrepared = false;
private bool $deprecationExpected = false;
private ?string $expectedDeprecationMessage = null;
private ?string $expectedDeprecationMessageRegularExpression = null;
private bool $errorExpected = false;
private ?string $expectedErrorMessage = null;
private ?string $expectedErrorMessageRegularExpression = null;
private bool $noticeExpected = false;
private ?string $expectedNoticeMessage = null;
private ?string $expectedNoticeMessageRegularExpression = null;
private bool $warningExpected = false;
private ?string $expectedWarningMessage = null;
private ?string $expectedWarningMessageRegularExpression = null;
private array $customComparators = [];
private ?Event\Code\TestMethod $testValueObjectForEvents = null;
private bool $wasPrepared = false;

/**
* Returns a matcher that matches when the method is executed
Expand Down Expand Up @@ -435,98 +416,6 @@ final public function expectNotToPerformAssertions(): void
$this->doesNotPerformAssertions = true;
}

final public function expectDeprecation(): void
{
Facade::ignoreTestTriggeredDeprecationEventForExpectation();

$this->deprecationExpected = true;
}

final public function expectDeprecationMessage(string $message): void
{
Facade::ignoreTestTriggeredDeprecationEventForExpectation();

$this->deprecationExpected = true;
$this->expectedDeprecationMessage = $message;
}

final public function expectDeprecationMessageMatches(string $regularExpression): void
{
Facade::ignoreTestTriggeredDeprecationEventForExpectation();

$this->deprecationExpected = true;
$this->expectedDeprecationMessageRegularExpression = $regularExpression;
}

final public function expectError(): void
{
Facade::ignoreTestTriggeredErrorEventForExpectation();

$this->errorExpected = true;
}

final public function expectErrorMessage(string $message): void
{
Facade::ignoreTestTriggeredErrorEventForExpectation();

$this->errorExpected = true;
$this->expectedErrorMessage = $message;
}

final public function expectErrorMessageMatches(string $regularExpression): void
{
Facade::ignoreTestTriggeredErrorEventForExpectation();

$this->errorExpected = true;
$this->expectedErrorMessageRegularExpression = $regularExpression;
}

final public function expectNotice(): void
{
Facade::ignoreTestTriggeredNoticeEventForExpectation();

$this->noticeExpected = true;
}

final public function expectNoticeMessage(string $message): void
{
Facade::ignoreTestTriggeredNoticeEventForExpectation();

$this->noticeExpected = true;
$this->expectedNoticeMessage = $message;
}

final public function expectNoticeMessageMatches(string $regularExpression): void
{
Facade::ignoreTestTriggeredNoticeEventForExpectation();

$this->noticeExpected = true;
$this->expectedNoticeMessageRegularExpression = $regularExpression;
}

final public function expectWarning(): void
{
Facade::ignoreTestTriggeredWarningEventForExpectation();

$this->warningExpected = true;
}

final public function expectWarningMessage(string $message): void
{
Facade::ignoreTestTriggeredWarningEventForExpectation();

$this->warningExpected = true;
$this->expectedWarningMessage = $message;
}

final public function expectWarningMessageMatches(string $regularExpression): void
{
Facade::ignoreTestTriggeredWarningEventForExpectation();

$this->warningExpected = true;
$this->expectedWarningMessageRegularExpression = $regularExpression;
}

final public function status(): TestStatus
{
return $this->status;
Expand Down Expand Up @@ -745,22 +634,15 @@ final public function runBare(): void
} catch (TimeoutException $e) {
$this->status = TestStatus::risky($e->getMessage());
} catch (Throwable $_e) {
if (!$this->errorExpected || $_e::class !== 'Error') {
$e = $_e;
$this->status = TestStatus::error($_e->getMessage());
$e = $_e;
$this->status = TestStatus::error($_e->getMessage());

$emitter->testErrored(
$this->valueObjectForEvents(),
Event\Code\Throwable::from($_e)
);
}
$emitter->testErrored(
$this->valueObjectForEvents(),
Event\Code\Throwable::from($_e)
);
}

$this->verifyDeprecationExpectations();
$this->verifyErrorExpectations();
$this->verifyNoticeExpectations();
$this->verifyWarningExpectations();

if ($this->stopOutputBuffering() && !isset($e)) {
$this->performAssertionsOnOutput();
}
Expand Down Expand Up @@ -2137,152 +2019,4 @@ private function expectedExceptionWasNotRaised(): void
);
}
}

private function verifyDeprecationExpectations(): void
{
if (!$this->deprecationExpected) {
return;
}

$this->numberOfAssertionsPerformed++;

if (!Facade::hasIgnoredEvent()) {
throw new AssertionFailedError('Failed asserting that a deprecation is triggered');
}

$event = Facade::ignoredEvent();

assert($event instanceof DeprecationTriggered || $event instanceof PhpDeprecationTriggered);

if ($this->expectedDeprecationMessage !== null) {
$this->assertThat(
$event->message(),
new MessageIsOrContains(
'deprecation',
$this->expectedDeprecationMessage
)
);
}

if ($this->expectedDeprecationMessageRegularExpression !== null) {
$this->assertThat(
$event->message(),
new MessageMatchesRegularExpression(
'deprecation',
$this->expectedDeprecationMessage
)
);
}
}

private function verifyErrorExpectations(): void
{
if (!$this->errorExpected) {
return;
}

$this->numberOfAssertionsPerformed++;

if (!Facade::hasIgnoredEvent()) {
throw new AssertionFailedError('Failed asserting that an error is triggered');
}

$event = Facade::ignoredEvent();

assert($event instanceof ErrorTriggered);

if ($this->expectedErrorMessage !== null) {
$this->assertThat(
$event->message(),
new MessageIsOrContains(
'error',
$this->expectedErrorMessage
)
);
}

if ($this->expectedErrorMessageRegularExpression !== null) {
$this->assertThat(
$event->message(),
new MessageMatchesRegularExpression(
'error',
$this->expectedErrorMessage
)
);
}
}

private function verifyNoticeExpectations(): void
{
if (!$this->noticeExpected) {
return;
}

$this->numberOfAssertionsPerformed++;

if (!Facade::hasIgnoredEvent()) {
throw new AssertionFailedError('Failed asserting that a notice is triggered');
}

$event = Facade::ignoredEvent();

assert($event instanceof NoticeTriggered || $event instanceof PhpNoticeTriggered);

if ($this->expectedNoticeMessage !== null) {
$this->assertThat(
$event->message(),
new MessageIsOrContains(
'notice',
$this->expectedNoticeMessage
)
);
}

if ($this->expectedNoticeMessageRegularExpression !== null) {
$this->assertThat(
$event->message(),
new MessageMatchesRegularExpression(
'notice',
$this->expectedNoticeMessage
)
);
}
}

private function verifyWarningExpectations(): void
{
if (!$this->warningExpected) {
return;
}

$this->numberOfAssertionsPerformed++;

if (!Facade::hasIgnoredEvent()) {
throw new AssertionFailedError('Failed asserting that a warning is triggered');
}

$event = Facade::ignoredEvent();

assert($event instanceof WarningTriggered || $event instanceof PhpWarningTriggered);

if ($this->expectedWarningMessage !== null) {
$this->assertThat(
$event->message(),
new MessageIsOrContains(
'warning',
$this->expectedWarningMessage
)
);
}

if ($this->expectedWarningMessageRegularExpression !== null) {
$this->assertThat(
$event->message(),
new MessageMatchesRegularExpression(
'warning',
$this->expectedWarningMessage
)
);
}
}
}

0 comments on commit a2c784c

Please sign in to comment.