PHPackages                             vendic/magento2-fixtures - 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. vendic/magento2-fixtures

ActiveMagento2-module[Testing &amp; Quality](/categories/testing)

vendic/magento2-fixtures
========================

Fixture library for Magento 2 integration tests

1.2.0(2mo ago)03.2k↓26.1%MITPHPPHP ^7.1|^8.0

Since Aug 6Pushed 2mo agoCompare

[ Source](https://github.com/Vendic/magento2-fixtures)[ Packagist](https://packagist.org/packages/vendic/magento2-fixtures)[ RSS](/packages/vendic-magento2-fixtures/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (18)Versions (42)Used By (0)

TddWizard Fixture library
=========================

[](#tddwizard-fixture-library)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1942f15f89277005391806fe1e0c5c4b37b15e920ccac8c5fb5203304c4b8f03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74646477697a6172642f6d6167656e746f322d66697874757265732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tddwizard/magento2-fixtures)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/818043142f3cf315a6e41a0d9ac3bef15c7eb228c54ab64b107a9df2ac153fac/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f74646477697a6172642f6d6167656e746f322d66697874757265732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/tddwizard/magento2-fixtures)[![Coverage Status](https://camo.githubusercontent.com/a18c865057e94a150b95944bcfeeb22a23d9dcd3c8e9fdff7b9af4b3dd199092/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f74646477697a6172642f6d6167656e746f322d66697874757265733f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tddwizard/magento2-fixtures/code-structure)[![Quality Score](https://camo.githubusercontent.com/fd51b269975532807aae814a5b635ab53e271069cefabda6a3e5c192b120c71c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f74646477697a6172642f6d6167656e746f322d66697874757265732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tddwizard/magento2-fixtures)[![Code Climate](https://camo.githubusercontent.com/24f2d45ea5cfae91c91ec5ceeef1087340b7ebd834575038fbb39765c666c473/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f74646477697a6172642f6d6167656e746f322d66697874757265733f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/tddwizard/magento2-fixtures)

---

Magento 2 Fixtures by Fabian Schmengler

🧙🏻‍♂

What is it?
-----------

[](#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
------------

[](#installation)

Install it into your Magento 2 project with composer:

```
composer require --dev tddwizard/magento2-fixtures

```

Requirements
------------

[](#requirements)

- Magento 2.3 or Magento 2.4
- PHP 7.3 or 7.4 *(7.1 and 7.2 is allowed via composer for full Magento 2.3 compatibility but not tested anymore)*

Usage examples:
---------------

[](#usage-examples)

### Customer

[](#customer)

If you need a customer without specific data, this is all:

```
protected function setUp(): void
{
  $this->customerFixture = new CustomerFixture(
    CustomerBuilder::aCustomer()->build()
  );
}
protected function tearDown(): void
{
  $this->customerFixture->rollback();
}
```

It uses default sample data and a random email address. If you need the ID or email address in the tests, the `CustomerFixture` gives you access:

```
$this->customerFixture->getId();
$this->customerFixture->getEmail();
```

You can configure the builder with attributes:

```
CustomerBuilder::aCustomer()
  ->withEmail('test@example.com')
  ->withCustomAttributes(
    [
      'my_custom_attribute' => 42
    ]
  )
  ->build()
```

You can add addresses to the customer:

```
CustomerBuilder::aCustomer()
  ->withAddresses(
    AddressBuilder::anAddress()->asDefaultBilling(),
    AddressBuilder::anAddress()->asDefaultShipping(),
    AddressBuilder::anAddress()
  )
  ->build()
```

Or just one:

```
CustomerBuilder::aCustomer()
  ->withAddresses(
    AddressBuilder::anAddress()->asDefaultBilling()->asDefaultShipping()
  )
  ->build()
```

The `CustomerFixture` also has a shortcut to create a customer session:

```
$this->customerFixture->login();
```

### Addresses

[](#addresses)

Similar to the customer builder you can also configure the address builder with custom attributes:

```
AddressBuilder::anAddress()
  ->withCountryId('DE')
  ->withCity('Aachen')
  ->withPostcode('52078')
  ->withCustomAttributes(
    [
      'my_custom_attribute' => 42
    ]
  )
  ->asDefaultShipping()
```

### Product

[](#product)

Product fixtures work similar as customer fixtures:

```
protected function setUp(): void
{
  $this->productFixture = new ProductFixture(
    ProductBuilder::aSimpleProduct()
      ->withPrice(10)
      ->withCustomAttributes(
        [
          'my_custom_attribute' => 42
        ]
      )
      ->build()
  );
}
protected function tearDown(): void
{
  $this->productFixture->rollback();
}
```

The SKU is randomly generated and can be accessed through `ProductFixture`, just as the ID:

```
$this->productFixture->getSku();
$this->productFixture->getId();
```

### Cart/Checkout

[](#cartcheckout)

To create a quote, use the `CartBuilder` together with product fixtures:

```
$cart = CartBuilder::forCurrentSession()
  ->withSimpleProduct(
    $productFixture1->getSku()
  )
  ->withSimpleProduct(
    $productFixture2->getSku(), 10 // optional qty parameter
  )
  ->build()
$quote = $cart->getQuote();
```

Checkout is supported for logged in customers. To create an order, you can simulate the checkout as follows, given a customer fixture with default shipping and billing addresses and a product fixture:

```
$customerFixture = new CustomerFixture(CustomerBuilder::aCustomer()->withAddresses(
  AddressBuilder::anAddress()->asDefaultBilling(),
  AddressBuilder::anAddress()->asDefaultShipping()
)->build());
$customerFixture->login();

$checkout = CustomerCheckout::fromCart(
  CartBuilder::forCurrentSession()
    ->withProductRequest(ProductBuilder::aVirtualProduct()->build()->getSku())
    ->build()
);

$order = $checkout->placeOrder();
```

It will try to select the default addresses and the first available shipping and payment methods.

You can also select them explicitly:

```
$order = $checkout
  ->withShippingMethodCode('freeshipping_freeshipping')
  ->withPaymentMethodCode('checkmo')
  ->withCustomerBillingAddressId($this->customerFixture->getOtherAddressId())
  ->withCustomerShippingAddressId($this->customerFixture->getOtherAddressId())
  ->placeOrder();
```

### Order

[](#order)

The `OrderBuilder` is a shortcut for checkout simulation.

```
$order = OrderBuilder::anOrder()->build();
```

Logged-in customer, products, and cart item quantities will be generated internally unless more control is desired:

```
$order = OrderBuilder::anOrder()
    ->withProducts(
        // prepare catalog product fixtures
        ProductBuilder::aSimpleProduct()->withSku('foo'),
        ProductBuilder::aSimpleProduct()->withSku('bar')
    )->withCart(
        // define cart item quantities
        CartBuilder::forCurrentSession()->withSimpleProduct('foo', 2)->withSimpleProduct('bar', 3)
    )->build();
```

### Shipment

[](#shipment)

Orders can be fully or partially shipped, optionally with tracks.

```
$order = OrderBuilder::anOrder()->build();

// ship everything
$shipment = ShipmentBuilder::forOrder($order)->build();
// ship only given order items, add tracks
$shipment = ShipmentBuilder::forOrder($order)
    ->withItem($fooItemId, $fooQtyToShip)
    ->withItem($barItemId, $barQtyToShip)
    ->withTrackingNumbers('123-FOO', '456-BAR')
    ->build();
```

### Invoice

[](#invoice)

Orders can be fully or partially invoiced.

```
$order = OrderBuilder::anOrder()->build();

// invoice everything
$invoice = InvoiceBuilder::forOrder($order)->build();
// invoice only given order items
$invoice = InvoiceBuilder::forOrder($order)
    ->withItem($fooItemId, $fooQtyToInvoice)
    ->withItem($barItemId, $barQtyToInvoice)
    ->build();
```

### Credit Memo

[](#credit-memo)

Credit memos can be created for either all or some of the items ordered. An invoice to refund will be created internally.

```
$order = OrderBuilder::anOrder()->build();

// refund everything
$creditmemo = CreditmemoBuilder::forOrder($order)->build();
// refund only given order items
$creditmemo = CreditmemoBuilder::forOrder($order)
    ->withItem($fooItemId, $fooQtyToRefund)
    ->withItem($barItemId, $barQtyToRefund)
    ->build();
```

### Fixture pools

[](#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)
}

```

### Config Fixtures

[](#config-fixtures)

With the config fixture you can set a configuration value globally, i.e. it will ensure that it is not only set in the default scope but also in all store scopes:

```
ConfigFixture::setGlobal('general/store_information/name', 'Ye Olde Wizard Shop');

```

It uses `MutableScopeConfigInterface`, so the configuration is not persisted in the database. Use `@magentoAppIsolation enabled` in your test to make sure that changes are reverted in subsequent tests.

You can also set configuration values explicitly for stores with `ConfigFixture::setForStore()`

Credits
-------

[](#credits)

- [Fabian Schmengler](https://github.com/schmengler)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.txt) for more information.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance83

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 82.4% 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 ~135 days

Recently: every ~340 days

Total

24

Last Release

87d ago

Major Versions

v0.12.1 → v1.0.02020-10-03

PHP version history (4 changes)v0.1.0PHP ^7.0

v0.1.1PHP ^7.0|^7.1

v0.11.0PHP ^7.1

v1.1.1PHP ^7.1|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/459ec352617fd5a9f46070338b99ed03828fc902eb0a361aed717576e67bd2c4?d=identicon)[TjitseE](/maintainers/TjitseE)

---

Top Contributors

[![schmengler](https://avatars.githubusercontent.com/u/367320?v=4)](https://github.com/schmengler "schmengler (182 commits)")[![lfolco](https://avatars.githubusercontent.com/u/1709329?v=4)](https://github.com/lfolco "lfolco (14 commits)")[![mam08ixo](https://avatars.githubusercontent.com/u/1771622?v=4)](https://github.com/mam08ixo "mam08ixo (8 commits)")[![artem-lytvynenko-ven](https://avatars.githubusercontent.com/u/189153674?v=4)](https://github.com/artem-lytvynenko-ven "artem-lytvynenko-ven (3 commits)")[![Tjitse-E](https://avatars.githubusercontent.com/u/14849044?v=4)](https://github.com/Tjitse-E "Tjitse-E (3 commits)")[![Zaahed](https://avatars.githubusercontent.com/u/39271781?v=4)](https://github.com/Zaahed "Zaahed (2 commits)")[![avstudnitz](https://avatars.githubusercontent.com/u/662059?v=4)](https://github.com/avstudnitz "avstudnitz (2 commits)")[![Maikel-Koek](https://avatars.githubusercontent.com/u/6301809?v=4)](https://github.com/Maikel-Koek "Maikel-Koek (2 commits)")[![Sebastian80](https://avatars.githubusercontent.com/u/6400300?v=4)](https://github.com/Sebastian80 "Sebastian80 (1 commits)")[![tim-bezhashvyly](https://avatars.githubusercontent.com/u/462687?v=4)](https://github.com/tim-bezhashvyly "tim-bezhashvyly (1 commits)")[![jvaughan](https://avatars.githubusercontent.com/u/4849?v=4)](https://github.com/jvaughan "jvaughan (1 commits)")[![Vinai](https://avatars.githubusercontent.com/u/72463?v=4)](https://github.com/Vinai "Vinai (1 commits)")[![amenk](https://avatars.githubusercontent.com/u/1087128?v=4)](https://github.com/amenk "amenk (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vendic-magento2-fixtures/health.svg)

```
[![Health](https://phpackages.com/badges/vendic-magento2-fixtures/health.svg)](https://phpackages.com/packages/vendic-magento2-fixtures)
```

###  Alternatives

[dotdigital/dotdigital-magento2-extension

Dotdigital for Magento 2

50374.2k18](/packages/dotdigital-dotdigital-magento2-extension)[tddwizard/magento2-fixtures

Fixture library for Magento 2 integration tests

146438.6k9](/packages/tddwizard-magento2-fixtures)[mollie/magento2

Mollie Payment Module for Magento 2

1121.6M10](/packages/mollie-magento2)[swissup/module-search-mysql-legacy

Legacy mysql search for magento 2.4

10483.0k](/packages/swissup-module-search-mysql-legacy)[pagbank/payment-magento

PagBank - Payment for Magento and Adobe

2128.3k7](/packages/pagbank-payment-magento)[buckaroo/magento2

Buckaroo Magento 2 extension

32404.0k6](/packages/buckaroo-magento2)

PHPackages © 2026

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