Skip to content

Commit 21087d6

Browse files
committed
Logger PHPStan fix
1 parent f852f82 commit 21087d6

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

src/Codeception/Module/Symfony/EventsAssertionsTrait.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ trait EventsAssertionsTrait
3232
*/
3333
public function dontSeeEvent(array|string|null $expected = null): void
3434
{
35-
$actualEvents = $this->getDispatchedEventNames();
36-
$actual = [$this->getOrphanedEvents(), $actualEvents];
37-
$this->assertEventTriggered(false, $expected, $actual);
35+
$this->handleEventAssertion(false, $expected, false);
3836
}
3937

4038
/**
@@ -96,8 +94,7 @@ public function dontSeeEventTriggered(array|object|string $expected): void
9694
*/
9795
public function dontSeeOrphanEvent(array|string|null $expected = null): void
9896
{
99-
$actual = [$this->getOrphanedEvents()];
100-
$this->assertEventTriggered(false, $expected, $actual);
97+
$this->handleEventAssertion(false, $expected, true);
10198
}
10299

103100
/**
@@ -112,9 +109,7 @@ public function dontSeeOrphanEvent(array|string|null $expected = null): void
112109
*/
113110
public function seeEvent(array|string $expected): void
114111
{
115-
$actualEvents = $this->getDispatchedEventNames();
116-
$actual = [$this->getOrphanedEvents(), $actualEvents];
117-
$this->assertEventTriggered(true, $expected, $actual);
112+
$this->handleEventAssertion(true, $expected, false);
118113
}
119114

120115
/**
@@ -175,8 +170,7 @@ public function seeEventTriggered(array|object|string $expected): void
175170
*/
176171
public function seeOrphanEvent(array|string $expected): void
177172
{
178-
$actual = [$this->getOrphanedEvents()];
179-
$this->assertEventTriggered(true, $expected, $actual);
173+
$this->handleEventAssertion(true, $expected, true);
180174
}
181175

182176
/** @return list<array{event: string, pretty: string}> */
@@ -191,16 +185,6 @@ protected function getDispatchedEvents(): array
191185
return $events;
192186
}
193187

194-
/** @return list<string> */
195-
private function getDispatchedEventNames(): array
196-
{
197-
$names = [];
198-
foreach ($this->getDispatchedEvents() as $listener) {
199-
$names[] = $listener['event'];
200-
}
201-
return $names;
202-
}
203-
204188
/** @return list<string> */
205189
protected function getOrphanedEvents(): array
206190
{
@@ -213,6 +197,16 @@ protected function getOrphanedEvents(): array
213197
return $events;
214198
}
215199

200+
/** @param string|object|list<string|object>|null $expected */
201+
private function handleEventAssertion(bool $assertTrue, array|object|string|null $expected, bool $orphanOnly): void
202+
{
203+
$actual = $orphanOnly
204+
? [$this->getOrphanedEvents()]
205+
: [$this->getOrphanedEvents(), array_column($this->getDispatchedEvents(), 'event')];
206+
207+
$this->assertEventTriggered($assertTrue, $expected, $actual);
208+
}
209+
216210
/**
217211
* @param string|object|list<string|object>|null $expected
218212
* @param list<list<string>> $actual
@@ -257,7 +251,7 @@ protected function assertListenerCalled(
257251
if ($expectedEvents === []) {
258252
$expectedEvents = [null];
259253
} elseif (count($expectedListeners) > 1) {
260-
Assert::fail('Cannot check multiple listeners with specific events; split assertions.');
254+
Assert::fail('Cannot check for events when using multiple listeners. Make multiple assertions instead.');
261255
}
262256

263257
$actualEvents = $this->getDispatchedEvents();

0 commit comments

Comments
 (0)