Skip to content

Commit

Permalink
revert to decorating factory
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin committed Jun 21, 2021
1 parent 1d4e338 commit 71f26d2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
29 changes: 20 additions & 9 deletions spec/Factory/ShopBillingDataFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,36 @@
namespace spec\Sylius\RefundPlugin\Factory;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Resource\Exception\UnsupportedMethodException;
use Sylius\RefundPlugin\Entity\ShopBillingData;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\RefundPlugin\Entity\ShopBillingDataInterface;
use Sylius\RefundPlugin\Factory\ShopBillingDataFactoryInterface;

class ShopBillingDataFactorySpec extends ObjectBehavior
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_doesnt_support_create_new_method(): void
{
$this->shouldThrow(UnsupportedMethodException::class)->during('createNew');
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(): void
{
$shopBillingData = new 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');
Expand Down
18 changes: 14 additions & 4 deletions src/Factory/ShopBillingDataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@

namespace Sylius\RefundPlugin\Factory;

use Sylius\Component\Resource\Exception\UnsupportedMethodException;
use Sylius\RefundPlugin\Entity\ShopBillingData;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\RefundPlugin\Entity\ShopBillingDataInterface;

final class ShopBillingDataFactory implements ShopBillingDataFactoryInterface
{
/** @var FactoryInterface */
private $shopBillingDataFactory;

public function __construct(FactoryInterface $shopBillingDataFactory)
{
$this->shopBillingDataFactory = $shopBillingDataFactory;
}

public function createNew(): ShopBillingDataInterface
{
throw new UnsupportedMethodException('This object is not default constructable.');
/** @var ShopBillingDataInterface $shopBillingData */
$shopBillingData = $this->shopBillingDataFactory->createNew();

return $shopBillingData;
}

public function createWithData(
Expand All @@ -32,7 +42,7 @@ public function createWithData(
?string $city,
?string $postcode
): ShopBillingDataInterface {
$shopBillingData = new ShopBillingData();
$shopBillingData = $this->createNew();

$shopBillingData->setCompany($company);
$shopBillingData->setTaxId($taxId);
Expand Down
2 changes: 0 additions & 2 deletions src/Factory/ShopBillingDataFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

interface ShopBillingDataFactoryInterface extends FactoryInterface
{
public function createNew(): ShopBillingDataInterface;

public function createWithData(
?string $company,
?string $taxId,
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ sylius_resource:
sylius_refund.shop_billing_data:
classes:
model: Sylius\RefundPlugin\Entity\ShopBillingData
factory: Sylius\RefundPlugin\Factory\ShopBillingDataFactory

sylius_mailer:
emails:
Expand Down
9 changes: 9 additions & 0 deletions src/Resources/config/services/factories.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
<argument type="service" id="Sylius\RefundPlugin\Provider\CurrentDateTimeImmutableProviderInterface" />
</service>

<service
id="Sylius\RefundPlugin\Factory\ShopBillingDataFactory"
decorates="sylius_refund.factory.shop_billing_data"
decoration-priority="256"
public="false"
>
<argument type="service" id="Sylius\RefundPlugin\Factory\ShopBillingDataFactory.inner" />
</service>

<service
id="Sylius\RefundPlugin\Factory\CustomerBillingDataFactory"
decorates="sylius_refund.factory.customer_billing_data"
Expand Down
Empty file.

0 comments on commit 71f26d2

Please sign in to comment.