Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

In this example we are going to place behat feature and context files under root folder.


Structure


src
└── ....

tests
├── behaviour
│   └── CustomerBundle
│   ├── Context
│   │   └── FeatureContext.php
│   └── Feature
│   └── PrintContextParameters.feature
└── unit
└── ...

Install behat packages


$ composer require --dev behat/behat

$ composer require --dev behat/symfony2-extension

behat.yml


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%%

FeatureContext


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);
}
}

PrintContextParameters.feature


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

Test


$ 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)