From 47697265644433e681dc56de6ebb3cea230cb38e Mon Sep 17 00:00:00 2001 From: Rafikooo Date: Wed, 14 Sep 2022 13:34:20 +0200 Subject: [PATCH] [Behat][Fix] Check notification expectation in JavaScriptTestHelper --- .../Context/Ui/Admin/NotificationContext.php | 8 ++++---- .../Service/Helper/JavaScriptTestHelper.php | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php b/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php index 992e197cd3a..295bbb1d5bb 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php @@ -51,15 +51,15 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void } /** - * @Then I should be notified that it has been successfully deleted - * @Then I should be notified that they have been successfully deleted + * @Then I should be notified that it :has been successfully deleted + * @Then I should be notified that they :have been successfully deleted */ - public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted(): void + public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted(string $hasHave): void { $this->testHelper->waitUntilNotificationPopups( $this->notificationChecker, NotificationType::success(), - 'has been successfully deleted.', + sprintf('%s been successfully deleted.', $hasHave), ); } diff --git a/src/Sylius/Behat/Service/Helper/JavaScriptTestHelper.php b/src/Sylius/Behat/Service/Helper/JavaScriptTestHelper.php index 991b761a3c0..b63d2d8c3bd 100644 --- a/src/Sylius/Behat/Service/Helper/JavaScriptTestHelper.php +++ b/src/Sylius/Behat/Service/Helper/JavaScriptTestHelper.php @@ -16,6 +16,7 @@ use Behat\Mink\Exception\ElementNotFoundException; use FriendsOfBehat\PageObjectExtension\Page\PageInterface; use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException; +use Sylius\Behat\Exception\NotificationExpectationMismatchException; use Sylius\Behat\NotificationType; use Sylius\Behat\Service\NotificationCheckerInterface; @@ -42,7 +43,12 @@ public function waitUntilNotificationPopups( $notificationChecker->checkNotification($message, $type); }; - $this->waitUntilExceptionDisappears($callable, ElementNotFoundException::class, $timeout); + $this->waitUntilExceptionDisappears( + $callable, + ElementNotFoundException::class, + $timeout, + $type, + ); } public function waitUntilPageOpens(PageInterface $page, ?array $options = [], ?int $timeout = null): void @@ -54,7 +60,12 @@ public function waitUntilPageOpens(PageInterface $page, ?array $options = [], ?i $this->waitUntilExceptionDisappears($callable, UnexpectedPageException::class, $timeout); } - private function waitUntilExceptionDisappears(callable $callable, string $exceptionClass, ?int $timeout = null): void + private function waitUntilExceptionDisappears( + callable $callable, + string $exceptionClass, + ?int $timeout = null, + NotificationType $type = null, + ): void { $start = microtime(true); $timeout ??= $this->defaultTimeout; @@ -63,6 +74,8 @@ private function waitUntilExceptionDisappears(callable $callable, string $except do { try { $callable(); + } catch (NotificationExpectationMismatchException $exception) { + throw new NotificationExpectationMismatchException($type, $exception->getMessage()); } catch (\Exception $exception) { if ($exception instanceof $exceptionClass) { usleep($this->microsecondsInterval);