Merge pull request #24 from aRn0D/symfony4_support
Provide Symfony 4 support
This commit is contained in:
@@ -18,6 +18,7 @@ before_install:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
- composer require symfony/http-kernel:${SYMFONY_VERSION} --no-update --no-scripts --prefer-dist
|
- 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 require --dev symfony/framework-bundle:${SYMFONY_VERSION} --no-update --no-scripts --prefer-dist
|
||||||
- composer update --prefer-dist
|
- composer update --prefer-dist
|
||||||
|
|
||||||
|
|||||||
25
README.md
25
README.md
@@ -27,4 +27,29 @@ ensures that application behaviour will not be affected by stateful services.
|
|||||||
FriendsOfBehat\SymfonyExtension: ~
|
FriendsOfBehat\SymfonyExtension: ~
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Symfony 3 configuration**
|
||||||
|
|
||||||
|
```
|
||||||
|
FriendsOfBehat\SymfonyExtension:
|
||||||
|
kernel:
|
||||||
|
bootstrap: 'var/bootstrap.php.cache'
|
||||||
|
path: app/AppKernel.php
|
||||||
|
class: 'AppKernel'
|
||||||
|
env: test
|
||||||
|
debug: true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Symfony 4 configuration**
|
||||||
|
|
||||||
|
```
|
||||||
|
FriendsOfBehat\SymfonyExtension:
|
||||||
|
env_file: .env
|
||||||
|
kernel:
|
||||||
|
class: 'MyTrip\Kernel'
|
||||||
|
path: src/Kernel.php
|
||||||
|
debug: true
|
||||||
|
```
|
||||||
|
|
||||||
|
Symfony 4 does not have bootstrap file anymore and the environment is configured in the .env file.
|
||||||
|
|
||||||
3. Good luck & have fun!
|
3. Good luck & have fun!
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
"php": "^7.1",
|
"php": "^7.1",
|
||||||
|
|
||||||
"behat/behat": "^3.1",
|
"behat/behat": "^3.1",
|
||||||
"symfony/http-kernel": "^3.3|^4.0"
|
"symfony/http-kernel": "^3.3|^4.0",
|
||||||
|
"symfony/dotenv": "^3.3|^4.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"behat/mink": "^1.7",
|
"behat/mink": "^1.7",
|
||||||
|
|||||||
@@ -56,3 +56,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 boot a Symfony4 kernel
|
||||||
|
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" 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
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\Container;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Component\Dotenv\Dotenv;
|
||||||
|
|
||||||
final class SymfonyExtension implements Extension
|
final class SymfonyExtension implements Extension
|
||||||
{
|
{
|
||||||
@@ -60,6 +61,16 @@ final class SymfonyExtension implements Extension
|
|||||||
*/
|
*/
|
||||||
const SHARED_KERNEL_CONTAINER_ID = 'sylius_symfony_extension.shared_kernel.container';
|
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
|
* @var CrossContainerProcessor|null
|
||||||
*/
|
*/
|
||||||
@@ -90,6 +101,7 @@ final class SymfonyExtension implements Extension
|
|||||||
$builder
|
$builder
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
|
->scalarNode('env_file')->defaultNull()->end()
|
||||||
->arrayNode('kernel')
|
->arrayNode('kernel')
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
@@ -110,6 +122,16 @@ 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']) {
|
||||||
|
$this->loadEnvVars($container, $config['env_file']);
|
||||||
|
|
||||||
|
$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']);
|
$this->loadKernel($container, $config['kernel']);
|
||||||
$this->loadKernelContainer($container);
|
$this->loadKernelContainer($container);
|
||||||
|
|
||||||
@@ -129,6 +151,16 @@ final class SymfonyExtension implements Extension
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ContainerBuilder $container
|
||||||
|
* @param string $fileName
|
||||||
|
*/
|
||||||
|
private function loadEnvVars(ContainerBuilder $container, string $fileName): void
|
||||||
|
{
|
||||||
|
$envFilePath = sprintf('%s/%s', $container->getParameter('paths.base'), $fileName);
|
||||||
|
(new Dotenv())->load($envFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
*/
|
*/
|
||||||
@@ -203,6 +235,8 @@ final class SymfonyExtension implements Extension
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function declareSymfonyContainers(ContainerBuilder $container): void
|
private function declareSymfonyContainers(ContainerBuilder $container): void
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user