diff --git a/.travis.yml b/.travis.yml index e937fc1..3ae989d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ before_install: install: - composer require symfony/http-kernel:${SYMFONY_VERSION} --no-update --no-scripts --prefer-dist + - composer require symfony/dotenv:${SYMFONY_VERSION} --no-update --no-scripts --prefer-dist - composer require --dev symfony/framework-bundle:${SYMFONY_VERSION} --no-update --no-scripts --prefer-dist - composer update --prefer-dist diff --git a/composer.json b/composer.json index ec36bf9..d6784c0 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "behat/behat": "^3.1", "symfony/http-kernel": "^3.3|^4.0", - "symfony/dotenv": "^4.0" + "symfony/dotenv": "^3.3|^4.0" }, "require-dev": { "behat/mink": "^1.7", diff --git a/features/not_crashing_behat.feature b/features/not_crashing_behat.feature index 1386842..7fc7f9b 100644 --- a/features/not_crashing_behat.feature +++ b/features/not_crashing_behat.feature @@ -67,6 +67,7 @@ Feature: Not crashing Behat kernel: path: src/MyKernel.php class: MyKernel + bootstrap: ~ """ And a file ".env_in_memory" containing: """ diff --git a/src/ServiceContainer/SymfonyExtension.php b/src/ServiceContainer/SymfonyExtension.php index 35bdabd..10afb25 100644 --- a/src/ServiceContainer/SymfonyExtension.php +++ b/src/ServiceContainer/SymfonyExtension.php @@ -61,6 +61,16 @@ final class SymfonyExtension implements Extension */ const SHARED_KERNEL_CONTAINER_ID = 'sylius_symfony_extension.shared_kernel.container'; + /** + * Default symfony environment used to run your suites. + */ + private const DEFAULT_ENV = 'test'; + + /** + * Enable or disable the debug mode + */ + private const DEBUG_MODE = false; + /** * @var CrossContainerProcessor|null */ @@ -115,10 +125,11 @@ final class SymfonyExtension implements Extension if (null !== $config['env_file']) { $this->loadEnvVars($container, $config['env_file']); - $environment = getenv('APP_ENV'); - $config['kernel']['env'] = $environment ?? 'test'; - } else { - $this->requireKernelBootstrapFile($container->getParameter('paths.base'), $config['bootstrap']); + $environment = false !== getenv('APP_ENV') ? getenv('APP_ENV') : self::DEFAULT_ENV; + $debugMode = false !== getenv('APP_DEBUG') ? getenv('APP_DEBUG') : self::DEBUG_MODE; + + $config['kernel']['env'] = $environment; + $config['kernel']['kernel'] = $debugMode; } $this->loadKernel($container, $config['kernel']); @@ -142,7 +153,7 @@ final class SymfonyExtension implements Extension /** * @param ContainerBuilder $container - * @param string $fileName + * @param string $fileName */ private function loadEnvVars(ContainerBuilder $container, string $fileName): void { @@ -163,6 +174,8 @@ final class SymfonyExtension implements Extension $definition->setFile($this->getKernelFile($container->getParameter('paths.base'), $config['path'])); $container->setDefinition(self::KERNEL_ID, $definition); + + $this->requireKernelBootstrapFile($container->getParameter('paths.base'), $config['bootstrap']); } /**