mkolecki/behat-fixtures-extension

Behat extension for loading fixtures to your context.

v0.2.2 2020-03-05 23:00 UTC

This package is auto-updated.

Last update: 2024-05-06 08:48:14 UTC


README

Build Status GitHub issues GitHub license Support PHP >= 5.3

Behat fixtures extension

Behat extension for loading and injecting fixtures to your context. It make life easier when you need test data in your features and you want to separate them from your scenarios.

Simple as:

  • install extension (composer require)
  • create your fixture files (vim fixtures/users.yml)
  • configure it (vim behat.yml)
  • add Fixtures object to your feature context constructor (__construct(Fixtures $fixtures))

Enjoy!

Installation

Use composer command to install mkolecki/behat-fixtures-extension:

composer require --dev mkolecki/behat-fixtures-extension

Usage

Create fixtures/development/users.yaml file in your project:

with-blocked-account:
  login: john
  passwotd: supersecret123

with-unpaid-invoces:
  login: max
  password: megasecret5
  
with-many-friends:
  login: adam
  password: test1234

Add extension configuration to your behat.yml file. fixtures is an array of files to load.

default:
  extensions:
    MKolecki\Behat\FixturesExtension:
      fixtures:
        users: %paths.base%/fixtures/development/users.yaml
        companies: %paths.base%/fixtures/development/companies.yaml
        admins: %paths.base%/fixtures/development/admins.yaml

Use fixtures in your feature context code:

<?php
use MKolecki\Behat\FixturesExtension\Fixtures;
use Behat\Behat\Context\Context;

class LoginContext implements Context
{
    /** @var Fixtures */
    private $fixtures;

    public function __construct(Fixtures $fixtures)
    {
        $this->fixtures = $fixtures;
    }

    /**
     * @Then I login with user :user
     */
    public function iLoginWithUser($user)
    {
        $login = $this->fixtures->get("users/$user/login");
        $password = $this->fixtures->get("users/$user/password");

        // eg. use selenium to fill login form and submit
    }

    // ...
}

In your *.feature file you can now refer to user definition:

Feature: User can login

  Scenario: I can login to my application and see home page
    When I open login page
    And I login with user "with-many-friends"
    Then I see my home page

License and Copyright

Code of this extension is published under MIT license.

Copyright: