Kamil Kokot 7f58add0f4 feature #29 Proposal: Add autoconfiguration for Symfony 4, other tweaks (adiq)
This PR was merged into the 1.4-dev branch.

Discussion
----------

So this is my proposal for SymfonyExtension. Related to #28 

What it changes:

1. Adds autoconfiguration for Symfony 4 (when default `src/Kernel.php` is detected); Improves DX.

So when project bein compliant with new Symfony 4 structure, the configuration will look like:
```
            extensions:
                FriendsOfBehat\SymfonyExtension: ~
```
The standard `.env` file is loaded by default.

2. Explicit settings of `env` and `debug` parameters will override the configuration loaded from `.env` file. This also improves DX, as there is no need for hacky workarounds to get behat working.

3. Fixed issue with the badly named configuration `$config['kernel']['kernel'] = $debugMode;` in 1a39d31f5e

4. Tweaked README to include new configuration details


When it might seem only like an improvement, it's required to get behat working on new Symfony 4 structure when you: do not want to store a separate copy of `.env` with only `APP_ENV` changed to `test`, do not want to change those settings back and forth in `.env` file; which I consider not good practice and not good DX for sure 😄 

Commits
-------

09c6530115 Add autoconfiguration for Symfony 4, allow overriding .env setting by using explicit env and debug settings, tweaks
141074a24e Tweak README to include new configuration details for Symfony 4, tweak variable name
149d41087f Add symfony 4 configuration loading when bootstrap is null; tweaked formatting, naming, tests and readme
49c4fc2a0e Tweak README typos
99db863175 Tweaks after CR: remove obsolete docblocks, fix code formatting to match ECS
2018-12-19 15:08:16 +01:00
2016-11-03 11:36:50 +01:00
2016-11-03 11:36:50 +01:00
2018-08-01 16:30:28 +02:00
2016-11-03 11:36:50 +01:00
2018-08-01 15:58:37 +02:00
2018-08-01 15:32:42 +02:00
2018-08-01 16:11:34 +02:00
2018-12-09 15:51:39 +01:00

Symfony Extension

Integrates Behat with Symfony (^3.4 and ^4.1).

Inspired by Behat/Symfony2Extension.

Differences

  • Built-in symfony driver uses different kernel than the one that is used in the contexts. This means you can always change it to any other driver without any issues and ensures that application behaviour will not be affected by stateful services.

Usage

  1. Install it:

    $ composer require friends-of-behat/symfony-extension --dev
    
  2. Enable and configure in your Behat configuration:

    # behat.yml
    default:
        # ...
        extensions:
            FriendsOfBehat\SymfonyExtension: ~
    
  3. Good luck & have fun!

Configuration

SymfonyExtension provides kind of autoconfiguration feature. When none explicit configuration is set, we will set for you sane default that will get you running fast.

Default Symfony 3 configuration

FriendsOfBehat\SymfonyExtension:
    kernel:
        bootstrap: 'app/autoload.php' # you may want to use var/bootstrap.php.cache instead
        path: app/AppKernel.php
        class: 'AppKernel'
        env: test
        debug: true

Default Symfony 4 configuration

FriendsOfBehat\SymfonyExtension:
    # .env.dist file will be used if .env file does not exist
    env_file: .env
    kernel:
        bootstrap: ~
        path: src/Kernel.php
        class: 'App\Kernel'
        env: test # When explicitly set, will override APP_ENV loaded from env_file file
        debug: true  # When explicitly set, will override APP_DEBUG loaded from env_file file

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.bootstrap 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.

Description
Fork of FriendsOfBehat SymfonyExtension with Symfony 8 / PHP 8.5 compatibility work
Readme MIT 564 KiB
Languages
Gherkin 62.7%
PHP 37.3%