From 48c28fe8c70919f834115427afbe3d9532e6f59b Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Wed, 13 Nov 2024 09:53:09 +0100 Subject: [PATCH 1/3] BUGFIX: Behat: Reset `lastCommandException` once asserted Without this fix it was not possible to expect multiple exceptions in a single step or, worse, it led to false positives: ```gherkin Scenario: When doing something Then the last command should have thrown an exception of type "Foo" When doing something else Then the last command should have thrown an exception of type "Bar" ``` The 2nd time would succeed even if the previous interaction did not lead to an exception --- .../Bootstrap/GenericCommandExecutionAndEventPublication.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php b/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php index 67c91d5..4c97d14 100644 --- a/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php +++ b/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php @@ -321,6 +321,7 @@ public function theLastCommandShouldHaveThrown(string $shortExceptionName, ?int $this->lastCommandException->getMessage() )); } + $this->lastCommandException = null; } /** From c8238e38e5eba51737bd8a32fffffef16cfedb25 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:09:25 +0100 Subject: [PATCH 2/3] TASK: Enforce command exceptions are asserted --- ...GenericCommandExecutionAndEventPublication.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php b/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php index 4c97d14..af0ba47 100644 --- a/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php +++ b/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php @@ -344,6 +344,21 @@ public function theLastCommandShouldHaveThrownTheWorkspaceRebaseFailedWith(Table } Assert::assertSame($payloadTable->getHash(), $actualComparableHash); + $this->lastCommandException = null; + } + + /** + * @AfterScenario + */ + public function ensureNoUnhandledCommandExceptions(): void + { + if ($this->lastCommandException !== null) { + Assert::fail(sprintf( + 'Last command did throw with exception which was not asserted: %s: %s', + $this->lastCommandException::class, + $this->lastCommandException->getMessage() + )); + } } /** From c2279ea732622d004ac7ec630cd75a68980e4535 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:24:17 +0100 Subject: [PATCH 3/3] TASK: Improve lastCommandException assertions --- .../GenericCommandExecutionAndEventPublication.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php b/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php index af0ba47..8ca9633 100644 --- a/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php +++ b/Classes/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php @@ -350,13 +350,15 @@ public function theLastCommandShouldHaveThrownTheWorkspaceRebaseFailedWith(Table /** * @AfterScenario */ - public function ensureNoUnhandledCommandExceptions(): void + public function ensureNoUnhandledCommandExceptions(\Behat\Behat\Hook\Scope\AfterScenarioScope $event): void { if ($this->lastCommandException !== null) { Assert::fail(sprintf( - 'Last command did throw with exception which was not asserted: %s: %s', + 'Last command did throw with exception which was not asserted: %s: "%s" in %s:%s', $this->lastCommandException::class, - $this->lastCommandException->getMessage() + $this->lastCommandException->getMessage(), + $event->getFeature()->getFile(), + $event->getScenario()->getLine(), )); } }