From 9cc5df85bfeedb11f63b12df3fd04fed46265075 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Mon, 31 Dec 2018 15:48:56 +0100 Subject: [PATCH] Throw an exception if the bundle isn't registered --- .../Handler/ContextServiceEnvironmentHandler.php | 13 +++++++++++++ src/ServiceContainer/SymfonyExtension.php | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Context/Environment/Handler/ContextServiceEnvironmentHandler.php b/src/Context/Environment/Handler/ContextServiceEnvironmentHandler.php index 438db23..07815e0 100644 --- a/src/Context/Environment/Handler/ContextServiceEnvironmentHandler.php +++ b/src/Context/Environment/Handler/ContextServiceEnvironmentHandler.php @@ -20,6 +20,7 @@ use Behat\Testwork\Environment\Exception\EnvironmentIsolationException; use Behat\Testwork\Environment\Handler\EnvironmentHandler; use Behat\Testwork\Suite\Exception\SuiteConfigurationException; use Behat\Testwork\Suite\Suite; +use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle; use FriendsOfBehat\SymfonyExtension\Context\Environment\InitialisedContextServiceEnvironment; use FriendsOfBehat\SymfonyExtension\Context\Environment\UninitialisedContextServiceEnvironment; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -155,6 +156,18 @@ final class ContextServiceEnvironmentHandler implements EnvironmentHandler private function getContainer(): ContainerInterface { + try { + $this->symfonyKernel->getBundle('FriendsOfBehatSymfonyExtensionBundle'); + } catch (\InvalidArgumentException $exception) { + throw new \DomainException(sprintf( + 'Kernel "%s" used in Behat in "%s" environment with debug %s needs to have "%s" bundle registered.', + get_class($this->symfonyKernel), + $this->symfonyKernel->getEnvironment(), + $this->symfonyKernel->isDebug() ? 'enabled' : 'disabled', + FriendsOfBehatSymfonyExtensionBundle::class + ), 0, $exception); + } + return $this->symfonyKernel->getContainer(); } } diff --git a/src/ServiceContainer/SymfonyExtension.php b/src/ServiceContainer/SymfonyExtension.php index 4db0b81..c7f57fa 100644 --- a/src/ServiceContainer/SymfonyExtension.php +++ b/src/ServiceContainer/SymfonyExtension.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace FriendsOfBehat\SymfonyExtension\ServiceContainer; use Behat\Behat\Context\ServiceContainer\ContextExtension; -use Behat\Mink\Mink; use Behat\Mink\Session; use Behat\MinkExtension\ServiceContainer\MinkExtension; use Behat\Testwork\Environment\ServiceContainer\EnvironmentExtension;