dev-master
9999999-dev http://codifico.plParameter bag extension for Behat
MIT
The Requires
- behat/behat ~3.0,>=3.0.4
- php >=5.4
The Development Requires
by Marcin Dryka
bdd behat parameter bag codifico
Parameter bag extension for Behat
for Behat 3.x, (*1)
Provides parameter bag for Behat contexts:, (*4)
php composer.phar require codifico/parameter-bag-extension:dev-master --dev
Activate extension by specifying its class in your behat.yml:, (*5)
# 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, (*6)
# behat.yml default: # ... extensions: Codifico\ParameterBagExtension\ServiceContainer\ParameterBagExtension: parameter_bag: class: Codifico\ParameterBagExtension\Bag\InMemoryPlaceholderBag
Additionally to setting and getting placeholder values you can replace placeholders in strings, (*7)
<?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., (*8)
Extension is based on a solution developed by PrzemysĆaw Piechota (kibao) in gist., (*9)
Parameter bag extension for Behat
MIT
bdd behat parameter bag codifico