Bu örneğimizde behat feature ve context dosyalarını ana klasörün altındaki farklı bir klasörde barındıracağız.


Yapı


src
└── ....

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

Behat paketlerinin kurulumu


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