Improve documentation

This commit is contained in:
Kamil Kokot
2020-04-04 19:13:09 +02:00
parent b7d6ba270f
commit b44c88cbc2
5 changed files with 52 additions and 15 deletions

View File

@@ -3,7 +3,7 @@
If you're starting a new project, we recommend to use Symfony 4 with Flex as it's the most straightforward way.
If you're adding this extension to an existing project, pick the method that fits it the best.
### Symfony 4 (with Flex)
### Symfony 4/5 (with Flex)
1. Require this extension using *Composer* and allow for using contrib recipes:
@@ -11,7 +11,7 @@ If you're adding this extension to an existing project, pick the method that fit
composer require --dev friends-of-behat/symfony-extension:^2.0
```
### Symfony 4 (new directory structure, without Flex)
### Symfony 4/5 (new directory structure, without Flex)
1. Require this extension using *Composer*:
@@ -22,7 +22,7 @@ composer require --dev friends-of-behat/symfony-extension:^2.0
2. Enable it within your Behat configuration:
```yaml
# behat.yml.dist / behat.yml
# behat.yaml.dist / behat.yaml
default:
extensions:

View File

@@ -4,6 +4,8 @@ This tutorial assumes you're using the new directory structure with autowiring a
Let's first create a sample feature file (which is quite useless for demo purposes):
```gherkin
# features/using_symfony_extension.feature
Feature: Using SymfonyExtension
Scenario: Checking the application's kernel environment
@@ -39,7 +41,7 @@ final class DemoContext implements Context
And also a suite defined in Behat configuration:
```yaml
# behat.yml.dist / behat.yml
# behat.yaml.dist / behat.yaml
default:
suites:
@@ -89,7 +91,7 @@ If you're using autowiring and autoconfiguration, that's all you need! After run
If you're not, you need to register your context as a public service and define its dependencies:
```yaml
# config/services_test.yaml (Symfony 4)
# config/services_test.yaml (Symfony 4/5)
# app/config/config_test.yml (Symfony 3)
services:
@@ -135,7 +137,7 @@ If you're using autowiring and autoconfiguration, that's all you need! After run
If you're not, you need to register your context as a public service and define its dependencies:
```yaml
# config/services_test.yaml (Symfony 4)
# config/services_test.yaml (Symfony 4/5)
# app/config/config_test.yml (Symfony 3)
services:

View File

@@ -1,11 +1,11 @@
## Mink integration
*SymfonyExtension* provides an integration with [Mink](https://github.com/minkphp/Mink) and defines a dedicated,
_SymfonyExtension_ provides an integration with [Mink](https://github.com/minkphp/Mink) and defines a dedicated,
isolated driver to use for Symfony application testing.
### Installation
1. Require the packages needed for the driver using *Composer*:
1. Require the packages needed for the driver using _Composer_:
```bash
composer require --dev friends-of-behat/mink friends-of-behat/mink-extension friends-of-behat/mink-browserkit-driver
@@ -16,7 +16,7 @@ _Those `friends-of-behat` packages are forks of the original ones, adding suppor
2. Enable the bundled driver:
```yaml
# behat.yml.dist / behat.yml
# behat.yaml.dist / behat.yaml
default:
extensions:
@@ -29,6 +29,41 @@ default:
### Usage
In order to use Mink, pass the Session to the constructor and call methods on it in the context.
```php
use Behat\Behat\Context\Context;
use Behat\Mink\Session;
use Symfony\Component\Routing\RouterInterface;
final class DemoContext implements Context
{
/** @var Session */
private $session;
/** @var RouterInterface */
private $router;
public function __construct(Session $session, RouterInterface $router)
{
$this->session = $session;
$this->router = $router;
}
/**
* @Then I visit some page
*/
public function visitSomePage(): void
{
$this->session->visit($this->router->generate('some_route'));
}
}
```
_Calling any method on Mink-related services in the constructor is not permitted and will cause errors._
### Shared services
This integration provides the following services to use inside Symfony container:
* **`behat.mink`** (autowired by `\Behat\Mink\Mink`) - the Mink service

View File

@@ -2,12 +2,12 @@
### Contexts as services
In *Behat/Symfony2Extension* the dependencies of a context are defined in the Behat configuration file. In this extension,
In _Behat/Symfony2Extension_ the dependencies of a context are defined in the Behat configuration file. In this extension,
contexts are defined as services - this makes reusing suites effortless, also allowing to support autowiring and autoconfiguration.
### Isolated driver
The Mink driver provided with this extension differs from the one provided with *Behat/Symfony2Extension*,
The Mink driver provided with this extension differs from the one provided with _Behat/Symfony2Extension_,
as it uses an isolated application kernel instance, so that services state changes within your contexts does not affect
the driver results. With that limitation, changing the driver to a different one is seamless. For more information, look
at [this issue](https://github.com/Behat/Symfony2Extension/issues/112).

View File

@@ -1,10 +1,10 @@
## Configuration reference
By default, if no confguration is passed, *SymfonyExtension* will try its best to guess it.
By default, if no confguration is passed, _SymfonyExtension_ will try its best to guess it.
The full configuration tree looks like that:
```yaml
# behat.yml.dist / behat.yml
# behat.yaml.dist / behat.yaml
default:
extensions:
@@ -21,13 +21,13 @@ default:
It is a path to the file requried once while the extension is loaded. You can use this file to set up your testing
environment - set some enviornment variables or preload an external file.
If you do not pass any, it would look for either `config/bootstrap.php` (Symfony 4) or `app/autoload.php` (Symfony 3).
If you do not pass any, it would look for either `config/bootstrap.php` (Symfony 4/5) or `app/autoload.php` (Symfony 3).
If none are found, no file would be loaded.
* **`kernel.class`**:
It is a fully qualified class name of the application kernel class.
If you do not pass any, it would look for either `App\Kernel` (Symfony 4) or `AppKernel` (Symfony 3).
If you do not pass any, it would look for either `App\Kernel` (Symfony 4/5) or `AppKernel` (Symfony 3).
If none are found, an exception would be thrown and you would be required to specify it explicitly.
* **`kernel.path`**: