Throw an exception if the bundle isn't registered

This commit is contained in:
Kamil Kokot
2018-12-31 15:48:56 +01:00
parent 5151d30b24
commit 9cc5df85bf
2 changed files with 13 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ use Behat\Testwork\Environment\Exception\EnvironmentIsolationException;
use Behat\Testwork\Environment\Handler\EnvironmentHandler; use Behat\Testwork\Environment\Handler\EnvironmentHandler;
use Behat\Testwork\Suite\Exception\SuiteConfigurationException; use Behat\Testwork\Suite\Exception\SuiteConfigurationException;
use Behat\Testwork\Suite\Suite; use Behat\Testwork\Suite\Suite;
use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle;
use FriendsOfBehat\SymfonyExtension\Context\Environment\InitialisedContextServiceEnvironment; use FriendsOfBehat\SymfonyExtension\Context\Environment\InitialisedContextServiceEnvironment;
use FriendsOfBehat\SymfonyExtension\Context\Environment\UninitialisedContextServiceEnvironment; use FriendsOfBehat\SymfonyExtension\Context\Environment\UninitialisedContextServiceEnvironment;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -155,6 +156,18 @@ final class ContextServiceEnvironmentHandler implements EnvironmentHandler
private function getContainer(): ContainerInterface 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(); return $this->symfonyKernel->getContainer();
} }
} }

View File

@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace FriendsOfBehat\SymfonyExtension\ServiceContainer; namespace FriendsOfBehat\SymfonyExtension\ServiceContainer;
use Behat\Behat\Context\ServiceContainer\ContextExtension; use Behat\Behat\Context\ServiceContainer\ContextExtension;
use Behat\Mink\Mink;
use Behat\Mink\Session; use Behat\Mink\Session;
use Behat\MinkExtension\ServiceContainer\MinkExtension; use Behat\MinkExtension\ServiceContainer\MinkExtension;
use Behat\Testwork\Environment\ServiceContainer\EnvironmentExtension; use Behat\Testwork\Environment\ServiceContainer\EnvironmentExtension;