hardman-commerce/magento2-fixtures

Fixture library for Magento 2 integration tests

Installs: 15

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 31

Type:magento2-module

2.0.0 2025-08-09 12:46 UTC

This package is auto-updated.

Last update: 2025-09-10 09:38:02 UTC


README

Latest Version on Packagist Software License

Forked from Magento 2 Fixtures by Fabian Schmengler.
Updated with code from Klevu Test Fixtures.

What is it?

An alternative to the procedural script-based fixtures in Magento 2 integration tests.

It aims to be:

  • extensible
  • expressive
  • easy to use

Installation

Install it into your Magento 2 project with composer:

composer require --dev hardman-commerce/magento2-fixtures

Requirements

  • Magento 2.4.4+
  • PHP 8.1+

Documentation:

Catalog/Attribute

Fixtures and Traits to build catalog attributes, including store scope settings.
Useful when an attribute is required to create configurable products.

Catalog/Category

Fixtures and Traits to build categories, including store scope settings.

Catalog/Product

Fixtures and Traits to build products, including store scope settings.
Extended TDDWizard product fixtures to add

  • Tier Prices
  • Images

The following product types are covered

  • Simple
  • Virtual
  • Downloadable
  • Grouped
  • Configurable

Todo:

  • Bundle
  • Gift Card

Catalog/Rule

Fixtures and Traits to build catalog price rules.

Checkout

Fixtures and Traits to build Cart and perform a customer checkout.

Add the following product types to the cart:

  • Simple
  • Configurable
  • Grouped

Todo:

  • Bundle
  • Gift Card

CMS

Fixtures and Traits to build:

  • Pages

Todo:

  • Blocks
  • Widgets

Core

Fixtures to create config settings.

Customer

Fixtures and Traits to build:

  • Customer Addresses
  • Customers
  • Customer Groups

Sales

Fixtures to build:

  • Credit memos
  • Invoices
  • Orders
  • Shipments

Todo:

  • Create traits

Store

Fixtures and Traits to build:

  • Stores
  • Store Groups
  • Websites

Tax

Fixtures and Traits to build

  • Tax Classes
  • Tax Rates
  • Tax Rules

Fixture pools

To manage multiple fixtures, fixture pools have been introduced for all entities:

Usage demonstrated with the ProductFixturePool:

protected function setUp()
{
    $this->productFixtures = new ProductFixturePool;
}

protected function tearDown()
{
    $this->productFixtures->rollback();
}

public function testSomethingWithMultipleProducts()
{
    $this->productFixtures->add(ProductBuilder::aSimpleProduct()->build());
    $this->productFixtures->add(ProductBuilder::aSimpleProduct()->build(), 'foo');
    $this->productFixtures->add(ProductBuilder::aSimpleProduct()->build());

    $this->productFixtures->get();      // returns ProductFixture object for last added product
    $this->productFixtures->get('foo'); // returns ProductFixture object for product added with specific key 'foo'
    $this->productFixtures->get(0);     // returns ProductFixture object for first product added without specific key (numeric array index)
}

Credits

License

The MIT License (MIT). Please see License File for more information.