1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Gewebe\SyliusProductDepositPlugin\OrderProcessing; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\AdjustmentInterface; |
9
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ChannelDepositInterface; |
10
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface; |
11
|
|
|
use Gewebe\SyliusProductDepositPlugin\OrderProcessing\OrderDepositProcessor; |
12
|
|
|
use PhpSpec\ObjectBehavior; |
13
|
|
|
use Sylius\Component\Addressing\Matcher\ZoneMatcherInterface; |
14
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
15
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
16
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
17
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
18
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
19
|
|
|
use Sylius\Component\Core\Model\OrderItemUnitInterface; |
20
|
|
|
use Sylius\Component\Core\Provider\ZoneProviderInterface; |
21
|
|
|
use Sylius\Component\Core\Taxation\Applicator\OrderTaxesApplicatorInterface; |
22
|
|
|
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface; |
23
|
|
|
use Sylius\Component\Order\Processor\OrderProcessorInterface; |
24
|
|
|
|
25
|
|
|
final class OrderDepositProcessorSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function let( |
|
|
|
|
28
|
|
|
AdjustmentFactoryInterface $adjustmentFactory, |
29
|
|
|
OrderTaxesApplicatorInterface $orderTaxesApplicator, |
30
|
|
|
ZoneMatcherInterface $zoneMatcher, |
31
|
|
|
ZoneProviderInterface $defaultTaxZoneProvider |
32
|
|
|
): void { |
33
|
|
|
$this->beConstructedWith( |
34
|
|
|
$adjustmentFactory, |
35
|
|
|
$orderTaxesApplicator, |
36
|
|
|
$zoneMatcher, |
37
|
|
|
$defaultTaxZoneProvider |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_is_initializable(): void |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$this->shouldHaveType(OrderDepositProcessor::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_implements_order_processor_interface(): void |
47
|
|
|
{ |
48
|
|
|
$this->shouldImplement(OrderProcessorInterface::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_process_order_deposit( |
52
|
|
|
AddressInterface $address, |
53
|
|
|
AdjustmentInterface $adjustment, |
54
|
|
|
AdjustmentFactoryInterface $adjustmentFactory, |
55
|
|
|
ChannelInterface $channel, |
56
|
|
|
OrderInterface $order, |
57
|
|
|
OrderItemInterface $orderItem, |
58
|
|
|
OrderItemUnitInterface $orderItemUnit, |
59
|
|
|
OrderTaxesApplicatorInterface $orderTaxesApplicator, |
60
|
|
|
ProductVariantInterface $productVariant, |
61
|
|
|
ZoneProviderInterface $defaultTaxZoneProvider, |
62
|
|
|
ZoneMatcherInterface $zoneMatcher, |
63
|
|
|
ZoneInterface $zone |
64
|
|
|
): void { |
65
|
|
|
$order->getChannel()->willReturn($channel); |
|
|
|
|
66
|
|
|
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); |
|
|
|
|
67
|
|
|
$order->getShippingAddress()->willReturn($address); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$orderItem->getVariant()->willReturn($productVariant); |
|
|
|
|
70
|
|
|
$orderItem->getUnits()->willReturn(new ArrayCollection([$orderItemUnit->getWrappedObject()])); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$productVariant->getDepositPriceByChannel($channel)->willReturn(50); |
73
|
|
|
|
74
|
|
|
$orderItemUnit->addAdjustment($adjustment)->shouldBeCalled(); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$adjustmentFactory->createWithData( |
77
|
|
|
AdjustmentInterface::DEPOSIT_ADJUSTMENT, |
78
|
|
|
'Deposit', |
79
|
|
|
50 |
80
|
|
|
)->willReturn($adjustment); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$defaultTaxZoneProvider->getZone($order)->willReturn($zone); |
|
|
|
|
83
|
|
|
$this->beConstructedWith($adjustmentFactory, $orderTaxesApplicator, $zoneMatcher, $defaultTaxZoneProvider); |
84
|
|
|
|
85
|
|
|
$this->process($order); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
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.