Skip to content

Commit

Permalink
refactor #315 Shop billing data as resource (SirDomin)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------



Commits
-------

9e16c9f add factory and refactor shop billing data
8a7b9a3 Bring back previous methods to avoid bc break
b3ff3ba finalize Factory
d1a6869 pr-fix
b0247e7 coding-standard
90e2732 rebase
1d4e338 add-previous-changes
71f26d2 revert to decorating factory
  • Loading branch information
Zales0123 authored Jun 22, 2021
2 parents abe9ba9 + 71f26d2 commit 07993fb
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 45 deletions.
6 changes: 5 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +37,8 @@
LineItemsConverterInterface $shipmentLineItemsConverter,
TaxItemsGeneratorInterface $taxItemsGenerator,
CreditMemoFactoryInterface $creditMemoFactory,
+ CustomerBillingDataFactoryInterface $customerBillingDataFactory
+ CustomerBillingDataFactoryInterface $customerBillingDataFactory,
+ ShopBillingDataFactoryInterface $shopBillingDataFactory
) {
...
}
Expand Down
37 changes: 19 additions & 18 deletions spec/Entity/ShopBillingDataSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,49 @@

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

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');
}
}
60 changes: 60 additions & 0 deletions spec/Factory/ShopBillingDataFactorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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\Resource\Factory\FactoryInterface;
use Sylius\RefundPlugin\Entity\ShopBillingDataInterface;
use Sylius\RefundPlugin\Factory\ShopBillingDataFactoryInterface;

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

Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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)
;
Expand Down
69 changes: 59 additions & 10 deletions src/Entity/ShopBillingData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/** final */
class ShopBillingData implements ShopBillingDataInterface
{
/** @var int|null */
/** @var mixed */
protected $id;

/** @var string|null */
Expand All @@ -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;
}
Expand Down
47 changes: 45 additions & 2 deletions src/Entity/ShopBillingDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit 07993fb

Please sign in to comment.