Home

Awesome

AliceBundleExtension

A Behat extension to load HautelookAliceBundle fixtures.

Package version Build Status SensioLabsInsight Scrutinizer Code Quality

Installation

You can use Composer to install the bundle to your project:

composer require --dev theofidry/alice-bundle-extension

Then, in your behat config file behat.yml, register the extension and declare the context:

# behat.yml
default:
    suites:
        default:
            contexts:
                - Fidry\AliceBundleExtension\Context\Doctrine\AliceORMContext

                # or if you want to set the base path only for this context:
                - Fidry\AliceBundleExtension\Context\Doctrine\AliceORMContext:
                    basePath: %paths.base%/tests/Features/fixtures/ORM (default value)
    # ...
    extensions:
        Fidry\AliceBundleExtension\Extension:
            fixtures_base_path: ~ # default to %paths.base%/features/fixtures

You have three contexts available:

With the default fixtures basePath respectively at:

Basic usage

Assuming you have the same configuration as the Installation section, you can create the following fixture file:

# features/fixtures/ORM/dummy.yml

AppBundle\Entity\Dummy:
    dummy_{1..10}:
        name: <name()>

Then simply load your fixtures with the following step:

Given the fixtures file "dummy.yml" is loaded
Given the fixtures file "dummy.yml" is loaded with the persister "doctrine.orm.entity_manager"
Given the following fixtures files are loaded:
  | fixtures1.yml |
  | fixtures2.yml |

Loading fixture parameters

Fixture parameters can be loaded in the same way as loading fixtures. Any available step which loads fixtures, can also load parameters. You have to load your parameters before the dependend fixtures:

Given the fixtures file "parameters.yml" is loaded
And the fixtures file "dummy.yml" is loaded

Steps

For each context, you have the following steps available:

@Given the database is empty
@Then I empty the database

@Given the fixtures "fixturesFile" are loaded
@Given the fixtures file "fixturesFile" is loaded
@Given the fixtures "fixturesFile" are loaded with the persister "persister_service_id"
@Given the fixtures file "fixturesFile" is loaded with the persister "persister_service_id"
@Given the following fixtures files are loaded:
  | fixtures1.yml |
  | fixtures2.yml |
@Given the following fixtures files are loaded with the persister "persister_service_id":
  | fixtures1.yml |
  | fixtures2.yml |

Loading fixture files can be done as follows:

<table> <thead style="float: left"> <tr> <th style="display: block">Type of path</th> <th style="display: block">Fixtures file path</th> <th style="display: block">Computed fixtures file path</th> </tr> </thead> <tbody style="float: right"> <tr> <td>Relative path</td> <td>`"dummy.yml"`</td> <td>`contextBasePath/dummy.yml`, ex: `%paths.base%/tests/Features/fixtures/ORM/dummy.yml`</td> </tr> <tr> <td>@Bundle path</td> <td>`"@AppBundle/DataFixtures/ORM/dummy.yml"`</td> <td>`src/AppBundle/DataFixtures/ORM/dummy.yml` (example)</td> </tr> <tr> <td>Absolute path</td> <td>`/dummy.yml`</td> <td>unchanged</td> </tr> <tr> <td>Absolute directory path</td> <td>`/tests/Features/fixtures/ORM/`</td> <td>`/tests/Features/fixtures/ORM/*`</td> </tr> <tr> <td>@Bundle</td> <td>`@AppBundle`</td> <td>`src/AppBundle/DataFixtures/ORM/*`</td> </tr> </tobdy> </table>

Paths can also be directories.

Credits

This library is developed by Théo FIDRY.

License

license