GithubHelp home page GithubHelp logo

alice-extension's Introduction

Alice Extension for Behat

Make Alice work with Behat.

You can import fixtures through a yaml file and from a behat step.

Versions

  • 1.0.x version, for Behat 3.x: Build Status
  • 0.1.x version, for Behat 2.5.x

Installation

Through Composer :

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

Configure your behat.yml :

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

This extension need Symfony2Extension to work. Have a look to its documentation

Usage

In your behat configuration you can activate AliceContext for the test suite you need

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

So you can now write in your features :

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.

And use inline fixtures to override values you need.

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.

Activate the bundle:

<?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

Adapters

Currently we support :

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

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 :

@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.

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.

Given I load "Acme\Bundle\Entity\User" fixtures where column "key" is the key:
    | key                  | emailAddress     | password |
    | user1 (extends user) | [email protected] | password |

You are able to load fixtures manually:

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.

Faker Providers

Some providers are available on AliceExtension:

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

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

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.

  • 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

  • I wanto to use this with PostgreSQL !

  • You should do a PR

alice-extension's People

Contributors

abuadella avatar armandabric avatar h4cc avatar shouze avatar stephpy avatar tyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

alice-extension's Issues

Improve Loading Model class with only construct

Currently, when you have a model you want to load, if it has only the constructor to set the value, it seems quiete obscure to know which properties are setted :

class MyModel 
{
    private $foo;

    private $bar;

    public function __construct($foo, $bar)
    {
         $this->foo = $foo;
         $this->bar = $bar;
   }
}
Given I load "My\Model (local)" fixtures where column "key" is the key:
    | key | __construct |
    | a1  | ["foo", "bar]  |

We should be able to "desactive" the construct and set the properties with column or any other way to achieve this result:

Given I load "My\Model (local)" fixtures where column "key" is the key:
    | key | foo   | bar    |
    | a1  | "foo" | "bar" |

Need to have a closer look in alice

Missing License

Hey there!

I really like your library, but I'm afraid, I can't use it in my project since it misses a license.
Could you please provide one?

Thank you very much!

Absolute path in "fixtures" config key.

The configuration key fixtures do not allow us to use an absolute path.

exemple:

default:
    extensions:
        ...
        Rezzza\AliceExtension\Extension:
            fixtures: /toto/Context/fixture/hotel.yml

This config give this error:

PHP Warning:  include(/Users/armandabric/workspace/beespy.vlr.dev/app/../yoto/Context/fixture/hotel.yml): failed to open stream: No such file or directory in /Users/armandabric/workspace/beespy.vlr.dev/vendor/rezzza/alice-extension/src/Rezzza/AliceExtension/Alice/YamlFixtures.php on line 39
PHP Warning:  include(): Failed opening '/Users/armandabric/workspace/beespy.vlr.dev/app/../yoto/Context/fixture/hotel.yml' for inclusion (include_path='.:/Users/armandabric/.phpbrew/php/php-5.5.10/lib/php') in /Users/armandabric/workspace/beespy.vlr.dev/vendor/rezzza/alice-extension/src/Rezzza/AliceExtension/Alice/YamlFixtures.php on line 39

It's seem all path are prefixed by the current application path.

Looking for maintainer

Hello !

We no longer use alice-extension. If some people want to get it back, please let me know. Otherwise we will deprecated it.

Thanks

Allow stable datafixture bundle

Hello,

I want to use your bundle with hautelook/alice-bundle.

dependency doctrine/data-fixtures is at ^1.2 but yours is at 2.0.*@dev.

"doctrine/data-fixtures": "2.0.*@dev"

Errors are like

  1. Without minimal stability at "dev":
rezzza/alice-extension v3.0.0 requires doctrine/data-fixtures 2.0.*@dev -> satisfiable by doctrine/data-fixtures[2.0.x-dev] but these conflict with your requirements or minimum-stability
  1. With minimal stability "dev" at and and prefer stable at true :
- rezzza/alice-extension v3.0.0 requires doctrine/data-fixtures 2.0.*@dev -> satisfiable by doctrine/data-fixtures[2.0.x-dev].
    - Installation request for rezzza/alice-extension ^3.0 -> satisfiable by rezzza/alice-extension[v3.0.0].
    - Installation request for doctrine/data-fixtures (locked at v1.2.2) -> satisfiable by doctrine/data-fixtures[v1.2.2].

So I think it could be nice to change it to for enable stable (dev || stable like 2.0.*@dev || ^1.2).

See @#49

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.