diff --git a/UPGRADE-API-1.11.md b/UPGRADE-API-1.11.md index ac85ad361d0d..82fe1e0b9403 100644 --- a/UPGRADE-API-1.11.md +++ b/UPGRADE-API-1.11.md @@ -22,11 +22,11 @@ product_image_prefix: 'media/image' ``` -1. `Sylius\Bundle\ApiBundle\View\CartShippingMethodInterface` and `Sylius\Bundle\ApiBundle\View\CartShippingMethod` have been removed. +2. `Sylius\Bundle\ApiBundle\View\CartShippingMethodInterface` and `Sylius\Bundle\ApiBundle\View\CartShippingMethod` have been removed. -1. `Sylius\Bundle\ApiBundle\View\Factory\CartShippingMethodFactoryInterface` and `Sylius\Bundle\ApiBundle\View\Factory\CartShippingMethodFactory` have been removed. +3. `Sylius\Bundle\ApiBundle\View\Factory\CartShippingMethodFactoryInterface` and `Sylius\Bundle\ApiBundle\View\Factory\CartShippingMethodFactory` have been removed. -1. The constructor of `Sylius\Bundle\ApiBundle\DataProvider\CartShippingMethodsSubresourceDataProvider` has been changed: +4. The constructor of `Sylius\Bundle\ApiBundle\DataProvider\CartShippingMethodsSubresourceDataProvider` has been changed: ```diff public function __construct( @@ -40,7 +40,22 @@ } ``` -1. The response schema for endpoint `GET /api/v2/shop/orders/{tokenValue}/shipments/{shipments}/methods` has been changed from: +5. The constructor of `\Sylius\Bundle\ApiBundle\CommandHandler\Checkout\AddressOrderHandler` has been changed: + + ```diff + public function __construct( + OrderRepositoryInterface $orderRepository, + - CustomerRepositoryInterface $customerRepository, + - FactoryInterface $customerFactory, + ObjectManager $manager, + StateMachineFactoryInterface $stateMachineFactory, + AddressMapperInterface $addressMapper + AddressMapperInterface $addressMapper, + + CustomerProviderInterface $customerProvider + ) { + ``` + +6. The response schema for endpoint `GET /api/v2/shop/orders/{tokenValue}/shipments/{shipments}/methods` has been changed from: ``` ... @@ -68,7 +83,7 @@ ] ``` -1. Constructor of `Core/OrderProcessing/OrderTaxesProcessor.php` has been changed where new service implementing +7. Constructor of `Core/OrderProcessing/OrderTaxesProcessor.php` has been changed where new service implementing `TaxationAddressResolverInterface` will become mandatory from Sylius version 2.0: ```diff @@ -82,7 +97,7 @@ } ``` -1. Constructor of `ApiBundle/Serializer/ProductVariantNormalizer.php` has been extended with `SectionProviderInterface` +8. Constructor of `ApiBundle/Serializer/ProductVariantNormalizer.php` has been extended with `SectionProviderInterface` argument: ```diff @@ -96,7 +111,7 @@ } ``` -1. Request body of `POST` `api/v2/shop/addresses` endpoint has been changed: +9. Request body of `POST` `api/v2/shop/addresses` endpoint has been changed: ```diff { @@ -114,39 +129,39 @@ } ``` -1. The service `Sylius\Bundle\ApiBundle\Converter\ItemIriToIdentifierConverter` has changed its name to `Sylius\Bundle\ApiBundle\Converter\IriToIdentifierConverter` - and its service definition from `Sylius\Bundle\ApiBundle\Converter\ItemIriToIdentifierConverter` to `Sylius\Bundle\ApiBundle\Converter\IriToIdentifierConverterInterface` - -1. The service `Sylius\Bundle\ApiBundle\Serializer\CommandFieldItemIriToIdentifierDenormalizer` has changed its name to `Sylius\Bundle\ApiBundle\Serializer\CommandArgumentsDenormalizer` - and also its service definition. - -1. Following namespaces has been changed: - * '\Sylius\Bundle\ApiBundle\CommandHandler\AddProductReviewHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Catalog\AddProductReviewHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\BlameCartHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Cart\BlameCartHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\RequestResetPasswordTokenHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\RequestResetPasswordTokenHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\ResendVerificationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\ResendVerificationEmailHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\ResetPasswordHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\ResetPasswordHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\SendAccountRegistrationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\SendAccountRegistrationEmailHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\SendAccountVerificationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\SendAccountVerificationEmailHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\SendOrderConfirmationHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Checkout\SendOrderConfirmationHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\SendResetPasswordEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\SendResetPasswordEmailHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\SendShipmentConfirmationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Checkout\SendShipmentConfirmationEmailHandler' - * '\Sylius\Bundle\ApiBundle\CommandHandler\VerifyCustomerAccountHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\VerifyCustomerAccountHandler' - * '\Sylius\Bundle\ApiBundle\Command\AddProductReview' => '\Sylius\Bundle\ApiBundle\Command\Catalog\AddProductReview' - * '\Sylius\Bundle\ApiBundle\Command\BlameCart' => '\Sylius\Bundle\ApiBundle\Command\Cart\BlameCart' - * '\Sylius\Bundle\ApiBundle\Command\RequestResetPasswordToken' => '\Sylius\Bundle\ApiBundle\Command\Account\RequestResetPasswordToken' - * '\Sylius\Bundle\ApiBundle\Command\ResendVerificationEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\ResendVerificationEmail' - * '\Sylius\Bundle\ApiBundle\Command\ResetPassword' => '\Sylius\Bundle\ApiBundle\Command\Account\ResetPassword' - * '\Sylius\Bundle\ApiBundle\Command\SendAccountRegistrationEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\SendAccountRegistrationEmail' - * '\Sylius\Bundle\ApiBundle\Command\SendAccountVerificationEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\SendAccountVerificationEmail' - * '\Sylius\Bundle\ApiBundle\Command\SendOrderConfirmation' => '\Sylius\Bundle\ApiBundle\Command\Checkout\SendOrderConfirmation' - * '\Sylius\Bundle\ApiBundle\Command\SendResetPasswordEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\SendResetPasswordEmail' - * '\Sylius\Bundle\ApiBundle\Command\SendShipmentConfirmationEmail' => '\Sylius\Bundle\ApiBundle\Command\Checkout\SendShipmentConfirmationEmail' - * '\Sylius\Bundle\ApiBundle\Command\VerifyCustomerAccount' => '\Sylius\Bundle\ApiBundle\Command\Account\VerifyCustomerAccount' - * `\Sylius\Bundle\ApiBundle\CommandHandler\ChangeShopUserPasswordHandler` => `\Sylius\Bundle\ApiBundle\CommandHandler\Account\ChangeShopUserPasswordHandler` - * `\Sylius\Bundle\ApiBundle\CommandHandler\PickupCartHandler` => `\Sylius\Bundle\ApiBundle\CommandHandler\Cart\PickupCartHandler` - * `\Sylius\Bundle\ApiBundle\CommandHandler\RegisterShopUserHandler` => `\Sylius\Bundle\ApiBundle\CommandHandler\Account\RegisterShopUserHandler` - * `\Sylius\Bundle\ApiBundle\Command\ChangeShopUserPassword` => `\Sylius\Bundle\ApiBundle\Command\Account\ChangeShopUserPassword` - * `\Sylius\Bundle\ApiBundle\Command\RegisterShopUser` => `\Sylius\Bundle\ApiBundle\Command\Account\RegisterShopUser` - * `\Sylius\Bundle\ApiBundle\Doctrine\Filters\ExchangeRateFilter` => `\Sylius\Bundle\ApiBundle\Doctrine\Filter\ExchangeRateFilter` - * `\Sylius\Bundle\ApiBundle\Doctrine\Filters\TranslationOrderNameAndLocaleFilter` => `Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter` +10. The service `Sylius\Bundle\ApiBundle\Converter\ItemIriToIdentifierConverter` has changed its name to `Sylius\Bundle\ApiBundle\Converter\IriToIdentifierConverter` + and its service definition from `Sylius\Bundle\ApiBundle\Converter\ItemIriToIdentifierConverter` to `Sylius\Bundle\ApiBundle\Converter\IriToIdentifierConverterInterface` + +11. The service `Sylius\Bundle\ApiBundle\Serializer\CommandFieldItemIriToIdentifierDenormalizer` has changed its name to `Sylius\Bundle\ApiBundle\Serializer\CommandArgumentsDenormalizer` + and also its service definition. + +12. Following namespaces has been changed: + * '\Sylius\Bundle\ApiBundle\CommandHandler\AddProductReviewHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Catalog\AddProductReviewHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\BlameCartHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Cart\BlameCartHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\RequestResetPasswordTokenHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\RequestResetPasswordTokenHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\ResendVerificationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\ResendVerificationEmailHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\ResetPasswordHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\ResetPasswordHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\SendAccountRegistrationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\SendAccountRegistrationEmailHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\SendAccountVerificationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\SendAccountVerificationEmailHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\SendOrderConfirmationHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Checkout\SendOrderConfirmationHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\SendResetPasswordEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\SendResetPasswordEmailHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\SendShipmentConfirmationEmailHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Checkout\SendShipmentConfirmationEmailHandler' + * '\Sylius\Bundle\ApiBundle\CommandHandler\VerifyCustomerAccountHandler' => '\Sylius\Bundle\ApiBundle\CommandHandler\Account\VerifyCustomerAccountHandler' + * '\Sylius\Bundle\ApiBundle\Command\AddProductReview' => '\Sylius\Bundle\ApiBundle\Command\Catalog\AddProductReview' + * '\Sylius\Bundle\ApiBundle\Command\BlameCart' => '\Sylius\Bundle\ApiBundle\Command\Cart\BlameCart' + * '\Sylius\Bundle\ApiBundle\Command\RequestResetPasswordToken' => '\Sylius\Bundle\ApiBundle\Command\Account\RequestResetPasswordToken' + * '\Sylius\Bundle\ApiBundle\Command\ResendVerificationEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\ResendVerificationEmail' + * '\Sylius\Bundle\ApiBundle\Command\ResetPassword' => '\Sylius\Bundle\ApiBundle\Command\Account\ResetPassword' + * '\Sylius\Bundle\ApiBundle\Command\SendAccountRegistrationEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\SendAccountRegistrationEmail' + * '\Sylius\Bundle\ApiBundle\Command\SendAccountVerificationEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\SendAccountVerificationEmail' + * '\Sylius\Bundle\ApiBundle\Command\SendOrderConfirmation' => '\Sylius\Bundle\ApiBundle\Command\Checkout\SendOrderConfirmation' + * '\Sylius\Bundle\ApiBundle\Command\SendResetPasswordEmail' => '\Sylius\Bundle\ApiBundle\Command\Account\SendResetPasswordEmail' + * '\Sylius\Bundle\ApiBundle\Command\SendShipmentConfirmationEmail' => '\Sylius\Bundle\ApiBundle\Command\Checkout\SendShipmentConfirmationEmail' + * '\Sylius\Bundle\ApiBundle\Command\VerifyCustomerAccount' => '\Sylius\Bundle\ApiBundle\Command\Account\VerifyCustomerAccount' + * `\Sylius\Bundle\ApiBundle\CommandHandler\ChangeShopUserPasswordHandler` => `\Sylius\Bundle\ApiBundle\CommandHandler\Account\ChangeShopUserPasswordHandler` + * `\Sylius\Bundle\ApiBundle\CommandHandler\PickupCartHandler` => `\Sylius\Bundle\ApiBundle\CommandHandler\Cart\PickupCartHandler` + * `\Sylius\Bundle\ApiBundle\CommandHandler\RegisterShopUserHandler` => `\Sylius\Bundle\ApiBundle\CommandHandler\Account\RegisterShopUserHandler` + * `\Sylius\Bundle\ApiBundle\Command\ChangeShopUserPassword` => `\Sylius\Bundle\ApiBundle\Command\Account\ChangeShopUserPassword` + * `\Sylius\Bundle\ApiBundle\Command\RegisterShopUser` => `\Sylius\Bundle\ApiBundle\Command\Account\RegisterShopUser` + * `\Sylius\Bundle\ApiBundle\Doctrine\Filters\ExchangeRateFilter` => `\Sylius\Bundle\ApiBundle\Doctrine\Filter\ExchangeRateFilter` + * `\Sylius\Bundle\ApiBundle\Doctrine\Filters\TranslationOrderNameAndLocaleFilter` => `Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter` diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/Checkout/AddressOrderHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/Checkout/AddressOrderHandler.php index 5a16660993ef..91bf7e240d05 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/Checkout/AddressOrderHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/Checkout/AddressOrderHandler.php @@ -17,13 +17,11 @@ use SM\Factory\FactoryInterface as StateMachineFactoryInterface; use Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder; use Sylius\Bundle\ApiBundle\Mapper\AddressMapperInterface; +use Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterface; use Sylius\Component\Core\Model\AddressInterface; -use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\OrderCheckoutTransitions; -use Sylius\Component\Core\Repository\CustomerRepositoryInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; use Webmozart\Assert\Assert; @@ -33,12 +31,6 @@ final class AddressOrderHandler implements MessageHandlerInterface /** @var OrderRepositoryInterface */ private $orderRepository; - /** @var CustomerRepositoryInterface */ - private $customerRepository; - - /** @var FactoryInterface */ - private $customerFactory; - /** @var ObjectManager */ private $manager; @@ -48,20 +40,21 @@ final class AddressOrderHandler implements MessageHandlerInterface /** @var AddressMapperInterface */ private $addressMapper; + /** @var CustomerProviderInterface */ + private $customerProvider; + public function __construct( OrderRepositoryInterface $orderRepository, - CustomerRepositoryInterface $customerRepository, - FactoryInterface $customerFactory, ObjectManager $manager, StateMachineFactoryInterface $stateMachineFactory, - AddressMapperInterface $addressMapper + AddressMapperInterface $addressMapper, + CustomerProviderInterface $customerProvider ) { $this->orderRepository = $orderRepository; - $this->customerRepository = $customerRepository; - $this->customerFactory = $customerFactory; $this->manager = $manager; $this->stateMachineFactory = $stateMachineFactory; $this->addressMapper = $addressMapper; + $this->customerProvider = $customerProvider; } public function __invoke(AddressOrder $addressOrder): OrderInterface @@ -80,7 +73,9 @@ public function __invoke(AddressOrder $addressOrder): OrderInterface ); if (null === $order->getCustomer()) { - $order->setCustomer($this->provideCustomerByEmail($addressOrder->email)); + Assert::notNull($addressOrder->email, sprintf('Visitor should provide an email.')); + + $order->setCustomer($this->customerProvider->provide($addressOrder->email)); } /** @var AddressInterface|null $billingAddress */ @@ -108,19 +103,4 @@ public function __invoke(AddressOrder $addressOrder): OrderInterface return $order; } - - private function provideCustomerByEmail(?string $email): CustomerInterface - { - Assert::notNull($email, sprintf('Visitor should provide an email.')); - - $customer = $this->customerRepository->findOneBy(['email' => $email]); - if (null === $customer) { - /** @var CustomerInterface $customer */ - $customer = $this->customerFactory->createNew(); - $customer->setEmail($email); - $this->manager->persist($customer); - } - - return $customer; - } } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index 9b891747b60c..e7ee752b40ca 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -57,11 +57,10 @@ - - - + + diff --git a/src/Sylius/Bundle/ApiBundle/Tests/CommandHandler/ChangeAddressOrderHandlerTest.php b/src/Sylius/Bundle/ApiBundle/Tests/CommandHandler/ChangeAddressOrderHandlerTest.php index e46b1c57b75c..2f753f4f236a 100644 --- a/src/Sylius/Bundle/ApiBundle/Tests/CommandHandler/ChangeAddressOrderHandlerTest.php +++ b/src/Sylius/Bundle/ApiBundle/Tests/CommandHandler/ChangeAddressOrderHandlerTest.php @@ -21,10 +21,9 @@ use Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder; use Sylius\Bundle\ApiBundle\CommandHandler\Checkout\AddressOrderHandler; use Sylius\Bundle\ApiBundle\Mapper\AddressMapperInterface; +use Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterface; use Sylius\Component\Core\Model\Address; -use Sylius\Component\Core\Repository\CustomerRepositoryInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -40,15 +39,12 @@ public function it_changes_address_order_without_duplication_in_database(): void /** @var RepositoryInterface $addressRepository */ $addressRepository = $container->get('sylius.repository.address'); - /** @var CustomerRepositoryInterface $customerRepository */ - $customerRepository = $container->get('sylius.repository.customer'); + /** @var CustomerProviderInterface $customerProvider */ + $customerProvider = $container->get('Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterface'); /** @var OrderRepositoryInterface $orderRepository */ $orderRepository = $container->get('sylius.repository.order'); - /** @var FactoryInterface $customerFactory */ - $customerFactory = $container->get('sylius.factory.customer'); - /** @var ObjectManager $manager */ $manager = $container->get('doctrine.orm.default_entity_manager'); @@ -79,11 +75,10 @@ public function it_changes_address_order_without_duplication_in_database(): void $addressOrderHandler = new AddressOrderHandler( $orderRepository, - $customerRepository, - $customerFactory, $manager, $stateMachineFactory, - $addressMapper + $addressMapper, + $customerProvider ); $newBillingAddress = $address = new Address(); diff --git a/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/Checkout/AddressOrderHandlerSpec.php b/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/Checkout/AddressOrderHandlerSpec.php index 2a8e743812d2..2a42ce812fc6 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/Checkout/AddressOrderHandlerSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/Checkout/AddressOrderHandlerSpec.php @@ -20,6 +20,7 @@ use SM\StateMachine\StateMachineInterface; use Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder; use Sylius\Bundle\ApiBundle\Mapper\AddressMapperInterface; +use Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterface; use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -32,19 +33,17 @@ final class AddressOrderHandlerSpec extends ObjectBehavior { function let( OrderRepositoryInterface $orderRepository, - CustomerRepositoryInterface $customerRepository, - FactoryInterface $customerFactory, ObjectManager $manager, StateMachineFactoryInterface $stateMachineFactory, - AddressMapperInterface $addressMapper + AddressMapperInterface $addressMapper, + CustomerProviderInterface $customerProvider ): void { $this->beConstructedWith( $orderRepository, - $customerRepository, - $customerFactory, $manager, $stateMachineFactory, - $addressMapper + $addressMapper, + $customerProvider ); } @@ -79,7 +78,7 @@ function it_handles_addressing_an_order_without_provided_shipping_address( function it_handles_addressing_an_order_for_visitor( OrderRepositoryInterface $orderRepository, - FactoryInterface $customerFactory, + CustomerProviderInterface $customerProvider, ObjectManager $manager, StateMachineFactoryInterface $stateMachineFactory, CustomerInterface $customer, @@ -99,9 +98,8 @@ function it_handles_addressing_an_order_for_visitor( $order->getCustomer()->willReturn(null); - $customerFactory->createNew()->willReturn($customer); - $customer->setEmail('r2d2@droid.com')->shouldBeCalled(); - $manager->persist($customer)->shouldBeCalled(); + $customerProvider->provide('r2d2@droid.com')->willReturn($customer); + $order->setCustomer($customer)->shouldBeCalled(); $order->getShippingAddress()->willReturn(null); $order->getBillingAddress()->willReturn(null); @@ -117,9 +115,9 @@ function it_handles_addressing_an_order_for_visitor( $this($addressOrder); } - function it_handles_addressing_an_order_for_logged_in_shop_user( + function it_handles_addressing_an_order_with_the_cutomer_already_assigned( OrderRepositoryInterface $orderRepository, - FactoryInterface $customerFactory, + CustomerProviderInterface $customerProvider, ObjectManager $manager, StateMachineFactoryInterface $stateMachineFactory, CustomerInterface $customer, @@ -139,8 +137,9 @@ function it_handles_addressing_an_order_for_logged_in_shop_user( $order->getCustomer()->willReturn($customer); - $customerFactory->createNew()->shouldNotBeCalled(); - $customer->setEmail('r2d2@droid.com')->shouldNotBeCalled(); + $customerProvider->provide(Argument::any())->shouldNotBeCalled(); + $customer->setEmail(Argument::any())->shouldNotBeCalled(); + $manager->persist($customer)->shouldNotBeCalled(); $order->setCustomer($customer)->shouldNotBeCalled(); @@ -158,49 +157,9 @@ function it_handles_addressing_an_order_for_logged_in_shop_user( $this($addressOrder); } - function it_handles_addressing_an_order_for_not_logged_in_shop_user( - OrderRepositoryInterface $orderRepository, - CustomerRepositoryInterface $customerRepository, - ObjectManager $manager, - StateMachineFactoryInterface $stateMachineFactory, - CustomerInterface $customer, - AddressInterface $billingAddress, - AddressInterface $shippingAddress, - OrderInterface $order, - StateMachineInterface $stateMachine - ): void { - $addressOrder = new AddressOrder( - 'r2d2@droid.com', - $billingAddress->getWrappedObject(), - $shippingAddress->getWrappedObject() - ); - $addressOrder->setOrderTokenValue('ORDERTOKEN'); - - $orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn($order); - - $order->getCustomer()->willReturn(null); - - $customerRepository->findOneBy(['email' => 'r2d2@droid.com'])->willReturn($customer); - - $order->getCustomer()->shouldBeCalled(); - $order->setCustomer($customer)->shouldBeCalled(); - $order->getShippingAddress()->willReturn(null); - $order->getBillingAddress()->willReturn(null); - $order->setBillingAddress($billingAddress)->shouldBeCalled(); - $order->setShippingAddress($shippingAddress)->shouldBeCalled(); - - $stateMachineFactory->get($order, OrderCheckoutTransitions::GRAPH)->willReturn($stateMachine); - $stateMachine->can(OrderCheckoutTransitions::TRANSITION_ADDRESS)->willReturn(true); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled(); - - $manager->persist($order)->shouldBeCalled(); - - $this($addressOrder); - } - function it_updates_order_address_based_on_data_form_new_order_address( OrderRepositoryInterface $orderRepository, - FactoryInterface $customerFactory, + CustomerProviderInterface $customerProvider, ObjectManager $manager, StateMachineFactoryInterface $stateMachineFactory, AddressMapperInterface $addressMapper, @@ -223,9 +182,8 @@ function it_updates_order_address_based_on_data_form_new_order_address( $order->getCustomer()->willReturn(null); - $customerFactory->createNew()->willReturn($customer); - $customer->setEmail('r2d2@droid.com')->shouldBeCalled(); - $manager->persist($customer)->shouldBeCalled(); + $customerProvider->provide('r2d2@droid.com')->willReturn($customer); + $order->setCustomer($customer)->shouldBeCalled(); $order->getBillingAddress()->willReturn($oldBillingAddress); $order->getShippingAddress()->willReturn($oldShippingAddress);