28/01/2018 - BEHAT, SYMFONY
In this example we are going to place behat feature and context files under root folder.
src
└── ....
tests
├── behaviour
│ └── CustomerBundle
│ ├── Context
│ │ └── FeatureContext.php
│ └── Feature
│ └── PrintContextParameters.feature
└── unit
└── ...
$ composer require --dev behat/behat
$ composer require --dev behat/symfony2-extension
default:
autoload:
- %paths.base%
extensions:
Behat\Symfony2Extension: ~
suites:
customer:
paths:
features: tests/behaviour/CustomerBundle/Feature
contexts:
- tests\behaviour\CustomerBundle\Context\FeatureContext:
parameters:
database_host: %%database_host%%
database_name: %%database_name%%
namespace tests\behaviour\CustomerBundle\Context;
use Behat\Behat\Context\Context;
class FeatureContext implements Context
{
private $parameters;
public function __construct(array $parameters = [])
{
$this->parameters = $parameters;
}
/**
* @Then /^the parameters are printed$/
*/
public function theParametersArePrinted()
{
print_r($this->parameters);
}
}
Feature: Printing context parameters
In order to print context parameters
As a developer
I should be able to call custom step
Scenario: Printing parameters
Given the parameters are printed
$ vendor/bin/behat --suite=customer
Feature: Printing context parameters
In order to print context parameters
As a developer
I should be able to call custom step
Scenario: Printing parameters
Given the parameters are printed
│ Array
│ (
│ [database_host] => 127.0.0.1
│ [database_name] => common
│ )
│
1 scenario (1 passed)
1 step (1 passed)
0m0.14s (11.28Mb)