2017 © Pedro Peláez
 

behat-extension alice-extension

Alice extension for Behat

image

rezzza/alice-extension

Alice extension for Behat

  • Friday, March 24, 2017
  • by steph_py
  • Repository
  • 7 Watchers
  • 29 Stars
  • 22,356 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 6 Open issues
  • 21 Versions
  • 2 % Grown

The README.md

Alice Extension for Behat

Make Alice work with Behat., (*1)

You can import fixtures through a yaml file and from a behat step., (*2)

Versions
* 1.0.x version, for Behat 3.x: Build Status * 0.1.x version, for Behat 2.5.x, (*3)

Installation

Through Composer :, (*4)

    $ composer require --dev "rezzza/alice-extension:1.0.*@dev"

Configure your behat.yml :, (*5)

default:
    extensions:
        Rezzza\AliceExtension\Extension:
            fixtures: /path/to/your/fixtures.yml
            lifetime: (scenario|feature)
            faker:
                locale: en_US #default
                providers: []

To write your fixtures.yml please report to Alice documentation, (*6)

This extension need Symfony2Extension to work. Have a look to its documentation, (*7)

Usage

In your behat configuration you can activate AliceContext for the test suite you need, (*8)

default:
    suites:
        default:
            contexts:
                - Rezzza\AliceExtension\Context\AliceContext

So you can now write in your features :, (*9)

Feature: Test My feature

    Background: Write fixtures
        Given I load "Vendor\My\Entity" fixtures where column "key" is the key:
            | key      | id | name |
            | fixture1 | 1  | jean |
            | fixture2 | 2  | marc |

If you use yaml file, you should consider put your default values in it thanks to template inheritance., (*10)

And use inline fixtures to override values you need., (*11)

Hook for specific entities

Sometimes you need to apply specific operations for objects persisted. You can do it through the Symfony2 Bundle packed with this extension., (*12)

Activate the bundle:, (*13)

<?php
/***/
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            /***/
            new Rezzza\AliceExtension\Symfony\Bundle\RezzzaAliceExtensionBundle()
            /***/
        );
    }
}
?>

Then in your Symfony2 app you will be able to build some Alice processors via service. It should extends Nelmio\Alice\ProcessorInterface and registred via the tag alice_extension.processor, (*14)

Adapters

Currently we support :, (*15)

  • DoctrineORM
  • ElasticSearch (through FOSElasticaBundle)
default:
    extensions:
        Rezzza\AliceExtension\Extension:
            adapters:
                elastica: ~
                orm: ~

For ElasticSearch we should use mapping config to indicate which ElasticSearch type alice should use to persist your mode:, (*16)

default:
    extensions:
        Rezzza\AliceExtension\Extension:
            adapters:
                elastica:
                    index_service: fos_elastica.index.name_of_your_index
                    mapping:
                        myType: My\Fully\Model
                orm: ~

Then in your features you should use tag to specify which adapters alice should use :, (*17)

@alice:elastica
Feature: Test My feature

    Background: Write fixtures
        Given I load "Vendor\My\Entity" fixtures where column "key" is the key:
            | key      | id | name |
            | fixture1 | 1  | jean |
            | fixture2 | 2  | marc |

Advanced Fixtures

Fixtures can be managed through the configuration., (*18)

default:
    extensions:
        Rezzza\AliceExtension\Extension:
            default_loading: implicit
            fixtures:
                default: [users, products] # could be scalar if you want only one => users
                key_paths:
                    users: /src/path/to/your/fixtures.yml
                    products: /src/path/to/your/fixtures.yml

With this kind of configuration, when you'll call step below, it'll load default fixtures (users and products in this example). default_loading key is important here, if it's defined as implicit, it'll implicitly load default fixtures when you use step below. If it's defined as explicit you'll have to use Given I load "default" fixtures to load default fixtures., (*19)

Given I load "Acme\Bundle\Entity\User" fixtures where column "key" is the key:
    | key                  | emailAddress     | password |
    | user1 (extends user) | chuck@norris.com | password |

You are able to load fixtures manually:, (*20)

Given I load "default" fixtures   # will load users AND products
Given I load "users" fixtures     # will load users
Given I load "products" fixtures  # will load products

Of course, fixtures are loaded once., (*21)

Faker Providers

Some providers are available on AliceExtension:, (*22)

  • NullProvider: <null>
  • FixedDateTimeProvider: <fixedDateTime("+1 hour")>

You can add them (or your own) easily in behat.yml configuration:, (*23)

default:
    extensions:
        Rezzza\AliceExtension\Extension:
            .....
            faker:
                locale: en_US #default
                providers:
                    - \Rezzza\AliceExtension\Providers\NullProvider
                    - \Rezzza\AliceExtension\Providers\FixedDateTimeProvider
                    - \Acme\Providers\YourOwnProvider

Lifetime

2 lifetime options are available., (*24)

  • scenario : will reset fixtures after each scenario. You have to use background step to describe your fixtures
  • feature : will reset fixtures after each feature. You have to use scenario step to describe your fixtures

FAQ

  • I want to use this with Doctrine ODM !
  • You should do a PR, (*25)

  • I wanto to use this with PostgreSQL !, (*26)

  • You should do a PR

The Versions

19/02 2016

dev-behat2

dev-behat2 https://github.com/rezzza/alice-extension

Alice extension for Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd symfony fixtures alice

19/02 2016