tddwizard / magento2-fixtures

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

Home Page:http://tddwizard.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Order placing example from README does not work

tim-bezhashvyly opened this issue · comments

I'm trying to place an order using the example from https://github.com/tddwizard/magento2-fixtures#cartcheckout but getting following error:

Error : Call to a member function getId() on bool
 /path/to/vendor/tddwizard/magento2-fixtures/src/Checkout/CustomerCheckout.php:140
 /path/to/vendor/tddwizard/magento2-fixtures/src/Checkout/CustomerCheckout.php:189
 /path/to/vendor/tddwizard/magento2-fixtures/src/Checkout/CustomerCheckout.php:166
 /path/to/app/code/Aescripts/RequiredPurchase/Test/Integration/Observer/DummyTest.php:26

Here is the reproducible code minimum:

<?php

declare(strict_types=1);

namespace Vendor\Module\Test\Integration\Observer;

use PHPUnit\Framework\TestCase;
use TddWizard\Fixtures\Catalog\ProductBuilder;
use TddWizard\Fixtures\Checkout\CartBuilder;
use TddWizard\Fixtures\Checkout\CustomerCheckout;
use TddWizard\Fixtures\Customer\CustomerBuilder;
use TddWizard\Fixtures\Customer\CustomerFixture;

class DummyTest extends TestCase
{
    public function testOrderCreation(): void
    {
        $customerFixture = new CustomerFixture(CustomerBuilder::aCustomer()->build());
        $customerFixture->login();

        $checkout = CustomerCheckout::fromCart(
            CartBuilder::forCurrentSession()
                ->withSimpleProduct(ProductBuilder::aSimpleProduct()->build()->getSku())
                ->build()
        );
        $order = $checkout->placeOrder();
    }
}

The execution command is following:

/opt/homebrew/Cellar/php/8.2.4/bin/php /path/to/vendor/phpunit/phpunit/phpunit --configuration /path/to/dev/tests/integration/phpunit.xml --filter Vendor\Module\Test\Integration\Observer\DummyTest --test-suffix DummyTest.php /path/to/app/code/Aescripts/RequiredPurchase/Test/Integration/Observer --teamcity

This seems to be the minimum working example:

        $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();

Hi Tim, nice to see you here 🙂 and thanks for the report! I classified this as documentation issue to fix the README at least, but IMHO default addresses should be added automatically if withAddresses() is not used, so I'll see how to implement that

Should I open a PR?

@tim-bezhashvyly sure, I'd merge that 👍

Can confirm that, lines with addresses have to be added