|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace spec\Gewebe\SyliusProductDepositPlugin\Taxation; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ChannelDepositInterface; |
|
9
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface; |
|
10
|
|
|
use Gewebe\SyliusProductDepositPlugin\Taxation\OrderDepositTaxesApplicator; |
|
11
|
|
|
use PhpSpec\ObjectBehavior; |
|
12
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
|
13
|
|
|
use Sylius\Component\Core\Model\AdjustmentInterface; |
|
14
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
15
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
16
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\OrderItemUnitInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\TaxRateInterface; |
|
19
|
|
|
use Sylius\Component\Core\Taxation\Applicator\OrderTaxesApplicatorInterface; |
|
20
|
|
|
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface; |
|
21
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
22
|
|
|
use Sylius\Component\Taxation\Calculator\CalculatorInterface; |
|
23
|
|
|
use Sylius\Component\Taxation\Model\TaxCategoryInterface; |
|
24
|
|
|
|
|
25
|
|
|
final class OrderDepositTaxesApplicatorSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function let( |
|
|
|
|
|
|
28
|
|
|
CalculatorInterface $calculator, |
|
29
|
|
|
AdjustmentFactoryInterface $adjustmentFactory, |
|
30
|
|
|
RepositoryInterface $taxRateRepository |
|
31
|
|
|
) { |
|
32
|
|
|
$this->beConstructedWith($calculator, $adjustmentFactory, $taxRateRepository); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function it_is_initializable(): void |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$this->shouldHaveType(OrderDepositTaxesApplicator::class); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function it_implements_order_processor_interface(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->shouldImplement(OrderTaxesApplicatorInterface::class); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function it_apply_taxes( |
|
46
|
|
|
AdjustmentFactoryInterface $adjustmentFactory, |
|
47
|
|
|
AdjustmentInterface $adjustment, |
|
48
|
|
|
CalculatorInterface $calculator, |
|
49
|
|
|
ChannelInterface $channel, |
|
50
|
|
|
ChannelDepositInterface $channelDeposit, |
|
51
|
|
|
OrderInterface $order, |
|
52
|
|
|
OrderItemInterface $orderItem, |
|
53
|
|
|
OrderItemUnitInterface $orderItemUnit, |
|
54
|
|
|
ProductVariantInterface $productVariant, |
|
55
|
|
|
RepositoryInterface $taxRateRepository, |
|
56
|
|
|
TaxCategoryInterface $taxCategory, |
|
57
|
|
|
TaxRateInterface $taxRate, |
|
58
|
|
|
ZoneInterface $zone |
|
59
|
|
|
): void { |
|
60
|
|
|
$adjustmentFactory->createWithData( |
|
61
|
|
|
AdjustmentInterface::TAX_ADJUSTMENT, |
|
62
|
|
|
'Returnable tax (exclude)', |
|
63
|
|
|
15, |
|
64
|
|
|
false |
|
65
|
|
|
)->willReturn($adjustment); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$taxRate->getLabel()->willReturn('Returnable tax (exclude)'); |
|
68
|
|
|
$taxRate->isIncludedInPrice()->willReturn(false); |
|
69
|
|
|
|
|
70
|
|
|
$calculator->calculate(100, $taxRate)->willReturn(15); |
|
71
|
|
|
$taxRateRepository->findOneBy(['category' => $taxCategory, 'zone' => $zone])->willReturn($taxRate); |
|
72
|
|
|
$this->beConstructedWith($calculator, $adjustmentFactory, $taxRateRepository); |
|
73
|
|
|
|
|
74
|
|
|
$channelDeposit->getPrice()->willReturn(100); |
|
75
|
|
|
|
|
76
|
|
|
$productVariant->getChannelDepositForChannel($channel)->willReturn($channelDeposit); |
|
|
|
|
|
|
77
|
|
|
$productVariant->getDepositTaxCategory()->willReturn($taxCategory); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$orderItem->getVariant()->willReturn($productVariant); |
|
|
|
|
|
|
80
|
|
|
$orderItem->getUnits()->willReturn(new ArrayCollection([$orderItemUnit->getWrappedObject()])); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$orderItemUnit->addAdjustment($adjustment)->shouldBeCalled(); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$order->getChannel()->willReturn($channel); |
|
|
|
|
|
|
85
|
|
|
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
$this->apply($order, $zone); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.