PHPackages                             ctasca/magefix - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. ctasca/magefix

ActiveLibrary[Testing &amp; Quality](/categories/testing)

ctasca/magefix
==============

Magento Behat Fixtures Library

3.1.2(9y ago)51.6k2[1 PRs](https://github.com/ctasca/magefix/pulls)MITPHPPHP &gt;=5.3

Since Dec 19Pushed 9y ago7 watchersCompare

[ Source](https://github.com/ctasca/magefix)[ Packagist](https://packagist.org/packages/ctasca/magefix)[ RSS](/packages/ctasca-magefix/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (9)Versions (22)Used By (0)

Magefix - Magento's Behat Fixtures Library
==========================================

[](#magefix---magentos-behat-fixtures-library)

A library to facilitate the creation of Magento fixtures for BehatMage. The following fixture types are currently available:

- Category
- Customer
- Simple Product
- Configurable Product
- Bundle Product
- Grouped Product
- Sales Order type Guest
- Sales Order type Register
- Sales Order type Customer
- Api Role
- Api User
- Admin User
- OAuth Consumer

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d2049baea82a23af3bc8bc92e262296e9bc10452949d56c6979a1c56322d8ddc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6374617363612f6d6167656669782f6261646765732f7175616c6974792d73636f72652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/ctasca/magefix/?branch=develop) [![Build Status](https://camo.githubusercontent.com/910d9fa3222872db40e1d1ca42c54f198704c978123aaac3ce5da0e814673fa2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6374617363612f6d6167656669782f6261646765732f6275696c642e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/ctasca/magefix/build-status/develop)

Please follow the below steps to get started, if you encounter any issues installing please check the [Common Issues](#common-issues) section first.

Installation
------------

[](#installation)

### 1) Add Magefix to your composer.json

[](#1-add-magefix-to-your-composerjson)

Add the following to your composer.json:

```
...
 "require-dev": {
    "ctasca/magefix": "dev-develop"
 },
 ...
```

### 2) Create the FixtureLocator

[](#2-create-the-fixturelocator)

Create the FixtureLocator class in features/fixtures directory. This class has to provide a concrete implementation for the `getLocation()` method specified in `Magefix\Parser\ResourceLocator` interface.

The getLocation method should return the path to the yml fixtures files. **IMPORTANT:** Make sure to end the path with a forward slash.

Here is an example of a ResourceLocator:

```
use Magefix\Parser\ResourceLocator;

class FixturesLocator implements ResourceLocator
{
    public function getLocation()
    {
        return 'features/fixtures/yaml/';
    }
}
```

### 3) Autoload FixtureLocator and feature/fixtures

[](#3-autoload-fixturelocator-and-featurefixtures)

In your `composer.json` add the following:

```
 "autoload": {
        "psr-0": {
            "": [
                ...
                "features/fixtures"
            ],
            ...
            "FixturesLocator" : "features/fixtures/FixturesLocator"
        }
    },
```

Run `composer dump-autoload` or `composer dumpautoload` to regenerate autoload file.

**NOTE:** More than one FixtureLocator could be created. This depends mainly on a project requirements. To use different fixture locators please refer to the [Creating Fixtures](#creating-fixtures)and [Using Many Locators](#using-many-locators) sections.

Creating Fixtures
-----------------

[](#creating-fixtures)

### 1) Create fixture yml

[](#1-create-fixture-yml)

In the chosen fixture location, create a yml file containing the fixture definition. Examples of fixture's yml files can be found in project's `examples` directory.

Here is an example for a Magento simple product fixture:

```
fixture:
    model: catalog/product
    data_provider: 'Data\Providers\SimpleProduct'
    attributes:
        name: 'Simple Product Fixture'
        description: 'Long Description'
        short_description: 'Short Description'
        weight: 10
        status: 1
        visibility: 4
        price: 100.00
        tax_class_id: 0
        website_ids: '{{getWebsiteIds}}'
        attribute_set_id : '{{getDefaultAttributeSetId}}'
        category_ids: '{{getCategoryIds}}'
        type_id: '{{getTypeId}}'
        sku: '{{getSku}}'
    stock:
        stock_data:
            qty: '{{getStockQty}}'
            is_in_stock: 1
            manage_stock: 1
```

### 2) Create Fixture's Data Provider

[](#2-create-fixtures-data-provider)

Most fixture nodes in fixtures's yml file can define dynamically generated values with the syntax `{{DATA_PROVIDER_METHOD}}`. This means the value for the node will be dynamically assigned via the given Data Provider when the fixture's yml is parsed.

Simply, `Data Providers` are data-objects and should be added to the `features/fixtures` directory and provide any method specified in the fixture's yml being parsed. A `ProviderMethodNotFound` exception is thrown if specified Data Provider does not have one or more methods as part of their protocol.

It is possible to switch data provider in scope in a fixtures's yml definitions, thus allowing to re-use existing data providers. For example, when creating a Sales Order fixture, we may want to also create a product and customer fixture.

```
fixture:
    model: sales/quote
    data_provider: 'Data\Providers\SalesOrderCustomer'
    attributes:
        store_id: '{{getStoreId}}'
    quote_products:
        products:
            0:
                model: catalog/product
                data_provider: 'Data\Providers\SimpleProduct'
                attributes:
                    name: 'Simple Product Fixture'
                    description: 'Long Description'
                    short_description: 'Short Description'
                    weight: 10
                    status: 1
                    visibility: 4
                    price: 100.00
                    tax_class_id: 0
                    website_ids: '{{getWebsiteIds}}'
                    attribute_set_id : '{{getDefaultAttributeSetId}}'
                    category_ids: '{{getCategoryIds}}'
                    type_id: '{{getTypeId}}'
                    sku: '{{getSku}}'
                stock:
                    stock_data:
                        qty: 10
                        is_in_stock: 1
                        manage_stock: 1
    checkout:
        data_provider: 'Data\Providers\SalesOrderCustomer'
```

An example of a Data Provider:

```
use Mage_Catalog_Model_Product_Type;
use Mage_Catalog_Model_Product_Visibility;
use Magefix\Fixtures\Data\Provider;

class SimpleProduct implements Provider
{
    public function getWebsiteIds()
    {
        return [1];
    }

    public function getDefaultAttributeSetId()
    {
        return 4;
    }

    public function getCategoryIds()
    {
        return [5, 14];
    }

    public function getSku()
    {
        $random = substr(md5(rand()), 0, 7);

        return 'SKU-' . $random;
    }

    public function getTypeId()
    {
        return Mage_Catalog_Model_Product_Type::TYPE_SIMPLE;
    }

    public function getStockQty()
    {
        return 10;
    }

    public function getFixtureImage()
    {
        return '/vagrant/features/fixtures/images/placeholder.jpg';
    }

    public function getVisibility()
    {
        return Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH;
    }
}
```

### 3) Create Fixture in Behat's Feature class

[](#3-create-fixture-in-behats-feature-class)

To build the fixture during Behat run, edit the required Feature Context file and do the following:

#### 1) Add `use` statement and include Fixtures `Registry` and `Builder`

[](#1-add-use-statement-and-include-fixtures-registry-and-builder)

```
use Magefix\Fixtures\Registry as FixturesRegistry;
use Magefix\Fixture\Factory\Builder as FixtureBuilder;
```

#### 2) Add `use` statement for Fixtures `Registry` trait

[](#2-add-use-statement-for-fixtures-registry-trait)

```
/**
 * Default features context.
 */
class FeatureContext extends MagentoContext
{
    use FixturesRegistry;
```

#### 3) Invoke `Builder::build` operation in Behat's Feature class

[](#3-invoke-builderbuild-operation-in-behats-feature-class)

```
FixtureBuilder::build(
            FixtureBuilder::SIMPLE_PRODUCT_FIXTURE_TYPE, new FixturesLocator(), 'simple-product.yml', '@AfterFeature'
        );
```

Available Builder's fixture type constants:

- `Builder::SIMPLE_PRODUCT_FIXTURE_TYPE`
- `Builder::CUSTOMER_FIXTURE_TYPE`
- `Builder::CATEGORY_FIXTURE_TYPE`
- `Builder::CONFIGURABLE_PRODUCT_FIXTURE_TYPE`
- `Builder::BUNDLE_PRODUCT_FIXTURE_TYPE`
- `Builder::GROUPED_PRODUCT_FIXTURE_TYPE`
- `Builder::SALES_ORDER_FIXTURE_TYPE`
- `Builder::API_ROLE_FIXTURE_TYPE`
- `Builder::API_USER_FIXTURE_TYPE`
- `Builder::ADMIN_FIXTURE_TYPE`
- `Builder::OAUTH_CONSUMER_FIXTURE_TYPE`

Cleaning Fixtures
-----------------

[](#cleaning-fixtures)

After building a fixture, to delete it via a Behat hook, simply provide the hook to `Builder`'s `build` method.

**Note:** If a hook is not specified, the fixture created will not be added to `Registry` for clean up, thus it won't be deleted.

[![Image of Data Providers Directory](assets/behatrun-s.png)](assets/behatrun-s.png)[![Image of Data Providers Directory](assets/behat-run-2.png)](assets/behat-run-2.png)

### Available hooks

[](#available-hooks)

- `@BeforeSuite`
- `@AfterSuite`
- `@BeforeFeature`
- `@AfterFeature`
- `@BeforeScenario`
- `@AfterScenario`
- `@BeforeStep`
- `@AfterStep`

Plugins
-------

[](#plugins)

Plugins comes in terms of Traits. The following traits are available:

### AdminPanelSession

[](#adminpanelsession)

Provides operations to manage admin panel session keys.

- getCurrentUrlKey
- getSessionKeyForUrl(string)

### DriverCurrentUrl

[](#drivercurrenturl)

Retrieves driver's current url.

- getDriverCurrentUrl()

### DriverSession

[](#driversession)

Provides functionality to refresh driver session.

- refreshSelenium2Session()

### DriverSwitcher

[](#driverswitcher)

Provides funtionality to switch driver scope between windows and i-frames.

- switchToIFrame(string|object) Accepts either a string or a SensioLabs\\Behat\\PageObjectExtension\\PageObject\\Element object

### ElementObjectGetter

[](#elementobjectgetter)

Provides functionality to create an Element object without providing an initial selector

- getElementObject(string)

### Spinner

[](#spinner)

Provides "waiting" functionality to contexts.

- spin(lamba, wait) where lamba is a function and wait a timeout in seconds for the operation.
- spinUntilVisible(element, wait) Spin until element is visible. Default timeout is 60 seconds. Element can be either a string or a SensioLabs\\Behat\\PageObjectExtension\\PageObject\\Element object.
- spinUntilInvisible(element, wait) Spin until element is not visible. Default timeout is 60 seconds. Element can be either a string or a SensioLabs\\Behat\\PageObjectExtension\\PageObject\\Element object.
- spinAndClick(element, wait) Spin and click element. Default timeout is 60 seconds. Element can be either a string or a SensioLabs\\Behat\\PageObjectExtension\\PageObject\\Element object.
- spinAndPress(element, wait) Spin and press element. Default timeout is 60 seconds. Element can be either a string or a SensioLabs\\Behat\\PageObjectExtension\\PageObject\\Element object.
- spinAndDo(element, action) Spin and carry out specified action on an element. Element can be either a string or a SensioLabs\\Behat\\PageObjectExtension\\PageObject\\Element object and action is a string (e.g. "press"). Also accept an optional condition and timeout. Default timeout is 60 seconds.

### WindowResizer

[](#windowresizer)

Provides functionality to resize context windows

- resizeToDesktopWindow(DriverInterface)
- resizeToMobileWindow(DriverInterface)

Using Many Locators
-------------------

[](#using-many-locators)

To use many locators, simply create them and make sure they are auto-loaded with composer. After being loaded, pass the desired locator instance to `Builder`'s `build` method.

Common Issues
-------------

[](#common-issues)

As setup issues are encountered please detail with step by step fix instructions, and where possible update the project itself to provide a more permanent fix.

- **There are currently no common issues reported**

License
=======

[](#license)

Copyright (C) 2015-2016

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

17

Last Release

3556d ago

Major Versions

1.5.2 → 2.0.02016-04-13

2.3.0 → 3.0.02016-07-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/41e1dd03169744d8705425d6e70ceb934fb157c4cca4011acb69b1b2daf25e3b?d=identicon)[ctascanw1](/maintainers/ctascanw1)

---

Top Contributors

[![danielkmariam](https://avatars.githubusercontent.com/u/1897967?v=4)](https://github.com/danielkmariam "danielkmariam (2 commits)")

---

Tags

testingFixtureBDDmagentoBehat

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/ctasca-magefix/health.svg)

```
[![Health](https://phpackages.com/badges/ctasca-magefix/health.svg)](https://phpackages.com/packages/ctasca-magefix)
```

###  Alternatives

[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)[tonicforhealth/behat-parallel-scenario

Behat parallel scenario

24354.7k](/packages/tonicforhealth-behat-parallel-scenario)[magetest/manager

Magento fixture manager

1744.1k](/packages/magetest-manager)[dmarynicz/behat-parallel-extension

Parallel extension for Behat

27544.3k](/packages/dmarynicz-behat-parallel-extension)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
