diff --git a/UPGRADE.md b/UPGRADE.md
index 71e5236d3..bc0e6ca59 100644
--- a/UPGRADE.md
+++ b/UPGRADE.md
@@ -23,6 +23,23 @@
1. The constructor of `Sylius\RefundPlugin\Provider\DefaultRelatedPaymentIdProvider` has been removed.
+1. Constructor of `Sylius\RefundPlugin\Entity\CustomerBillingData` has been removed and now `CustomerBillingData` entity
+ is created by `Sylius\RefundPlugin\Factory\CustomerBillingDataFactory`.
+
+1. The constructor of `Sylius\RefundPlugin\Generator\CreditMemoGenerator` has been changed:
+
+ ```diff
+ public function __construct(
+ LineItemsConverterInterface $lineItemsConverter,
+ LineItemsConverterInterface $shipmentLineItemsConverter,
+ TaxItemsGeneratorInterface $taxItemsGenerator,
+ CreditMemoFactoryInterface $creditMemoFactory,
+ + CustomerBillingDataFactoryInterface $customerBillingDataFactory
+ ) {
+ ...
+ }
+ ```
+
### UPGRADE FROM 1.0.0-RC.9 TO 1.0.0-RC.10
1. Support for Sylius 1.8 has been dropped, upgrade your application to [Sylius 1.9](https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.9.md)
diff --git a/spec/Entity/CustomerBillingDataSpec.php b/spec/Entity/CustomerBillingDataSpec.php
index ff145c31e..8d815ac7e 100644
--- a/spec/Entity/CustomerBillingDataSpec.php
+++ b/spec/Entity/CustomerBillingDataSpec.php
@@ -18,21 +18,6 @@
final class CustomerBillingDataSpec extends ObjectBehavior
{
- public function let(): void
- {
- $this->beConstructedWith(
- 'Rick',
- 'Sanchez',
- 'Main St. 3322',
- '90802',
- 'US',
- 'Los Angeles',
- 'Curse Purge Plus!',
- 'Baldwin Hills',
- '323'
- );
- }
-
public function it_implements_customer_billing_data_interface(): void
{
$this->shouldImplement(CustomerBillingDataInterface::class);
@@ -40,56 +25,73 @@ public function it_implements_customer_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_an_id(): void
+ {
+ $this->setId(1234);
+ $this->getId()->shouldReturn(1234);
}
- public function it_has_first_name(): void
+ public function it_has_a_first_name(): void
{
- $this->firstName()->shouldReturn('Rick');
+ $this->setFirstName('Rick');
+ $this->getFirstName()->shouldReturn('Rick');
}
- public function it_has_last_name(): void
+ public function it_has_a_last_name(): void
{
- $this->lastName()->shouldReturn('Sanchez');
+ $this->setLastName('Sanchez');
+ $this->getLastName()->shouldReturn('Sanchez');
}
- public function it_has_full_name(): void
+ public function it_has_a_full_name(): void
{
- $this->fullName()->shouldReturn('Rick Sanchez');
+ $this->setFirstName('Rick');
+ $this->setLastName('Sanchez');
+ $this->getFullName()->shouldReturn('Rick Sanchez');
}
- public function it_has_company(): void
+ public function it_has_a_company(): void
{
- $this->company()->shouldReturn('Curse Purge Plus!');
+ $this->setCompany('Curse Purge Plus!');
+ $this->getCompany()->shouldReturn('Curse Purge Plus!');
}
- public function it_has_street(): void
+ public function it_has_a_street(): void
{
- $this->street()->shouldReturn('Main St. 3322');
+ $this->setStreet('Main St. 3322');
+ $this->getStreet()->shouldReturn('Main St. 3322');
}
- public function it_has_postcode(): void
+ public function it_has_a_postcode(): void
{
- $this->postcode()->shouldReturn('90802');
+ $this->setPostcode('90802');
+ $this->getPostcode()->shouldReturn('90802');
}
- 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_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_province_name(): void
+ public function it_has_a_province_name(): void
{
- $this->provinceName()->shouldReturn('Baldwin Hills');
+ $this->setProvinceName('Baldwin Hills');
+ $this->getProvinceName()->shouldReturn('Baldwin Hills');
}
- public function it_has_province_code(): void
+ public function it_has_a_province_code(): void
{
- $this->provinceCode()->shouldReturn('323');
+ $this->setProvinceCode('323');
+ $this->getProvinceCode()->shouldReturn('323');
}
}
diff --git a/spec/Factory/CustomerBillingDataFactorySpec.php b/spec/Factory/CustomerBillingDataFactorySpec.php
new file mode 100644
index 000000000..da249bb4e
--- /dev/null
+++ b/spec/Factory/CustomerBillingDataFactorySpec.php
@@ -0,0 +1,97 @@
+beConstructedWith($customerBillingDataFactory);
+ }
+
+ public function it_implements_customer_billing_data_factory_interface(): void
+ {
+ $this->shouldImplement(CustomerBillingDataFactoryInterface::class);
+ }
+
+ public function it_creates_a_new_customer_billing_data(
+ FactoryInterface $customerBillingDataFactory,
+ CustomerBillingDataInterface $billingData
+ ): void {
+ $customerBillingDataFactory->createNew()->willReturn($billingData);
+
+ $this->createNew()->shouldReturn($billingData);
+ }
+
+ public function it_creates_a_new_customer_billing_data_with_data(
+ CustomerBillingDataInterface $customerBillingData,
+ CustomerBillingDataFactoryInterface $customerBillingDataFactory
+ ): void {
+ $customerBillingDataFactory->createNew()->willReturn($customerBillingData);
+
+ $customerBillingData->setFirstName('Pablo')->shouldBeCalled();
+ $customerBillingData->setLastName('Escobar')->shouldBeCalled();
+ $customerBillingData->setStreet('Coke street')->shouldBeCalled();
+ $customerBillingData->setPostcode('90-210')->shouldBeCalled();
+ $customerBillingData->setCountryCode('CO')->shouldBeCalled();
+ $customerBillingData->setCity('Bogota')->shouldBeCalled();
+ $customerBillingData->setCompany('Coca cola but better')->shouldBeCalled();
+ $customerBillingData->setProvinceName('Bogota')->shouldBeCalled();
+ $customerBillingData->setProvinceCode('CO-DC')->shouldBeCalled();
+
+ $this
+ ->createWithData('Pablo', 'Escobar', 'Coke street', '90-210', 'CO', 'Bogota', 'Coca cola but better', 'Bogota', 'CO-DC')
+ ->shouldBeLike($customerBillingData)
+ ;
+ }
+
+ public function it_creates_a_new_customer_billing_data_with_address(
+ CustomerBillingDataInterface $customerBillingData,
+ CustomerBillingDataFactoryInterface $customerBillingDataFactory,
+ AddressInterface $address
+ ): void {
+ $address->getFirstName()->willReturn('Pablo');
+ $address->getLastName()->willReturn('Escobar');
+ $address->getStreet()->willReturn('Coke street');
+ $address->getPostcode()->willReturn('90-210');
+ $address->getCountryCode()->willReturn('CO');
+ $address->getCity()->willReturn('Bogota');
+ $address->getCompany()->willReturn('Coca cola but better');
+ $address->getProvinceName()->willReturn('Bogota');
+ $address->getProvinceCode()->willReturn('CO-DC');
+
+ $customerBillingDataFactory->createNew()->willReturn($customerBillingData);
+
+ $customerBillingData->setFirstName('Pablo')->shouldBeCalled();
+ $customerBillingData->setLastName('Escobar')->shouldBeCalled();
+ $customerBillingData->setStreet('Coke street')->shouldBeCalled();
+ $customerBillingData->setPostcode('90-210')->shouldBeCalled();
+ $customerBillingData->setCountryCode('CO')->shouldBeCalled();
+ $customerBillingData->setCity('Bogota')->shouldBeCalled();
+ $customerBillingData->setCompany('Coca cola but better')->shouldBeCalled();
+ $customerBillingData->setProvinceName('Bogota')->shouldBeCalled();
+ $customerBillingData->setProvinceCode('CO-DC')->shouldBeCalled();
+
+ $this
+ ->createWithAddress($address)
+ ->shouldReturn($customerBillingData)
+ ;
+ }
+}
diff --git a/spec/Generator/CreditMemoGeneratorSpec.php b/spec/Generator/CreditMemoGeneratorSpec.php
index a25f1e2ee..714d60558 100644
--- a/spec/Generator/CreditMemoGeneratorSpec.php
+++ b/spec/Generator/CreditMemoGeneratorSpec.php
@@ -20,11 +20,12 @@
use Sylius\Component\Core\Model\ShopBillingDataInterface;
use Sylius\RefundPlugin\Converter\LineItemsConverterInterface;
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
-use Sylius\RefundPlugin\Entity\CustomerBillingData;
+use Sylius\RefundPlugin\Entity\CustomerBillingDataInterface;
use Sylius\RefundPlugin\Entity\LineItemInterface;
use Sylius\RefundPlugin\Entity\ShopBillingData;
use Sylius\RefundPlugin\Entity\TaxItemInterface;
use Sylius\RefundPlugin\Factory\CreditMemoFactoryInterface;
+use Sylius\RefundPlugin\Factory\CustomerBillingDataFactoryInterface;
use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface;
use Sylius\RefundPlugin\Generator\TaxItemsGeneratorInterface;
use Sylius\RefundPlugin\Model\OrderItemUnitRefund;
@@ -36,13 +37,15 @@ public function let(
LineItemsConverterInterface $lineItemsConverter,
LineItemsConverterInterface $shipmentLineItemsConverter,
TaxItemsGeneratorInterface $taxItemsGenerator,
- CreditMemoFactoryInterface $creditMemoFactory
+ CreditMemoFactoryInterface $creditMemoFactory,
+ CustomerBillingDataFactoryInterface $customerBillingDataFactory
): void {
$this->beConstructedWith(
$lineItemsConverter,
$shipmentLineItemsConverter,
$taxItemsGenerator,
- $creditMemoFactory
+ $creditMemoFactory,
+ $customerBillingDataFactory
);
}
@@ -56,7 +59,9 @@ public function it_generates_credit_memo_basing_on_event_data(
LineItemsConverterInterface $shipmentLineItemsConverter,
TaxItemsGeneratorInterface $taxItemsGenerator,
CreditMemoFactoryInterface $creditMemoFactory,
+ CustomerBillingDataFactoryInterface $customerBillingDataFactory,
CreditMemoInterface $creditMemo,
+ CustomerBillingDataInterface $customerBillingData,
OrderInterface $order,
ChannelInterface $channel,
ShopBillingDataInterface $shopBillingData,
@@ -93,6 +98,7 @@ public function it_generates_credit_memo_basing_on_event_data(
$shipmentLineItemsConverter->convert([$shipmentRefund])->willReturn([$secondLineItem]);
$taxItemsGenerator->generate([$firstLineItem, $secondLineItem])->willReturn([$taxItem]);
+ $customerBillingDataFactory->createWithAddress($customerBillingAddress)->willReturn($customerBillingData);
$creditMemoFactory
->createWithData(
@@ -101,7 +107,7 @@ public function it_generates_credit_memo_basing_on_event_data(
[$firstLineItem, $secondLineItem],
[$taxItem],
'Comment',
- new CustomerBillingData('Rick', 'Sanchez', 'Universe St. 444', '000333', 'US', 'Los Angeles', 'Curse Purge Plus!'),
+ $customerBillingData,
new ShopBillingData('Needful Things', '000222', 'US', 'Main St. 123', 'New York', '90222')
)
->willReturn($creditMemo)
diff --git a/src/Entity/CustomerBillingData.php b/src/Entity/CustomerBillingData.php
index 2e2bd3c92..d5dbd1531 100644
--- a/src/Entity/CustomerBillingData.php
+++ b/src/Entity/CustomerBillingData.php
@@ -46,80 +46,108 @@ class CustomerBillingData implements CustomerBillingDataInterface
/** @var string|null */
protected $provinceCode;
- public function __construct(
- string $firstName,
- string $lastName,
- string $street,
- string $postcode,
- string $countryCode,
- string $city,
- ?string $company = null,
- ?string $provinceName = null,
- ?string $provinceCode = null
- ) {
- $this->firstName = $firstName;
- $this->lastName = $lastName;
- $this->street = $street;
- $this->postcode = $postcode;
- $this->countryCode = $countryCode;
- $this->city = $city;
- $this->company = $company;
- $this->provinceName = $provinceName;
- $this->provinceCode = $provinceCode;
+ public function getId(): ?int
+ {
+ return $this->id;
}
- public function id(): ?int
+ public function setId(?int $id): void
{
- return $this->id;
+ $this->id = $id;
}
- public function firstName(): string
+ public function getFirstName(): string
{
return $this->firstName;
}
- public function lastName(): string
+ public function setFirstName(string $firstName): void
+ {
+ $this->firstName = $firstName;
+ }
+
+ public function getLastName(): string
{
return $this->lastName;
}
- public function fullName(): string
+ public function setLastName(string $lastName): void
+ {
+ $this->lastName = $lastName;
+ }
+
+ public function getFullName(): string
{
return trim(sprintf('%s %s', $this->firstName, $this->lastName));
}
- public function street(): string
+ public function getStreet(): string
{
return $this->street;
}
- public function postcode(): string
+ public function setStreet(string $street): void
+ {
+ $this->street = $street;
+ }
+
+ public function getPostcode(): string
{
return $this->postcode;
}
- public function countryCode(): string
+ public function setPostcode(string $postcode): void
+ {
+ $this->postcode = $postcode;
+ }
+
+ public function getCountryCode(): string
{
return $this->countryCode;
}
- public function city(): string
+ public function setCountryCode(string $countryCode): void
+ {
+ $this->countryCode = $countryCode;
+ }
+
+ public function getCity(): string
{
return $this->city;
}
- public function company(): ?string
+ public function setCity(string $city): void
+ {
+ $this->city = $city;
+ }
+
+ public function getCompany(): ?string
{
return $this->company;
}
- public function provinceName(): ?string
+ public function setCompany(?string $company): void
+ {
+ $this->company = $company;
+ }
+
+ public function getProvinceName(): ?string
{
return $this->provinceName;
}
- public function provinceCode(): ?string
+ public function setProvinceName(?string $provinceName): void
+ {
+ $this->provinceName = $provinceName;
+ }
+
+ public function getProvinceCode(): ?string
{
return $this->provinceCode;
}
+
+ public function setProvinceCode(?string $provinceCode): void
+ {
+ $this->provinceCode = $provinceCode;
+ }
}
diff --git a/src/Entity/CustomerBillingDataInterface.php b/src/Entity/CustomerBillingDataInterface.php
index 2ebc1027c..9c4c1338e 100644
--- a/src/Entity/CustomerBillingDataInterface.php
+++ b/src/Entity/CustomerBillingDataInterface.php
@@ -15,25 +15,43 @@
interface CustomerBillingDataInterface
{
- public function id(): ?int;
+ public function setId(?int $id): void;
- public function firstName(): string;
+ public function getFirstName(): string;
- public function lastName(): string;
+ public function setFirstName(string $firstName): void;
- public function fullName(): string;
+ public function getLastName(): string;
- public function street(): string;
+ public function setLastName(string $lastName): void;
- public function postcode(): string;
+ public function getFullName(): string;
- public function countryCode(): string;
+ public function getStreet(): string;
- public function city(): string;
+ public function setStreet(string $street): void;
- public function company(): ?string;
+ public function getPostcode(): string;
- public function provinceName(): ?string;
+ public function setPostcode(string $postcode): void;
- public function provinceCode(): ?string;
+ public function getCountryCode(): string;
+
+ public function setCountryCode(string $countryCode): void;
+
+ public function getCity(): string;
+
+ public function setCity(string $city): void;
+
+ public function getCompany(): ?string;
+
+ public function setCompany(?string $company): void;
+
+ public function getProvinceName(): ?string;
+
+ public function setProvinceName(?string $provinceName): void;
+
+ public function getProvinceCode(): ?string;
+
+ public function setProvinceCode(?string $provinceCode): void;
}
diff --git a/src/Factory/CustomerBillingDataFactory.php b/src/Factory/CustomerBillingDataFactory.php
new file mode 100644
index 000000000..5788fb6b6
--- /dev/null
+++ b/src/Factory/CustomerBillingDataFactory.php
@@ -0,0 +1,78 @@
+customerBillingDataFactory = $customerBillingDataFactory;
+ }
+
+ public function createNew(): CustomerBillingDataInterface
+ {
+ /** @var CustomerBillingDataInterface $customerBillingData */
+ $customerBillingData = $this->customerBillingDataFactory->createNew();
+
+ return $customerBillingData;
+ }
+
+ public function createWithData(
+ string $firstName,
+ string $lastName,
+ string $street,
+ string $postcode,
+ string $countryCode,
+ string $city,
+ ?string $company = null,
+ ?string $provinceName = null,
+ ?string $provinceCode = null
+ ): CustomerBillingDataInterface {
+ $customerBillingData = $this->createNew();
+
+ $customerBillingData->setFirstName($firstName);
+ $customerBillingData->setLastName($lastName);
+ $customerBillingData->setStreet($street);
+ $customerBillingData->setPostcode($postcode);
+ $customerBillingData->setCountryCode($countryCode);
+ $customerBillingData->setCity($city);
+ $customerBillingData->setCompany($company);
+ $customerBillingData->setProvinceName($provinceName);
+ $customerBillingData->setProvinceCode($provinceCode);
+
+ return $customerBillingData;
+ }
+
+ public function createWithAddress(AddressInterface $address): CustomerBillingDataInterface
+ {
+ return $this->createWithData(
+ $address->getFirstName(),
+ $address->getLastName(),
+ $address->getStreet(),
+ $address->getPostcode(),
+ $address->getCountryCode(),
+ $address->getCity(),
+ $address->getCompany(),
+ $address->getProvinceName(),
+ $address->getProvinceCode()
+ );
+ }
+}
diff --git a/src/Factory/CustomerBillingDataFactoryInterface.php b/src/Factory/CustomerBillingDataFactoryInterface.php
new file mode 100644
index 000000000..2608231b1
--- /dev/null
+++ b/src/Factory/CustomerBillingDataFactoryInterface.php
@@ -0,0 +1,35 @@
+lineItemsConverter = $lineItemsConverter;
$this->shipmentLineItemsConverter = $shipmentLineItemsConverter;
$this->taxItemsGenerator = $taxItemsGenerator;
$this->creditMemoFactory = $creditMemoFactory;
+ $this->customerBillingDataFactory = $customerBillingDataFactory;
}
public function generate(
@@ -86,26 +92,15 @@ public function generate(
);
}
- private function getFromAddress(AddressInterface $address): CustomerBillingData
+ private function getFromAddress(AddressInterface $address): CustomerBillingDataInterface
{
Assert::notNull($address->getFirstName());
Assert::notNull($address->getLastName());
Assert::notNull($address->getStreet());
Assert::notNull($address->getPostcode());
Assert::notNull($address->getCountryCode());
- Assert::notNull($address->getCity());
-
- return new CustomerBillingData(
- $address->getFirstName(),
- $address->getLastName(),
- $address->getStreet(),
- $address->getPostcode(),
- $address->getCountryCode(),
- $address->getCity(),
- $address->getCompany(),
- $address->getProvinceName(),
- $address->getProvinceCode()
- );
+
+ return $this->customerBillingDataFactory->createWithAddress($address);
}
private function getToAddress(?ChannelShopBillingData $channelShopBillingData): ?ShopBillingData
diff --git a/src/Resources/config/services/factories.xml b/src/Resources/config/services/factories.xml
index 7040cf218..82875c7d5 100644
--- a/src/Resources/config/services/factories.xml
+++ b/src/Resources/config/services/factories.xml
@@ -30,5 +30,14 @@
+
+
+
+
diff --git a/src/Resources/config/services/generators.xml b/src/Resources/config/services/generators.xml
index 184b6a8ac..cba224511 100644
--- a/src/Resources/config/services/generators.xml
+++ b/src/Resources/config/services/generators.xml
@@ -21,6 +21,7 @@
+
The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 1.0, use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface instead.
diff --git a/tests/Behat/Context/Application/CreditMemoContext.php b/tests/Behat/Context/Application/CreditMemoContext.php
index a214589a2..46ffb2834 100644
--- a/tests/Behat/Context/Application/CreditMemoContext.php
+++ b/tests/Behat/Context/Application/CreditMemoContext.php
@@ -5,13 +5,10 @@
namespace Tests\Sylius\RefundPlugin\Behat\Context\Application;
use Behat\Behat\Context\Context;
-use Behat\Behat\Tester\Exception\PendingException;
use Doctrine\Persistence\ObjectRepository;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
-use Sylius\RefundPlugin\Entity\CustomerBillingData;
-use Sylius\RefundPlugin\Entity\ShopBillingData;
use Sylius\RefundPlugin\Entity\TaxItemInterface;
use Sylius\RefundPlugin\Provider\CurrentDateTimeImmutableProviderInterface;
use Webmozart\Assert\Assert;
@@ -163,11 +160,11 @@ public function itShouldBeIssuedFrom(
): void {
$customerBillingData = $this->creditMemo->getFrom();
- Assert::same($customerBillingData->fullName(), $customerName);
- Assert::same($customerBillingData->street(), $street);
- Assert::same($customerBillingData->postcode(), $postcode);
- Assert::same($customerBillingData->city(), $city);
- Assert::same($customerBillingData->countryCode(), $country->getCode());
+ Assert::same($customerBillingData->getFullName(), $customerName);
+ Assert::same($customerBillingData->getStreet(), $street);
+ Assert::same($customerBillingData->getPostcode(), $postcode);
+ Assert::same($customerBillingData->getCity(), $city);
+ Assert::same($customerBillingData->getCountryCode(), $country->getCode());
}
/**