|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace spec\Sylius\PayPalPlugin\Processor; |
| 6 | + |
| 7 | +use Doctrine\Persistence\ObjectManager; |
| 8 | +use PhpSpec\ObjectBehavior; |
| 9 | +use Sylius\Component\Core\Model\AddressInterface; |
| 10 | +use Sylius\Component\Core\Model\OrderInterface; |
| 11 | +use Sylius\PayPalPlugin\Processor\PayPalAddressProcessorInterface; |
| 12 | + |
| 13 | +final class PayPalAddressProcessorSpec extends ObjectBehavior |
| 14 | +{ |
| 15 | + function let(ObjectManager $objectManager): void |
| 16 | + { |
| 17 | + $this->beConstructedWith($objectManager); |
| 18 | + } |
| 19 | + |
| 20 | + function it_implements_pay_pal_address_processor_interface(): void |
| 21 | + { |
| 22 | + $this->shouldImplement(PayPalAddressProcessorInterface::class); |
| 23 | + } |
| 24 | + |
| 25 | + function it_updates_order_address( |
| 26 | + OrderInterface $order, |
| 27 | + AddressInterface $orderAddress, |
| 28 | + ObjectManager $objectManager |
| 29 | + ): void { |
| 30 | + $order->getShippingAddress()->willReturn($orderAddress); |
| 31 | + |
| 32 | + $orderAddress->setCity('New York')->shouldBeCalled(); |
| 33 | + $orderAddress->setStreet('Main St. 123')->shouldBeCalled(); |
| 34 | + $orderAddress->setPostcode('10001')->shouldBeCalled(); |
| 35 | + $orderAddress->setCountryCode('US')->shouldBeCalled(); |
| 36 | + |
| 37 | + $objectManager->flush()->shouldBeCalled(); |
| 38 | + |
| 39 | + $this->process( |
| 40 | + [ |
| 41 | + 'address_line_1' => 'Main St. 123', |
| 42 | + 'admin_area_2' => 'New York', |
| 43 | + 'postal_code' => '10001', |
| 44 | + 'country_code' => 'US', |
| 45 | + ], |
| 46 | + $order |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + function it_updates_order_address_with_two_address_lines( |
| 51 | + OrderInterface $order, |
| 52 | + AddressInterface $orderAddress, |
| 53 | + ObjectManager $objectManager |
| 54 | + ): void { |
| 55 | + $order->getShippingAddress()->willReturn($orderAddress); |
| 56 | + |
| 57 | + $orderAddress->setCity('New York')->shouldBeCalled(); |
| 58 | + $orderAddress->setStreet('Main St. 123')->shouldBeCalled(); |
| 59 | + $orderAddress->setPostcode('10001')->shouldBeCalled(); |
| 60 | + $orderAddress->setCountryCode('US')->shouldBeCalled(); |
| 61 | + |
| 62 | + $objectManager->flush()->shouldBeCalled(); |
| 63 | + |
| 64 | + $this->process( |
| 65 | + [ |
| 66 | + 'address_line_1' => 'Main St.', |
| 67 | + 'address_line_2' => '123', |
| 68 | + 'admin_area_2' => 'New York', |
| 69 | + 'postal_code' => '10001', |
| 70 | + 'country_code' => 'US', |
| 71 | + ], |
| 72 | + $order |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + function it_throws_an_exception_if_address_data_is_missing( |
| 77 | + OrderInterface $order, |
| 78 | + AddressInterface $orderAddress, |
| 79 | + ObjectManager $objectManager |
| 80 | + ): void { |
| 81 | + $order->getShippingAddress()->willReturn($orderAddress); |
| 82 | + |
| 83 | + $objectManager->flush()->shouldNotBeCalled(); |
| 84 | + $this->shouldThrow(\InvalidArgumentException::class)->during('process', [[], $order]); |
| 85 | + } |
| 86 | +} |
0 commit comments