diff --git a/README.md b/README.md index 18b8f35..ed97e39 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,19 @@ FriendsOfBehat\SymfonyExtension: debug: true # When explicitly set, will override APP_DEBUG loaded from env_file file ``` -Symfony 4 is detected, based on the existence of `src/Kernel.php` file, so if you did not migrate to new Symfony structure yet; you need to set those values yourself. +Symfony 4 is automatically detected, based on the existence of default `src/Kernel.php` kernel file. + +If you did not migrate to new Symfony structure yet or you are using custom paths/naming; you need to configure `kernel.boostrap` parameter, to enable default Symfony 4 configuration as shown in the example below: + +``` +FriendsOfBehat\SymfonyExtension: + # env_file: .env # loaded from the default configuration + kernel: + bootstrap: ~ # this enables default Symfony 4 configuration + path: app/AppKernel.php + # class: 'App\Kernel' # loaded from the default configuration + # env: test # loaded from the default configuration + # debug: true # loaded from the default configuration +``` Of course, you can always change each of those settings. diff --git a/features/not_crashing_behat.feature b/features/not_crashing_behat.feature index 69f0135..a2e0f7b 100644 --- a/features/not_crashing_behat.feature +++ b/features/not_crashing_behat.feature @@ -8,9 +8,12 @@ Feature: Not crashing Behat """ default: extensions: - FriendsOfBehat\SymfonyExtension: - kernel: - bootstrap: ~ + FriendsOfBehat\SymfonyExtension: ~ + """ + And a file "app/autoload.php" containing: + """ + children() ->scalarNode('env_file')->end() ->arrayNode('kernel') + ->addDefaultsIfNotSet() ->children() - ->scalarNode('bootstrap')->end() + ->scalarNode('bootstrap')->defaultFalse()->end() ->scalarNode('path')->end() ->scalarNode('class')->end() ->scalarNode('env')->end() @@ -165,15 +166,17 @@ final class SymfonyExtension implements Extension * @param array $userConfig * @return array */ - private function autoconfigure(ContainerBuilder $container, array $userConfig) { - + private function autoconfigure(ContainerBuilder $container, array $userConfig): array + { $defaults = self::SYMFONY_DEFAULTS; - $symfony4KernelPath = sprintf('%s/%s', $container->getParameter('paths.base'), self::SYMFONY_4_DEFAULTS['kernel']['path']); - if (file_exists($symfony4KernelPath)) { + $symfonyFourKernelPath = sprintf('%s/%s', $container->getParameter('paths.base'), self::SYMFONY_4_DEFAULTS['kernel']['path']); + if ($userConfig['kernel']['bootstrap'] === null || file_exists($symfonyFourKernelPath)) { $defaults = self::SYMFONY_4_DEFAULTS; } + $userConfig['kernel']['bootstrap'] = $userConfig['kernel']['bootstrap'] === false ? null : $userConfig['kernel']['bootstrap']; + $config = array_replace_recursive($defaults, $userConfig); if (null !== $config['env_file']) {