-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move invoice number generation to invoice generator decorator in orde…
…r space Signed-off-by: Anton Fedurtsya <[email protected]>
- Loading branch information
Showing
8 changed files
with
135 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FreshAdvance\Invoice\Order\Decoration; | ||
|
||
use FreshAdvance\Invoice\DataType\InvoiceDataInterface; | ||
use FreshAdvance\Invoice\Document\InvoiceGeneratorInterface; | ||
use FreshAdvance\Invoice\Service\OrderServiceInterface; | ||
|
||
class InvoiceGeneratorDecorator implements InvoiceGeneratorInterface | ||
{ | ||
public function __construct( | ||
private InvoiceGeneratorInterface $originalGenerator, | ||
private OrderServiceInterface $orderService, | ||
) { | ||
} | ||
|
||
public function generate(InvoiceDataInterface $invoiceData): void | ||
{ | ||
$this->orderService->prepareOrderInvoiceNumber($invoiceData); | ||
$this->originalGenerator->generate($invoiceData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
services: | ||
_defaults: | ||
public: false | ||
autowire: true | ||
|
||
FreshAdvance\Invoice\Order\Decoration\InvoiceGeneratorDecorator: | ||
decorates: FreshAdvance\Invoice\Document\InvoiceGeneratorInterface | ||
arguments: | ||
$originalGenerator: '@.inner' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
imports: | ||
- { resource: Decoration/services.yaml } | ||
|
||
services: | ||
_defaults: | ||
public: false | ||
autowire: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/Integration/Order/Decoration/InvoiceGeneratorDecoratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FreshAdvance\Invoice\Tests\Integration\Order\Decoration; | ||
|
||
use FreshAdvance\Invoice\Document\InvoiceGeneratorInterface; | ||
use FreshAdvance\Invoice\Order\Decoration\InvoiceGeneratorDecorator; | ||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; | ||
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; | ||
|
||
/** @covers \FreshAdvance\Invoice\Order\Decoration\InvoiceGeneratorDecorator */ | ||
class InvoiceGeneratorDecoratorTest extends IntegrationTestCase | ||
{ | ||
public function testOriginalServiceIsDecorated(): void | ||
{ | ||
$sut = ContainerFactory::getInstance()->getContainer()->get(InvoiceGeneratorInterface::class); | ||
|
||
$this->assertInstanceOf(InvoiceGeneratorDecorator::class, $sut); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/Unit/Order/Decoration/InvoiceGeneratorDecoratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © MB Arbatos Klubas. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FreshAdvance\Invoice\Tests\Unit\Order\Decoration; | ||
|
||
use FreshAdvance\Invoice\DataType\InvoiceDataInterface; | ||
use FreshAdvance\Invoice\Document\InvoiceGeneratorInterface; | ||
use FreshAdvance\Invoice\Order\Decoration\InvoiceGeneratorDecorator; | ||
use FreshAdvance\Invoice\Service\OrderServiceInterface; | ||
use OxidEsales\Eshop\Application\Model\Order; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \FreshAdvance\Invoice\Order\Decoration\InvoiceGeneratorDecorator */ | ||
class InvoiceGeneratorDecoratorTest extends TestCase | ||
{ | ||
public function testOriginalGeneratorCalledWithCorrectParameter(): void | ||
{ | ||
$invoiceDataStub = $this->createStub(InvoiceDataInterface::class); | ||
|
||
$generatorSpy = $this->createMock(InvoiceGeneratorInterface::class); | ||
$generatorSpy->expects($this->once()) | ||
->method('generate') | ||
->with($invoiceDataStub); | ||
|
||
$sut = $this->getSut($generatorSpy); | ||
|
||
$sut->generate($invoiceDataStub); | ||
} | ||
|
||
public function testGenerateTriggersOrderNumberingUpdate(): void | ||
{ | ||
$invoiceData = $this->createConfiguredMock(InvoiceDataInterface::class, [ | ||
'getOrder' => $this->createStub(Order::class) | ||
]); | ||
|
||
$sut = $this->getSut( | ||
orderService: $orderServiceSpy = $this->createMock(OrderServiceInterface::class), | ||
); | ||
|
||
$orderServiceSpy->expects($this->once()) | ||
->method('prepareOrderInvoiceNumber') | ||
->with($invoiceData); | ||
|
||
$sut->generate($invoiceData); | ||
} | ||
|
||
public function getSut( | ||
InvoiceGeneratorInterface $originalGenerator = null, | ||
OrderServiceInterface $orderService = null, | ||
): InvoiceGeneratorInterface { | ||
return new InvoiceGeneratorDecorator( | ||
originalGenerator: $originalGenerator ?? $this->createStub(InvoiceGeneratorInterface::class), | ||
orderService: $orderService ?? $this->createStub(OrderServiceInterface::class), | ||
); | ||
} | ||
} |