Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saeven/circlical-behat-fixtures
Simpler Behat Fixtures for Doctrine & Zend Framework, using Nelmio
https://github.com/saeven/circlical-behat-fixtures
Last synced: 25 days ago
JSON representation
Simpler Behat Fixtures for Doctrine & Zend Framework, using Nelmio
- Host: GitHub
- URL: https://github.com/saeven/circlical-behat-fixtures
- Owner: Saeven
- License: mpl-2.0
- Created: 2020-02-28T21:34:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-17T04:37:14.000Z (almost 3 years ago)
- Last Synced: 2024-09-14T07:52:59.593Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Simpler Behat Fixtures for Doctrine & Laminas
Trigger fixture loading from within Behat tests, like so:
```
Feature: I can define fixtures from within my tests
In order to keep my test database clean
As a developer writing behat tests
I want to load fixtures directly from within my test contextScenario: Test loading a new fixture
Given fixture "Application/user" is loaded
And fixture "Application/user" is loaded
And fixtures "Application/user, Billing/invoices" are loaded
```> This package adds a behavior to alice, by way of automatically falling back onto reflection
> when a setter for a fixture-defined value is not available, and that value is nontrivial.Highlights:
- fixtures provided by the excellent [nelmio/alice](https://github.com/nelmio/alice)
- comes with a ready-to-go context you can plug into Behat
- define what fixtures are required right at the Scenario level
- adds a convenient CLI command as well> Inspired by [dkorsak/doctrine-data-fixture-module](https://github.com/dkorsak/doctrine-data-fixture-module) -- thanks!
## Installation
- Composer install, then add `CirclicalBehatFixtures` to your application.config.php
## Wiring it into Behat
- Edit your behat.yml, to add the `CirclicalBehatFixtures\Behat\DatabaseContext` context
e.g.
```
# behat.yml
default:
autoload: [ '%paths.base%/../contexts' ]
suites:
core_features:
paths: [ '%paths.base%/../features' ]
contexts:
- FeatureContext
- CirclicalBehatFixtures\Behat\DatabaseContext
```### Or, if you need to override the location of the Doctrine bin (where the symlink points to)
```
# behat.yml
default:
autoload: [ '%paths.base%/../contexts' ]
suites:
core_features:
paths: [ '%paths.base%/../features' ]
contexts:
- FeatureContext
- CirclicalBehatFixtures\Behat\DatabaseContext:
- vendor/doctrine/doctrine-module/bin/doctrine-module
```## Author a Fixture
The syntax for fixture identification is very simple, MODULE/fixturename. Examples:
- Application/user
- Application/roles
- Member/purchasesIn your individual ZF modules, you will save your [nelmio/alice](https://github.com/nelmio/alice) fixtures as `module/MODULE/user.yml`. Examples based on fixture IDs above:
- module/Application/fixtures/user.yml
- module/Application/fixtures/roles.yml
- module/Member/fixtures/purchases.yml## Author a Scenario
Do this the way you usually would. The context provided by this module gives you a new action:
`Given Fixture "FIXTUREID" is loaded`
e.g.
`Given Fixture "Application/user" is loaded`
You can stack these as you need. The first one in a feature will auto-purge, the subsequent ones will append.
## Container Support
If you need to import the fixture in a Docker command for example, perhaps as a part of a CI/CD chain, you'll need to change where the fixture gets loaded. In short, instead of this command:
vendor/bin/doctrine-module orm:fixtures:load --fixtures=Application/orders
You might need to run something like this command:
/usr/local/bin/docker container exec -w /code -i $(docker-compose ps -q php) php vendor/bin/doctrine-module orm:fixtures:load --fixtures=Application/orders
You can achieve this by outputting a prefix into a file with name `circlical-fixtures-cmd-prefix`, e.g. in your CI/CD scripts:
echo "/usr/local/bin/docker container exec -w /code -i $(docker-compose ps -q php) " > ./circlical-fixtures-cmd-prefix
It becomes your responsibility to create (at startup) and delete (at tear-down) this file in your CI chain configuration.