Skip to content

Commit a2c784c

Browse files
Remove expectDeprecation*(), expectError*(), expectNotice*(), and expectWarning*()
1 parent 687b6ab commit a2c784c

File tree

8 files changed

+16
-515
lines changed

8 files changed

+16
-515
lines changed

.psalm/baseline.xml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,7 @@
328328
<InvalidReturnType occurrences="1">
329329
<code>MockObject&amp;RealInstanceType</code>
330330
</InvalidReturnType>
331-
<MissingThrowsDocblock occurrences="29">
332-
<code>Facade::ignoredEvent()</code>
333-
<code>Facade::ignoredEvent()</code>
334-
<code>Facade::ignoredEvent()</code>
335-
<code>Facade::ignoredEvent()</code>
336-
<code>assertThat</code>
337-
<code>assertThat</code>
338-
<code>assertThat</code>
339-
<code>assertThat</code>
340-
<code>assertThat</code>
341-
<code>assertThat</code>
342-
<code>assertThat</code>
343-
<code>assertThat</code>
331+
<MissingThrowsDocblock occurrences="13">
344332
<code>assertThat</code>
345333
<code>assertThat</code>
346334
<code>assertThat</code>
@@ -354,17 +342,7 @@
354342
<code>getMockForTrait</code>
355343
<code>getObjectForTrait</code>
356344
<code>onlyMethods</code>
357-
<code>throw new AssertionFailedError('Failed asserting that a deprecation is triggered');</code>
358-
<code>throw new AssertionFailedError('Failed asserting that a notice is triggered');</code>
359-
<code>throw new AssertionFailedError('Failed asserting that a warning is triggered');</code>
360-
<code>throw new AssertionFailedError('Failed asserting that an error is triggered');</code>
361345
</MissingThrowsDocblock>
362-
<PossiblyNullArgument occurrences="4">
363-
<code>$this-&gt;expectedDeprecationMessage</code>
364-
<code>$this-&gt;expectedErrorMessage</code>
365-
<code>$this-&gt;expectedNoticeMessage</code>
366-
<code>$this-&gt;expectedWarningMessage</code>
367-
</PossiblyNullArgument>
368346
<PropertyNotSetInConstructor occurrences="1">
369347
<code>$outputBufferingLevel</code>
370348
</PropertyNotSetInConstructor>

ChangeLog-10.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
7777
* [#4564](https://github.com/sebastianbergmann/phpunit/issues/4564): Remove `withConsecutive()`
7878
* [#4567](https://github.com/sebastianbergmann/phpunit/issues/4567): Remove support for generators in `assertCount()` and `Count` constraint
7979
* [#4601](https://github.com/sebastianbergmann/phpunit/issues/4601): Remove assertions that operate on class/object properties
80+
* Removed the `expectDeprecation()`, `expectDeprecationMessage()`, and `expectDeprecationMessageMatches()` methods
81+
* Removed the `expectError()`, `expectErrorMessage()`, and `expectErrorMessageMatches()` methods
82+
* Removed the `expectNotice()`, `expectNoticeMessage()`, and `expectNoticeMessageMatches()` methods
83+
* Removed the `expectWarning()`, `expectWarningMessage()`, and `expectWarningMessageMatches()` methods
8084
* Removed the `PHPUnit\Runner\TestSuiteLoader` interface
8185
* Removed the `<listeners>` XML configuration element and its children
8286
* Removed the `groups` attribute on the `<test>` element in the TestDox XML report

src/Framework/TestCase.php

Lines changed: 9 additions & 275 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@
5858
use AssertionError;
5959
use DeepCopy\DeepCopy;
6060
use PHPUnit\Event;
61-
use PHPUnit\Event\Test\DeprecationTriggered;
62-
use PHPUnit\Event\Test\ErrorTriggered;
63-
use PHPUnit\Event\Test\NoticeTriggered;
64-
use PHPUnit\Event\Test\PhpDeprecationTriggered;
65-
use PHPUnit\Event\Test\PhpNoticeTriggered;
66-
use PHPUnit\Event\Test\PhpWarningTriggered;
67-
use PHPUnit\Event\Test\WarningTriggered;
6861
use PHPUnit\Framework\Constraint\Exception as ExceptionConstraint;
6962
use PHPUnit\Framework\Constraint\ExceptionCode;
7063
use PHPUnit\Framework\Constraint\MessageIsOrContains;
@@ -183,21 +176,9 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
183176
/**
184177
* @psalm-var list<Comparator>
185178
*/
186-
private array $customComparators = [];
187-
private ?Event\Code\TestMethod $testValueObjectForEvents = null;
188-
private bool $wasPrepared = false;
189-
private bool $deprecationExpected = false;
190-
private ?string $expectedDeprecationMessage = null;
191-
private ?string $expectedDeprecationMessageRegularExpression = null;
192-
private bool $errorExpected = false;
193-
private ?string $expectedErrorMessage = null;
194-
private ?string $expectedErrorMessageRegularExpression = null;
195-
private bool $noticeExpected = false;
196-
private ?string $expectedNoticeMessage = null;
197-
private ?string $expectedNoticeMessageRegularExpression = null;
198-
private bool $warningExpected = false;
199-
private ?string $expectedWarningMessage = null;
200-
private ?string $expectedWarningMessageRegularExpression = null;
179+
private array $customComparators = [];
180+
private ?Event\Code\TestMethod $testValueObjectForEvents = null;
181+
private bool $wasPrepared = false;
201182

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

438-
final public function expectDeprecation(): void
439-
{
440-
Facade::ignoreTestTriggeredDeprecationEventForExpectation();
441-
442-
$this->deprecationExpected = true;
443-
}
444-
445-
final public function expectDeprecationMessage(string $message): void
446-
{
447-
Facade::ignoreTestTriggeredDeprecationEventForExpectation();
448-
449-
$this->deprecationExpected = true;
450-
$this->expectedDeprecationMessage = $message;
451-
}
452-
453-
final public function expectDeprecationMessageMatches(string $regularExpression): void
454-
{
455-
Facade::ignoreTestTriggeredDeprecationEventForExpectation();
456-
457-
$this->deprecationExpected = true;
458-
$this->expectedDeprecationMessageRegularExpression = $regularExpression;
459-
}
460-
461-
final public function expectError(): void
462-
{
463-
Facade::ignoreTestTriggeredErrorEventForExpectation();
464-
465-
$this->errorExpected = true;
466-
}
467-
468-
final public function expectErrorMessage(string $message): void
469-
{
470-
Facade::ignoreTestTriggeredErrorEventForExpectation();
471-
472-
$this->errorExpected = true;
473-
$this->expectedErrorMessage = $message;
474-
}
475-
476-
final public function expectErrorMessageMatches(string $regularExpression): void
477-
{
478-
Facade::ignoreTestTriggeredErrorEventForExpectation();
479-
480-
$this->errorExpected = true;
481-
$this->expectedErrorMessageRegularExpression = $regularExpression;
482-
}
483-
484-
final public function expectNotice(): void
485-
{
486-
Facade::ignoreTestTriggeredNoticeEventForExpectation();
487-
488-
$this->noticeExpected = true;
489-
}
490-
491-
final public function expectNoticeMessage(string $message): void
492-
{
493-
Facade::ignoreTestTriggeredNoticeEventForExpectation();
494-
495-
$this->noticeExpected = true;
496-
$this->expectedNoticeMessage = $message;
497-
}
498-
499-
final public function expectNoticeMessageMatches(string $regularExpression): void
500-
{
501-
Facade::ignoreTestTriggeredNoticeEventForExpectation();
502-
503-
$this->noticeExpected = true;
504-
$this->expectedNoticeMessageRegularExpression = $regularExpression;
505-
}
506-
507-
final public function expectWarning(): void
508-
{
509-
Facade::ignoreTestTriggeredWarningEventForExpectation();
510-
511-
$this->warningExpected = true;
512-
}
513-
514-
final public function expectWarningMessage(string $message): void
515-
{
516-
Facade::ignoreTestTriggeredWarningEventForExpectation();
517-
518-
$this->warningExpected = true;
519-
$this->expectedWarningMessage = $message;
520-
}
521-
522-
final public function expectWarningMessageMatches(string $regularExpression): void
523-
{
524-
Facade::ignoreTestTriggeredWarningEventForExpectation();
525-
526-
$this->warningExpected = true;
527-
$this->expectedWarningMessageRegularExpression = $regularExpression;
528-
}
529-
530419
final public function status(): TestStatus
531420
{
532421
return $this->status;
@@ -745,22 +634,15 @@ final public function runBare(): void
745634
} catch (TimeoutException $e) {
746635
$this->status = TestStatus::risky($e->getMessage());
747636
} catch (Throwable $_e) {
748-
if (!$this->errorExpected || $_e::class !== 'Error') {
749-
$e = $_e;
750-
$this->status = TestStatus::error($_e->getMessage());
637+
$e = $_e;
638+
$this->status = TestStatus::error($_e->getMessage());
751639

752-
$emitter->testErrored(
753-
$this->valueObjectForEvents(),
754-
Event\Code\Throwable::from($_e)
755-
);
756-
}
640+
$emitter->testErrored(
641+
$this->valueObjectForEvents(),
642+
Event\Code\Throwable::from($_e)
643+
);
757644
}
758645

759-
$this->verifyDeprecationExpectations();
760-
$this->verifyErrorExpectations();
761-
$this->verifyNoticeExpectations();
762-
$this->verifyWarningExpectations();
763-
764646
if ($this->stopOutputBuffering() && !isset($e)) {
765647
$this->performAssertionsOnOutput();
766648
}
@@ -2137,152 +2019,4 @@ private function expectedExceptionWasNotRaised(): void
21372019
);
21382020
}
21392021
}
2140-
2141-
private function verifyDeprecationExpectations(): void
2142-
{
2143-
if (!$this->deprecationExpected) {
2144-
return;
2145-
}
2146-
2147-
$this->numberOfAssertionsPerformed++;
2148-
2149-
if (!Facade::hasIgnoredEvent()) {
2150-
throw new AssertionFailedError('Failed asserting that a deprecation is triggered');
2151-
}
2152-
2153-
$event = Facade::ignoredEvent();
2154-
2155-
assert($event instanceof DeprecationTriggered || $event instanceof PhpDeprecationTriggered);
2156-
2157-
if ($this->expectedDeprecationMessage !== null) {
2158-
$this->assertThat(
2159-
$event->message(),
2160-
new MessageIsOrContains(
2161-
'deprecation',
2162-
$this->expectedDeprecationMessage
2163-
)
2164-
);
2165-
}
2166-
2167-
if ($this->expectedDeprecationMessageRegularExpression !== null) {
2168-
$this->assertThat(
2169-
$event->message(),
2170-
new MessageMatchesRegularExpression(
2171-
'deprecation',
2172-
$this->expectedDeprecationMessage
2173-
)
2174-
);
2175-
}
2176-
}
2177-
2178-
private function verifyErrorExpectations(): void
2179-
{
2180-
if (!$this->errorExpected) {
2181-
return;
2182-
}
2183-
2184-
$this->numberOfAssertionsPerformed++;
2185-
2186-
if (!Facade::hasIgnoredEvent()) {
2187-
throw new AssertionFailedError('Failed asserting that an error is triggered');
2188-
}
2189-
2190-
$event = Facade::ignoredEvent();
2191-
2192-
assert($event instanceof ErrorTriggered);
2193-
2194-
if ($this->expectedErrorMessage !== null) {
2195-
$this->assertThat(
2196-
$event->message(),
2197-
new MessageIsOrContains(
2198-
'error',
2199-
$this->expectedErrorMessage
2200-
)
2201-
);
2202-
}
2203-
2204-
if ($this->expectedErrorMessageRegularExpression !== null) {
2205-
$this->assertThat(
2206-
$event->message(),
2207-
new MessageMatchesRegularExpression(
2208-
'error',
2209-
$this->expectedErrorMessage
2210-
)
2211-
);
2212-
}
2213-
}
2214-
2215-
private function verifyNoticeExpectations(): void
2216-
{
2217-
if (!$this->noticeExpected) {
2218-
return;
2219-
}
2220-
2221-
$this->numberOfAssertionsPerformed++;
2222-
2223-
if (!Facade::hasIgnoredEvent()) {
2224-
throw new AssertionFailedError('Failed asserting that a notice is triggered');
2225-
}
2226-
2227-
$event = Facade::ignoredEvent();
2228-
2229-
assert($event instanceof NoticeTriggered || $event instanceof PhpNoticeTriggered);
2230-
2231-
if ($this->expectedNoticeMessage !== null) {
2232-
$this->assertThat(
2233-
$event->message(),
2234-
new MessageIsOrContains(
2235-
'notice',
2236-
$this->expectedNoticeMessage
2237-
)
2238-
);
2239-
}
2240-
2241-
if ($this->expectedNoticeMessageRegularExpression !== null) {
2242-
$this->assertThat(
2243-
$event->message(),
2244-
new MessageMatchesRegularExpression(
2245-
'notice',
2246-
$this->expectedNoticeMessage
2247-
)
2248-
);
2249-
}
2250-
}
2251-
2252-
private function verifyWarningExpectations(): void
2253-
{
2254-
if (!$this->warningExpected) {
2255-
return;
2256-
}
2257-
2258-
$this->numberOfAssertionsPerformed++;
2259-
2260-
if (!Facade::hasIgnoredEvent()) {
2261-
throw new AssertionFailedError('Failed asserting that a warning is triggered');
2262-
}
2263-
2264-
$event = Facade::ignoredEvent();
2265-
2266-
assert($event instanceof WarningTriggered || $event instanceof PhpWarningTriggered);
2267-
2268-
if ($this->expectedWarningMessage !== null) {
2269-
$this->assertThat(
2270-
$event->message(),
2271-
new MessageIsOrContains(
2272-
'warning',
2273-
$this->expectedWarningMessage
2274-
)
2275-
);
2276-
}
2277-
2278-
if ($this->expectedWarningMessageRegularExpression !== null) {
2279-
$this->assertThat(
2280-
$event->message(),
2281-
new MessageMatchesRegularExpression(
2282-
'warning',
2283-
$this->expectedWarningMessage
2284-
)
2285-
);
2286-
}
2287-
}
22882022
}

0 commit comments

Comments
 (0)