for Behat 3.x
Provides parameter bag for Behat contexts:
- ParameterBagAwareContext provides an parameter bag instance for contexts
php composer.phar require codifico/parameter-bag-extension:dev-master --devActivate extension by specifying its class in your behat.yml:
# behat.yml
default:
# ...
extensions:
Codifico\ParameterBagExtension\ServiceContainer\ParameterBagExtension: ~<?php
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Codifico\ParameterBagExtension\Context\ParameterBagDictionary;
class FeatureContext implements SnippetAcceptingContext
{
use ParameterBagDictionary;
/**
* @Given Entity :entityName exists:
*/
public function entityExists($entityName)
{
// ... create entity
$this->getParameterBag()->set($entityName, $entity);
}
}<?php
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Codifico\ParameterBagExtension\Context\ParameterBagDictionary;
class AnotherFeatureContext implements SnippetAcceptingContext
{
use ParameterBagDictionary;
/**
* @Then I need entity :entityName
*/
public function iNeedEntity($entityName)
{
$entity = $this->getParameterBag()->get($entityName);
}
}You can also use it as a placeholder bag. To switch to a placeholder bag just
# behat.yml
default:
# ...
extensions:
Codifico\ParameterBagExtension\ServiceContainer\ParameterBagExtension:
parameter_bag:
class: Codifico\ParameterBagExtension\Bag\InMemoryPlaceholderBagAdditionally to setting and getting placeholder values you can replace placeholders in strings
<?php
class AnotherFeatureContext implements SnippetAcceptingContext
{
use ParameterBagDictionary;
/**
* @Then I should get :message
*/
public function iShouldGet($message)
{
/*
* let's assume that
* $message = 'User USER_ID is active'
* and placeholder bag contains value 123 under key USER_ID
*/
$message = $this->getParameterBag()->replace($message)
// $message = 'User 123 is active'
}
}Copyright (c) 2014 Marcin Dryka (drymek). See LICENSE for details.
Extension is based on a solution developed by Przemysław Piechota (kibao) in gist.
- Marcin Dryka drymek [lead developer]
- Other awesome developers

