2017 © Pedro PelĂĄez
 

behat-extension parameter-bag-extension

Parameter bag extension for Behat

image

codifico/parameter-bag-extension

Parameter bag extension for Behat

  • Wednesday, September 2, 2015
  • by drymek
  • Repository
  • 1 Watchers
  • 7 Stars
  • 56,438 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 1 Versions
  • 21 % Grown

The README.md

ParameterBagExtension

for Behat 3.x, (*1)

Build Status Scrutinizer Code Quality SensioLabsInsight, (*2)

Latest Stable Version Latest Unstable Version License Total Downloads, (*3)

Provides parameter bag for Behat contexts:, (*4)

  • ParameterBagAwareContext provides an parameter bag instance for contexts

Instalation

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: ~

Parameter Bag Usage

Prepare parameter:

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

Use the parameter:

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

Placeholder Bag Usage

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

Replacing placeholders

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)

Thanks

Extension is based on a solution developed by PrzemysƂaw Piechota (kibao) in gist., (*9)

Contributors

The Versions

02/09 2015

dev-master

9999999-dev http://codifico.pl

Parameter bag extension for Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd behat parameter bag codifico