tddwizard / magento2-fixtures

Fixture library for Magento 2 integration tests by @schmengler (@integer-net)
http://tddwizard.com/
MIT License
142 stars 28 forks source link

Order placing example from README does not work #87

Closed tim-bezhashvyly closed 1 year ago

tim-bezhashvyly commented 1 year ago

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

tim-bezhashvyly commented 1 year ago

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();
schmengler commented 1 year ago

Hi Tim, nice to see you here :slightly_smiling_face: 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

tim-bezhashvyly commented 1 year ago

Should I open a PR?

schmengler commented 1 year ago

@tim-bezhashvyly sure, I'd merge that :+1:

bartoszkubicki commented 1 year ago

Can confirm that, lines with addresses have to be added