Merge pull request #38 from Zales0123/load-dist-files-by-default
Use dist env file by default
This commit is contained in:
@@ -44,6 +44,7 @@ ensures that application behaviour will not be affected by stateful services.
|
||||
|
||||
```
|
||||
FriendsOfBehat\SymfonyExtension:
|
||||
# .env.dist file will be used if .env file does not exist
|
||||
env_file: .env
|
||||
kernel:
|
||||
class: 'MyTrip\Kernel'
|
||||
|
||||
@@ -89,3 +89,36 @@ Feature: Not crashing Behat
|
||||
And a feature file with passing scenario
|
||||
When I run Behat
|
||||
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
|
||||
|
||||
@@ -115,7 +115,8 @@ final class SymfonyExtension implements Extension
|
||||
public function load(ContainerBuilder $container, array $config): void
|
||||
{
|
||||
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;
|
||||
$debugMode = false !== getenv('APP_DEBUG') ? getenv('APP_DEBUG') : self::DEBUG_MODE;
|
||||
|
||||
Reference in New Issue
Block a user