diff --git a/UPGRADE.md b/UPGRADE.md index d989f93b..b1136db3 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -26,6 +26,9 @@ 1. Constructor of `Sylius\RefundPlugin\Entity\CustomerBillingData` has been removed and now `CustomerBillingData` entity is created by `Sylius\RefundPlugin\Factory\CustomerBillingDataFactory`. +1. Constructor of `Sylius\RefundPlugin\Entity\ShopBillingData` has been removed and now `ShopBillingData` entity + is created by `Sylius\RefundPlugin\Factory\ShopBillingDataFactory`. + 1. The constructor of `Sylius\RefundPlugin\Generator\CreditMemoGenerator` has been changed: ```diff @@ -34,7 +37,8 @@ LineItemsConverterInterface $shipmentLineItemsConverter, TaxItemsGeneratorInterface $taxItemsGenerator, CreditMemoFactoryInterface $creditMemoFactory, - + CustomerBillingDataFactoryInterface $customerBillingDataFactory + + CustomerBillingDataFactoryInterface $customerBillingDataFactory, + + ShopBillingDataFactoryInterface $shopBillingDataFactory ) { ... } diff --git a/spec/Entity/ShopBillingDataSpec.php b/spec/Entity/ShopBillingDataSpec.php index 75574c82..90cad56c 100644 --- a/spec/Entity/ShopBillingDataSpec.php +++ b/spec/Entity/ShopBillingDataSpec.php @@ -18,11 +18,6 @@ final class ShopBillingDataSpec extends ObjectBehavior { - public function let(): void - { - $this->beConstructedWith('Needful Things', '000222', 'US', 'Main St. 123', 'Los Angeles', '90001'); - } - public function it_implements_shop_billing_data_interface(): void { $this->shouldImplement(ShopBillingDataInterface::class); @@ -30,36 +25,42 @@ public function it_implements_shop_billing_data_interface(): void public function it_has_no_id_by_default(): void { - $this->id()->shouldReturn(null); + $this->getId()->shouldReturn(null); } - public function it_has_company(): void + public function it_has_a_company(): void { - $this->company()->shouldReturn('Needful Things'); + $this->setCompany('Needful Things'); + $this->getCompany()->shouldReturn('Needful Things'); } - public function it_has_tax_id(): void + public function it_has_a_tax_id(): void { - $this->taxId()->shouldReturn('000222'); + $this->setTaxId('000222'); + $this->getTaxId()->shouldReturn('000222'); } - public function it_has_country_code(): void + public function it_has_a_country_code(): void { - $this->countryCode()->shouldReturn('US'); + $this->setCountryCode('US'); + $this->getCountryCode()->shouldReturn('US'); } - public function it_has_street(): void + public function it_has_a_street(): void { - $this->street()->shouldReturn('Main St. 123'); + $this->setStreet('Main St. 123'); + $this->getStreet()->shouldReturn('Main St. 123'); } - public function it_has_city(): void + public function it_has_a_city(): void { - $this->city()->shouldReturn('Los Angeles'); + $this->setCity('Los Angeles'); + $this->getCity()->shouldReturn('Los Angeles'); } - public function it_has_postcode(): void + public function it_has_a_postcode(): void { - $this->postcode()->shouldReturn('90001'); + $this->setPostcode('90001'); + $this->getPostcode()->shouldReturn('90001'); } } diff --git a/spec/Factory/ShopBillingDataFactorySpec.php b/spec/Factory/ShopBillingDataFactorySpec.php new file mode 100644 index 00000000..5f7965ab --- /dev/null +++ b/spec/Factory/ShopBillingDataFactorySpec.php @@ -0,0 +1,60 @@ +beConstructedWith($shopBillingDataFactory); + } + + public function it_implements_shop_billing_data_factory_interface(): void + { + $this->shouldImplement(ShopBillingDataFactoryInterface::class); + } + + public function it_creates_new_shop_billing_data( + FactoryInterface $shopBillingDataFactory, + ShopBillingDataInterface $shopBillingData + ): void { + $shopBillingDataFactory->createNew()->willReturn($shopBillingData); + + $this->createNew()->shouldReturn($shopBillingData); + } + + public function it_creates_new_shop_billing_data_with_data( + ShopBillingDataInterface $shopBillingData, + FactoryInterface $shopBillingDataFactory + ): void { + $shopBillingDataFactory->createNew()->willReturn($shopBillingData); + + $shopBillingData->setCompany('Needful Things'); + $shopBillingData->setTaxId('000222'); + $shopBillingData->setCountryCode('US'); + $shopBillingData->setStreet('Main St. 123'); + $shopBillingData->setCity('Los Angeles'); + $shopBillingData->setPostcode('90001'); + + $this + ->createWithData('Needful Things', '000222', 'US', 'Main St. 123', 'Los Angeles', '90001') + ->shouldBeLike($shopBillingData) + ; + } +} diff --git a/spec/Generator/CreditMemoGeneratorSpec.php b/spec/Generator/CreditMemoGeneratorSpec.php index 714d6055..92d3083c 100644 --- a/spec/Generator/CreditMemoGeneratorSpec.php +++ b/spec/Generator/CreditMemoGeneratorSpec.php @@ -26,6 +26,7 @@ use Sylius\RefundPlugin\Entity\TaxItemInterface; use Sylius\RefundPlugin\Factory\CreditMemoFactoryInterface; use Sylius\RefundPlugin\Factory\CustomerBillingDataFactoryInterface; +use Sylius\RefundPlugin\Factory\ShopBillingDataFactoryInterface; use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface; use Sylius\RefundPlugin\Generator\TaxItemsGeneratorInterface; use Sylius\RefundPlugin\Model\OrderItemUnitRefund; @@ -38,14 +39,16 @@ public function let( LineItemsConverterInterface $shipmentLineItemsConverter, TaxItemsGeneratorInterface $taxItemsGenerator, CreditMemoFactoryInterface $creditMemoFactory, - CustomerBillingDataFactoryInterface $customerBillingDataFactory + CustomerBillingDataFactoryInterface $customerBillingDataFactory, + ShopBillingDataFactoryInterface $shopBillingDataFactory ): void { $this->beConstructedWith( $lineItemsConverter, $shipmentLineItemsConverter, $taxItemsGenerator, $creditMemoFactory, - $customerBillingDataFactory + $customerBillingDataFactory, + $shopBillingDataFactory ); } @@ -68,7 +71,9 @@ public function it_generates_credit_memo_basing_on_event_data( AddressInterface $customerBillingAddress, LineItemInterface $firstLineItem, LineItemInterface $secondLineItem, - TaxItemInterface $taxItem + TaxItemInterface $taxItem, + ShopBillingDataFactoryInterface $shopBillingDataFactory, + ShopBillingData $shopBillingDataFromFactory ): void { $firstUnitRefund = new OrderItemUnitRefund(1, 500); $secondUnitRefund = new OrderItemUnitRefund(3, 500); @@ -100,6 +105,15 @@ public function it_generates_credit_memo_basing_on_event_data( $taxItemsGenerator->generate([$firstLineItem, $secondLineItem])->willReturn([$taxItem]); $customerBillingDataFactory->createWithAddress($customerBillingAddress)->willReturn($customerBillingData); + $shopBillingDataFactory->createWithData( + 'Needful Things', + '000222', + 'US', + 'Main St. 123', + 'New York', + '90222' + )->willReturn($shopBillingDataFromFactory); + $creditMemoFactory ->createWithData( $order, @@ -108,7 +122,7 @@ public function it_generates_credit_memo_basing_on_event_data( [$taxItem], 'Comment', $customerBillingData, - new ShopBillingData('Needful Things', '000222', 'US', 'Main St. 123', 'New York', '90222') + $shopBillingDataFromFactory ) ->willReturn($creditMemo) ; diff --git a/src/Entity/ShopBillingData.php b/src/Entity/ShopBillingData.php index 6b2d2d52..66780c10 100644 --- a/src/Entity/ShopBillingData.php +++ b/src/Entity/ShopBillingData.php @@ -16,7 +16,7 @@ /** final */ class ShopBillingData implements ShopBillingDataInterface { - /** @var int|null */ + /** @var mixed */ protected $id; /** @var string|null */ @@ -37,23 +37,72 @@ class ShopBillingData implements ShopBillingDataInterface /** @var string|null */ protected $postcode; - public function __construct( - ?string $company, - ?string $taxId, - ?string $countryCode, - ?string $street, - ?string $city, - ?string $postcode - ) { + public function getId() + { + return $this->id; + } + + public function getCompany(): ?string + { + return $this->company; + } + + public function setCompany(?string $company): void + { $this->company = $company; + } + + public function getTaxId(): ?string + { + return $this->taxId; + } + + public function setTaxId(?string $taxId): void + { $this->taxId = $taxId; + } + + public function getCountryCode(): ?string + { + return $this->countryCode; + } + + public function setCountryCode(?string $countryCode): void + { $this->countryCode = $countryCode; + } + + public function getStreet(): ?string + { + return $this->street; + } + + public function setStreet(?string $street): void + { $this->street = $street; + } + + public function getCity(): ?string + { + return $this->city; + } + + public function setCity(?string $city): void + { $this->city = $city; + } + + public function getPostcode(): ?string + { + return $this->postcode; + } + + public function setPostcode(?string $postcode): void + { $this->postcode = $postcode; } - public function id(): ?int + public function id() { return $this->id; } diff --git a/src/Entity/ShopBillingDataInterface.php b/src/Entity/ShopBillingDataInterface.php index 09686d5c..8db67ce1 100644 --- a/src/Entity/ShopBillingDataInterface.php +++ b/src/Entity/ShopBillingDataInterface.php @@ -13,19 +13,62 @@ namespace Sylius\RefundPlugin\Entity; -interface ShopBillingDataInterface +use Sylius\Component\Resource\Model\ResourceInterface; + +interface ShopBillingDataInterface extends ResourceInterface { - public function id(): ?int; + /** + * @return mixed + */ + public function getId(); + + public function getCompany(): ?string; + + public function setCompany(?string $company): void; + + public function getTaxId(): ?string; + + public function setTaxId(?string $taxId): void; + + public function getCountryCode(): ?string; + + public function setCountryCode(?string $countryCode): void; + + public function getStreet(): ?string; + + public function setStreet(?string $street): void; + + public function getCity(): ?string; + + public function setCity(?string $city): void; + + public function getPostcode(): ?string; + + public function setPostcode(?string $postcode): void; + + /** + * @return mixed + * + * @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getId() instead + * @see CustomerBillingDataInterface::getId + */ + public function id(); + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getCompany() instead */ public function company(): ?string; + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getTaxId() instead */ public function taxId(): ?string; + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getCountryCode() instead */ public function countryCode(): ?string; + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getStreet() instead */ public function street(): ?string; + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getCity() instead */ public function city(): ?string; + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getPostcode() instead */ public function postcode(): ?string; } diff --git a/src/Factory/ShopBillingDataFactory.php b/src/Factory/ShopBillingDataFactory.php new file mode 100644 index 00000000..9cee2db8 --- /dev/null +++ b/src/Factory/ShopBillingDataFactory.php @@ -0,0 +1,56 @@ +shopBillingDataFactory = $shopBillingDataFactory; + } + + public function createNew(): ShopBillingDataInterface + { + /** @var ShopBillingDataInterface $shopBillingData */ + $shopBillingData = $this->shopBillingDataFactory->createNew(); + + return $shopBillingData; + } + + public function createWithData( + ?string $company, + ?string $taxId, + ?string $countryCode, + ?string $street, + ?string $city, + ?string $postcode + ): ShopBillingDataInterface { + $shopBillingData = $this->createNew(); + + $shopBillingData->setCompany($company); + $shopBillingData->setTaxId($taxId); + $shopBillingData->setCountryCode($countryCode); + $shopBillingData->setStreet($street); + $shopBillingData->setCity($city); + $shopBillingData->setPostcode($postcode); + + return $shopBillingData; + } +} diff --git a/src/Factory/ShopBillingDataFactoryInterface.php b/src/Factory/ShopBillingDataFactoryInterface.php new file mode 100644 index 00000000..8f18a96e --- /dev/null +++ b/src/Factory/ShopBillingDataFactoryInterface.php @@ -0,0 +1,29 @@ +lineItemsConverter = $lineItemsConverter; $this->shipmentLineItemsConverter = $shipmentLineItemsConverter; $this->taxItemsGenerator = $taxItemsGenerator; $this->creditMemoFactory = $creditMemoFactory; $this->customerBillingDataFactory = $customerBillingDataFactory; + $this->shopBillingDataFactory = $shopBillingDataFactory; } public function generate( @@ -97,7 +103,7 @@ private function getFromAddress(AddressInterface $address): CustomerBillingDataI return $this->customerBillingDataFactory->createWithAddress($address); } - private function getToAddress(?ChannelShopBillingData $channelShopBillingData): ?ShopBillingData + private function getToAddress(?ChannelShopBillingData $channelShopBillingData): ?ShopBillingDataInterface { if ( $channelShopBillingData === null || @@ -106,7 +112,7 @@ private function getToAddress(?ChannelShopBillingData $channelShopBillingData): return null; } - return new ShopBillingData( + return $this->shopBillingDataFactory->createWithData( $channelShopBillingData->getCompany(), $channelShopBillingData->getTaxId(), $channelShopBillingData->getCountryCode(), diff --git a/src/Resources/config/app/config.yml b/src/Resources/config/app/config.yml index ae50d60c..4875cddd 100644 --- a/src/Resources/config/app/config.yml +++ b/src/Resources/config/app/config.yml @@ -22,6 +22,9 @@ sylius_resource: sylius_refund.customer_billing_data: classes: model: Sylius\RefundPlugin\Entity\CustomerBillingData + sylius_refund.shop_billing_data: + classes: + model: Sylius\RefundPlugin\Entity\ShopBillingData sylius_mailer: emails: diff --git a/src/Resources/config/services/factories.xml b/src/Resources/config/services/factories.xml index 82875c7d..f004fae0 100644 --- a/src/Resources/config/services/factories.xml +++ b/src/Resources/config/services/factories.xml @@ -31,6 +31,15 @@ + + + + + + The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 1.0, use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface instead. @@ -35,6 +37,7 @@ @SyliusRefundPlugin/Download/creditMemo.html.twig %sylius.refund.template.logo_file% + The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 1.0, use Sylius\RefundPlugin\Generator\CreditMemoPdfFileGeneratorInterface instead. diff --git a/tests/Behat/Context/Application/CreditMemoContext.php b/tests/Behat/Context/Application/CreditMemoContext.php index 46ffb283..34faf695 100644 --- a/tests/Behat/Context/Application/CreditMemoContext.php +++ b/tests/Behat/Context/Application/CreditMemoContext.php @@ -180,11 +180,11 @@ public function itShouldBeIssuedTo( ): void { $shopBillingData = $this->creditMemo->getTo(); - Assert::same($company, $shopBillingData->company()); - Assert::same($street, $shopBillingData->street()); - Assert::same($postcode, $shopBillingData->postcode()); - Assert::same($city, $shopBillingData->city()); - Assert::same($country->getCode(), $shopBillingData->countryCode()); - Assert::same($taxId, $shopBillingData->taxId()); + Assert::same($company, $shopBillingData->getCompany()); + Assert::same($street, $shopBillingData->getStreet()); + Assert::same($postcode, $shopBillingData->getPostcode()); + Assert::same($city, $shopBillingData->getCity()); + Assert::same($country->getCode(), $shopBillingData->getCountryCode()); + Assert::same($taxId, $shopBillingData->getTaxId()); } }