Skip to content

Commit

Permalink
Fail if expected exception was not thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
simensen committed Aug 23, 2023
1 parent b4d7318 commit ef62e28
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Testing/GivenWhenThen/Scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public function assert(): self
$handler = [$handler, 'handle'];
}

$caughtException = false;

try {
($handler)($instance->when->command);
} catch (\Throwable $throwable) {
Expand All @@ -179,13 +181,19 @@ public function assert(): self
} else {
Assert::assertEquals($instance->expect, $throwable);
}

$caughtException = true;
} else {
throw $throwable;
}
}

$recordedEvents = $messageRepository->lastCommit();

if (isset($instance->expect) && !$caughtException) {
Assert::fail('Expected exception not thrown.');
}

if (!isset($instance->outcome)) {
Assert::fail('Expected an outcome.');
}
Expand Down

0 comments on commit ef62e28

Please sign in to comment.