All Projects → tddwizard → Magento2 Fixtures

tddwizard / Magento2 Fixtures

Licence: mit
Fixture library for Magento 2 integration tests by @schmengler (@integer-net)

Projects that are alternatives of or similar to Magento2 Fixtures

Magento 2 Seo
Magento 2 SEO extension will do perfectly for your better SEO. This is a bundle of outstanding features that are auto-active when you install it from Mageplaza without any code modifications. It is also friendly with your store if you need to insert meta keywords and meta descriptions for your product.
Stars: ✭ 99 (-10%)
Mutual labels:  magento, magento2
Module Rocketjavascript
Stars: ✭ 37 (-66.36%)
Mutual labels:  magento, magento2
Magento2 Form Field Manager
Customer and Address Form Fields Manager for Magento2
Stars: ✭ 21 (-80.91%)
Mutual labels:  magento, magento2
Firegento Magesetup2
MageSetup for Magento2
Stars: ✭ 107 (-2.73%)
Mutual labels:  magento, magento2
Vue Storefront
The open-source frontend for any eCommerce. Built with a PWA and headless approach, using a modern JS stack. We have custom integrations with Magento, commercetools, Shopware and Shopify and total coverage is just a matter of time. The API approach also allows you to merge VSF with any third-party tool like CMS, payment gateways or analytics. Ne…
Stars: ✭ 9,111 (+8182.73%)
Mutual labels:  magento, magento2
Magentoextensions
Magento Extension Directory 1> Themes Switcher 2> Default Shipping On Cart 3> Upshare 4> Product Image Optimizer 5> Idealo Product Export 6> magento Google shopping Api v2 7>Google feed and facebook feed 8> Pdf upload in magento media wysiwyg 9> Product Image optimizer. If You want magento 2 extensions 1>Advance Layred Navigation(including SEO URL, Rating as filter, slider filter, Ajax Filtering), 2>Attribute Pages with SEO and Custom URL key(you can do all kind of seo on those pages with logos) 3>Improved Sorting (Enable users to view products by options as 'Best Sellers', 'Top Rated', 'Most Viewed' etc.) 4>Custom Stock Status(Add statuses to products automatically or manually, Create multiple custom stock statuses, Upload special icons for stock statuses) 5>Product Labels(Using this extension you can add any label to your produts on product page or category page) 6>Custom Order Number(Using this extension you can customize order, invoice, shippment, credit memo Number) 7>All type of file upload in Wysiwyg(pdf, zip, doc etc file upload in wysiwyg), 8>Infinite Scroll, 9>Multiple FlatRate Shipping, 10>Open Api,Google api for currency Rates, 11>Product Attribute's Description, 12>Store and Currency switcher according to Ip address Please Contact me and All those extensions are paid with installation and configuration are free support.
Stars: ✭ 106 (-3.64%)
Mutual labels:  magento, magento2
Magento2 Varnish Redis Ssl Docker Compose
Deploy Magento2 with Varnish Cache and Redis with SSL termination using Docker-compose tool
Stars: ✭ 37 (-66.36%)
Mutual labels:  magento, magento2
Elasticsuite
Smile ElasticSuite - Magento 2 merchandising and search engine built on ElasticSearch
Stars: ✭ 647 (+488.18%)
Mutual labels:  magento, magento2
Docker Magento
Mark Shust's Docker Configuration for Magento
Stars: ✭ 1,123 (+920.91%)
Mutual labels:  magento, magento2
Magento2 Faq
This module adds an easy way to use FAQ Section to your Magento store with jQuery Accordion. In this module, admin can add and update FAQ. Admin can also create FAQ group with group icon.
Stars: ✭ 43 (-60.91%)
Mutual labels:  magento, magento2
Generator Mage2
Yeoman generator for Magento 2 extensions (modules and themes)
Stars: ✭ 12 (-89.09%)
Mutual labels:  magento, magento2
Magento2 Custom Shipping Rate
Create your own Custom Shipping rates for admin order or a predefined sets of shipping methods for frontend customers.
Stars: ✭ 76 (-30.91%)
Mutual labels:  magento, magento2
Magento2 Module Pagebuildersourcecode
The Page Builder Source Code module adds a Source Code button to the toolbar of the Page Builder WYSIWYG editor.
Stars: ✭ 24 (-78.18%)
Mutual labels:  magento, magento2
Magento2
All Submissions you make to Magento Inc. ("Magento") through GitHub are subject to the following terms and conditions: (1) You grant Magento a perpetual, worldwide, non-exclusive, no charge, royalty free, irrevocable license under your applicable copyrights and patents to reproduce, prepare derivative works of, display, publically perform, subli…
Stars: ✭ 9,816 (+8823.64%)
Mutual labels:  magento, magento2
Ddev
DDEV-Local: a local PHP development environment system
Stars: ✭ 915 (+731.82%)
Mutual labels:  magento, magento2
Magento2 Easy Template Path Hints
Magento 2 Easy Template Path Hints
Stars: ✭ 36 (-67.27%)
Mutual labels:  magento, magento2
Magento2 Frontools
Set of front-end tools for Magento 2 based on Gulp.js
Stars: ✭ 416 (+278.18%)
Mutual labels:  magento, magento2
Magento Nginx Config
Default Nginx config for Magento
Stars: ✭ 462 (+320%)
Mutual labels:  magento, magento2
M2 Opcache Monitor
Monitor PHP OpCache from the Admin
Stars: ✭ 38 (-65.45%)
Mutual labels:  magento, magento2
Magento2 Import Export Sample Files
Default Magento 2 CE import / export CSV files & sample files for Firebear Improved Import / Export extension
Stars: ✭ 68 (-38.18%)
Mutual labels:  magento, magento2

TddWizard Fixture library

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Code Climate


Magento 2 Fixtures by Fabian Schmengler

🧙🏻‍♂ https://tddwizard.com/

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 tddwizard/magento2-fixtures

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:

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('[email protected]')
  ->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

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 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

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:

$this->customerFixture->login();
$checkout = CustomerCheckout::fromCart(
  CartBuilder::forCurrentSession()
    ->withSimpleProduct(
      $productFixture->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

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

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

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 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

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

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

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].