Merge pull request #38 from Zales0123/load-dist-files-by-default

Use dist env file by default
This commit is contained in:
Kamil Kokot
2018-09-25 13:18:21 +02:00
committed by GitHub
3 changed files with 36 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ ensures that application behaviour will not be affected by stateful services.
``` ```
FriendsOfBehat\SymfonyExtension: FriendsOfBehat\SymfonyExtension:
# .env.dist file will be used if .env file does not exist
env_file: .env env_file: .env
kernel: kernel:
class: 'MyTrip\Kernel' class: 'MyTrip\Kernel'

View File

@@ -89,3 +89,36 @@ Feature: Not crashing Behat
And a feature file with passing scenario And a feature file with passing scenario
When I run Behat When I run Behat
Then it should pass Then it should pass
Scenario: This extension used dist file by default
Given a Behat configuration containing:
"""
default:
extensions:
FriendsOfBehat\SymfonyExtension:
env_file: .env_in_memory
kernel:
path: src/MyKernel.php
class: MyKernel
bootstrap: ~
"""
And a file ".env_in_memory.dist" containing:
"""
APP_ENV=dev
"""
And a file "src/MyKernel.php" containing:
"""
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class MyKernel extends Kernel
{
public function registerBundles() { return []; }
public function registerContainerConfiguration(LoaderInterface $loader) {}
}
"""
And a feature file with passing scenario
When I run Behat
Then it should pass

View File

@@ -115,7 +115,8 @@ final class SymfonyExtension implements Extension
public function load(ContainerBuilder $container, array $config): void public function load(ContainerBuilder $container, array $config): void
{ {
if (null !== $config['env_file']) { if (null !== $config['env_file']) {
$this->loadEnvVars($container, $config['env_file']); $envFile = file_exists($config['env_file']) ? $config['env_file'] : $config['env_file'].'.dist';
$this->loadEnvVars($container, $envFile);
$environment = false !== getenv('APP_ENV') ? getenv('APP_ENV') : self::DEFAULT_ENV; $environment = false !== getenv('APP_ENV') ? getenv('APP_ENV') : self::DEFAULT_ENV;
$debugMode = false !== getenv('APP_DEBUG') ? getenv('APP_DEBUG') : self::DEBUG_MODE; $debugMode = false !== getenv('APP_DEBUG') ? getenv('APP_DEBUG') : self::DEBUG_MODE;