Skip to content

Commit

Permalink
refactor #313 Change CustomerBillingData to resource and create via f…
Browse files Browse the repository at this point in the history
…actory (arti0090)

This PR was merged into the 1.0-dev branch.

Discussion
----------



Commits
-------

1576c43 Change CustomerBillingData to resource and create via factory
86ecbe2 Assert creation of billing
7bb4533 Add note about getters
1d9d77d Deprecate old methods
bae02c1 Suppress phpstan
  • Loading branch information
GSadee authored Jun 17, 2021
2 parents ec8e508 + bae02c1 commit 2c98749
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 102 deletions.
50 changes: 50 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,56 @@

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
) {
...
}
```

1. The `id` method from `Sylius\RefundPlugin\Entity\CustomerBillingData` has its return type removed:

```diff
- public function id(): ?int;
+ public function id();
```


1. The getter methods of `Sylius\RefundPlugin\Entity\CustomerBillingData` are now deprecated and will be replaced with:

```diff
- public function id(): ?int
+ public function getId()
- public function firstName(): string
+ public function getFirstName(): string
- public function lastName(): string
+ public function getLastName(): string
- public function fullName(): string
+ public function getFullName(): string
- public function street(): string
+ public function getStreet(): string
- public function postcode(): string
+ public function getPostcode(): string
- public function city(): string
+ public function getCity(): string
- public function company(): ?string
+ public function getCompany(): ?string
- public function provinceName(): ?string
+ public function getProvinceName(): ?string
- public function provinceCode(): ?string
+ public function getProvinceCode(): ?string
```

### 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)
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ parameters:
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::id\(\) has no return typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::getId\(\) has no return typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::setId\(\) has parameter \$id with no typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::id\(\) has no return typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::setId\(\) has parameter \$id with no typehint specified./'
74 changes: 38 additions & 36 deletions spec/Entity/CustomerBillingDataSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,78 +18,80 @@

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);
}

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');
}
}
97 changes: 97 additions & 0 deletions spec/Factory/CustomerBillingDataFactorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Sylius\RefundPlugin\Factory;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\RefundPlugin\Entity\CustomerBillingDataInterface;
use Sylius\RefundPlugin\Factory\CustomerBillingDataFactoryInterface;

final class CustomerBillingDataFactorySpec extends ObjectBehavior
{
public function let(FactoryInterface $customerBillingDataFactory): void
{
$this->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)
;
}
}
14 changes: 10 additions & 4 deletions spec/Generator/CreditMemoGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
);
}

Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 2c98749

Please sign in to comment.