Skip to content

Commit

Permalink
Change CustomerBillingData to resource and create via factory
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Jun 15, 2021
1 parent ec8e508 commit e164487
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 107 deletions.
17 changes: 17 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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 e164487

Please sign in to comment.