Skip to content

Commit

Permalink
Make phpDoc and variable names more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
xEdelweiss committed Dec 19, 2023
1 parent 8836add commit 71d11e9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Codeception/Module/Symfony/EventsAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function dontSeeOrphanEvent(array|object|string $expected = null): void

/**
* Verifies that there were no events during the test.
* Orphan events are included. Use `dontSeeOrphanEvent` to exclude them.
* Both regular and orphan events are checked.
*
* ```php
* <?php
Expand Down Expand Up @@ -158,7 +158,10 @@ public function seeOrphanEvent(array|object|string $expected): void

/**
* Verifies that one or more events were dispatched during the test.
* Orphan events are included. Use `seeOrphanEvent` to exclude them.
* Both regular and orphan events are checked.
*
* If you need to verify that expected event is not orphan,
* add `dontSeeOrphanEvent` call.
*
* ```php
* <?php
Expand All @@ -168,7 +171,6 @@ public function seeOrphanEvent(array|object|string $expected): void
* ```
*
* @param array|object|string $expected
* @see seeOrphanEvent
*/
public function seeEvent(array|object|string $expected): void
{
Expand Down Expand Up @@ -250,24 +252,24 @@ protected function assertEventTriggered(
$this->fail('No event was triggered');
}

$actual = array_map(static fn (Data $data) => $data->getValue(true), $data);
$actualEventsCollection = array_map(static fn (Data $data) => $data->getValue(true), $data);

foreach ($expected as $expectedEvent) {
$expectedEvent = is_object($expectedEvent) ? $expectedEvent::class : $expectedEvent;
$message = $assertTrue
? "The '{$expectedEvent}' event did not trigger"
: "The '{$expectedEvent}' event triggered";

$condition = false;
$eventTriggered = false;

foreach ($actual as $actualEvents) {
$condition = $condition || $this->eventWasTriggered($actualEvents, (string)$expectedEvent);
foreach ($actualEventsCollection as $actualEvents) {
$eventTriggered = $eventTriggered || $this->eventWasTriggered($actualEvents, (string)$expectedEvent);
}

if ($assertTrue) {
$this->assertTrue($condition, $message);
$this->assertTrue($eventTriggered, $message);
} else {
$this->assertFalse($condition, $message);
$this->assertFalse($eventTriggered, $message);
}
}
}
Expand Down

0 comments on commit 71d11e9

Please sign in to comment.