-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CreditMemo] Refactor creating CreditMemo to use a factory
- Loading branch information
Showing
12 changed files
with
396 additions
and
157 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,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\RefundPlugin\Factory; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Sylius\RefundPlugin\Entity\CreditMemoInterface; | ||
use Sylius\RefundPlugin\Entity\CustomerBillingDataInterface; | ||
use Sylius\RefundPlugin\Entity\LineItemInterface; | ||
use Sylius\RefundPlugin\Entity\ShopBillingDataInterface; | ||
use Sylius\RefundPlugin\Entity\TaxItemInterface; | ||
use Sylius\RefundPlugin\Factory\CreditMemoFactoryInterface; | ||
use Sylius\RefundPlugin\Generator\CreditMemoIdentifierGeneratorInterface; | ||
use Sylius\RefundPlugin\Generator\NumberGenerator; | ||
use Sylius\RefundPlugin\Provider\CurrentDateTimeImmutableProviderInterface; | ||
|
||
final class CreditMemoFactorySpec extends ObjectBehavior | ||
{ | ||
function let( | ||
FactoryInterface $creditMemoFactory, | ||
CreditMemoIdentifierGeneratorInterface $creditMemoIdentifierGenerator, | ||
NumberGenerator $creditMemoNumberGenerator, | ||
CurrentDateTimeImmutableProviderInterface $currentDateTimeImmutableProvider | ||
): void { | ||
$this->beConstructedWith( | ||
$creditMemoFactory, | ||
$creditMemoIdentifierGenerator, | ||
$creditMemoNumberGenerator, | ||
$currentDateTimeImmutableProvider | ||
); | ||
} | ||
function it_implements_a_credit_memo_factory_interface(): void | ||
{ | ||
$this->shouldImplement(CreditMemoFactoryInterface::class); | ||
} | ||
|
||
function it_creates_a_new_credit_memo( | ||
FactoryInterface $creditMemoFactory, | ||
CreditMemoInterface $creditMemo | ||
): void { | ||
$creditMemoFactory->createNew()->willReturn($creditMemo); | ||
|
||
$this->createNew()->shouldReturn($creditMemo); | ||
} | ||
|
||
function it_creates_a_new_credit_memo_with_data( | ||
FactoryInterface $creditMemoFactory, | ||
CreditMemoIdentifierGeneratorInterface $creditMemoIdentifierGenerator, | ||
NumberGenerator $creditMemoNumberGenerator, | ||
CurrentDateTimeImmutableProviderInterface $currentDateTimeImmutableProvider, | ||
CreditMemoInterface $creditMemo, | ||
OrderInterface $order, | ||
ChannelInterface $channel, | ||
LineItemInterface $firstLineItem, | ||
LineItemInterface $secondLineItem, | ||
TaxItemInterface $taxItem, | ||
CustomerBillingDataInterface $from, | ||
ShopBillingDataInterface $to | ||
): void { | ||
$creditMemoIdentifierGenerator->generate()->willReturn('7903c83a-4c5e-4bcf-81d8-9dc304c6a353'); | ||
$creditMemoNumberGenerator->generate()->willReturn('2018/07/00001111'); | ||
$currentDateTimeImmutableProvider->now()->willReturn(new \DateTimeImmutable('01-01-2020 10:10:10')); | ||
|
||
$order->getChannel()->willReturn($channel); | ||
$order->getCurrencyCode()->willReturn('USD'); | ||
$order->getLocaleCode()->willReturn('en_US'); | ||
|
||
$creditMemoFactory->createNew()->willReturn($creditMemo); | ||
$creditMemo->setId('7903c83a-4c5e-4bcf-81d8-9dc304c6a353')->shouldBeCalled(); | ||
$creditMemo->setNumber('2018/07/00001111')->shouldBeCalled(); | ||
$creditMemo->setOrder($order)->shouldBeCalled(); | ||
$creditMemo->setChannel($channel)->shouldBeCalled(); | ||
$creditMemo->setCurrencyCode('USD')->shouldBeCalled(); | ||
$creditMemo->setLocaleCode('en_US')->shouldBeCalled(); | ||
$creditMemo->setTotal(1400)->shouldBeCalled(); | ||
$creditMemo->setLineItems(new ArrayCollection([$firstLineItem->getWrappedObject(), $secondLineItem->getWrappedObject()]))->shouldBeCalled(); | ||
$creditMemo->setTaxItems(new ArrayCollection([$taxItem->getWrappedObject()]))->shouldBeCalled(); | ||
$creditMemo->setComment('Comment')->shouldBeCalled(); | ||
$creditMemo->setIssuedAt(new \DateTimeImmutable('01-01-2020 10:10:10'))->shouldBeCalled(); | ||
$creditMemo->setFrom($from)->shouldBeCalled(); | ||
$creditMemo->setTo($to)->shouldBeCalled(); | ||
|
||
$this | ||
->createWithData($order, 1400, [$firstLineItem, $secondLineItem], [$taxItem], 'Comment', $from, $to) | ||
->shouldBeLike($creditMemo) | ||
; | ||
} | ||
} |
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
Oops, something went wrong.