|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Spryker Commerce OS. |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types = 1); |
|
9
|
|
|
|
|
10
|
|
|
namespace PyzTest\Yves\Checkout\Process\Steps; |
|
11
|
|
|
|
|
12
|
|
|
use Codeception\Test\Unit; |
|
13
|
|
|
use Generated\Shared\Transfer\ExpenseTransfer; |
|
14
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
15
|
|
|
use Generated\Shared\Transfer\ShipmentTransfer; |
|
16
|
|
|
use Spryker\Shared\Shipment\ShipmentConfig; |
|
17
|
|
|
use Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginCollection; |
|
18
|
|
|
use Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginInterface; |
|
19
|
|
|
use SprykerShop\Yves\CheckoutPage\CheckoutPageDependencyProvider; |
|
20
|
|
|
use SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToCalculationClientInterface; |
|
21
|
|
|
use SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceBridge; |
|
22
|
|
|
use SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceInterface; |
|
23
|
|
|
use SprykerShop\Yves\CheckoutPage\GiftCard\GiftCardItemsChecker; |
|
24
|
|
|
use SprykerShop\Yves\CheckoutPage\GiftCard\GiftCardItemsCheckerInterface; |
|
25
|
|
|
use SprykerShop\Yves\CheckoutPage\Process\Steps\PostConditionCheckerInterface; |
|
26
|
|
|
use SprykerShop\Yves\CheckoutPage\Process\Steps\ShipmentStep; |
|
27
|
|
|
use SprykerShop\Yves\CheckoutPage\Process\Steps\ShipmentStep\PostConditionChecker; |
|
28
|
|
|
use SprykerShop\Yves\CheckoutPageExtension\Dependency\Plugin\CheckoutShipmentStepEnterPreCheckPluginInterface; |
|
29
|
|
|
use SprykerShop\Yves\QuoteApprovalWidget\Plugin\CheckoutPage\QuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPlugin; |
|
30
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Auto-generated group annotations |
|
34
|
|
|
* |
|
35
|
|
|
* @group PyzTest |
|
36
|
|
|
* @group Yves |
|
37
|
|
|
* @group Checkout |
|
38
|
|
|
* @group Process |
|
39
|
|
|
* @group Steps |
|
40
|
|
|
* @group ShipmentStepTest |
|
41
|
|
|
* Add your own group annotations below this line |
|
42
|
|
|
*/ |
|
43
|
|
|
class ShipmentStepTest extends Unit |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @var \PyzTest\Yves\Checkout\CheckoutBusinessTester |
|
47
|
|
|
*/ |
|
48
|
|
|
public $tester; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testShipmentStepExecuteShouldTriggerPlugins(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$shipmentPluginMock = $this->createShipmentMock(); |
|
56
|
|
|
$shipmentPluginMock->expects($this->once())->method('addToDataClass'); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$shipmentStepHandler = new StepHandlerPluginCollection(); |
|
59
|
|
|
$shipmentStepHandler->add($shipmentPluginMock, CheckoutPageDependencyProvider::PLUGIN_SHIPMENT_STEP_HANDLER); |
|
60
|
|
|
$shipmentStep = $this->createShipmentStep($shipmentStepHandler); |
|
61
|
|
|
|
|
62
|
|
|
$quoteTransfer = new QuoteTransfer(); |
|
63
|
|
|
|
|
64
|
|
|
$shipmentTransfer = new ShipmentTransfer(); |
|
65
|
|
|
$shipmentTransfer->setShipmentSelection(CheckoutPageDependencyProvider::PLUGIN_SHIPMENT_STEP_HANDLER); |
|
66
|
|
|
$quoteTransfer->setShipment($shipmentTransfer); |
|
67
|
|
|
|
|
68
|
|
|
$shipmentStep->execute($this->createRequest(), $quoteTransfer); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testShipmentPostConditionsShouldReturnTrueWhenShipmentSet(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$this->markTestSkipped('This test is skipped because it is no longer relevant after https://spryker.atlassian.net/browse/SUPESC-435.'); |
|
77
|
|
|
|
|
78
|
|
|
$quoteTransfer = new QuoteTransfer(); |
|
79
|
|
|
$expenseTransfer = new ExpenseTransfer(); |
|
80
|
|
|
$expenseTransfer->setType(ShipmentConfig::SHIPMENT_EXPENSE_TYPE); |
|
81
|
|
|
$quoteTransfer->addExpense($expenseTransfer); |
|
82
|
|
|
|
|
83
|
|
|
$shipmentStep = $this->createShipmentStep(new StepHandlerPluginCollection()); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertTrue($shipmentStep->postCondition($quoteTransfer)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param \Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginCollection $shipmentPlugins |
|
90
|
|
|
* |
|
91
|
|
|
* @return \SprykerShop\Yves\CheckoutPage\Process\Steps\ShipmentStep |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function createShipmentStep(StepHandlerPluginCollection $shipmentPlugins): ShipmentStep |
|
94
|
|
|
{ |
|
95
|
|
|
$giftCardItemsCheckerMock = $this->createGiftCardItemsCheckerMock(); |
|
96
|
|
|
|
|
97
|
|
|
return new ShipmentStep( |
|
98
|
|
|
$this->createCalculationClientMock(), |
|
99
|
|
|
$shipmentPlugins, |
|
100
|
|
|
$this->createShipmentStepPostConditionCheckerMock($giftCardItemsCheckerMock), |
|
|
|
|
|
|
101
|
|
|
$giftCardItemsCheckerMock, |
|
102
|
|
|
CheckoutPageDependencyProvider::PLUGIN_SHIPMENT_STEP_HANDLER, |
|
103
|
|
|
'escape_route', |
|
104
|
|
|
$this->getCheckoutShipmentStepEnterPreCheckPlugins(), |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return \Symfony\Component\HttpFoundation\Request |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function createRequest(): Request |
|
112
|
|
|
{ |
|
113
|
|
|
return Request::createFromGlobals(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return \SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToCalculationClientInterface |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function createCalculationClientMock(): CheckoutPageToCalculationClientInterface |
|
120
|
|
|
{ |
|
121
|
|
|
$calculationClientMock = $this->createMock(CheckoutPageToCalculationClientInterface::class); |
|
122
|
|
|
$calculationClientMock->method('recalculate') |
|
123
|
|
|
->willReturnArgument(0); |
|
124
|
|
|
|
|
125
|
|
|
return $calculationClientMock; |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return \Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginInterface |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function createShipmentMock(): StepHandlerPluginInterface |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->createMock(StepHandlerPluginInterface::class); |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceInterface $giftCardItemsCheckerMock |
|
138
|
|
|
* |
|
139
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Process\Steps\PostConditionCheckerInterface |
|
140
|
|
|
*/ |
|
141
|
|
|
protected function createShipmentStepPostConditionCheckerMock($giftCardItemsCheckerMock): PostConditionCheckerInterface |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->getMockBuilder(PostConditionChecker::class) |
|
|
|
|
|
|
144
|
|
|
->setConstructorArgs([$this->createShipmentServiceMock(), $giftCardItemsCheckerMock]) |
|
145
|
|
|
->enableProxyingToOriginalMethods() |
|
146
|
|
|
->getMock(); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\GiftCard\GiftCardItemsCheckerInterface |
|
151
|
|
|
*/ |
|
152
|
|
|
protected function createGiftCardItemsCheckerMock(): GiftCardItemsCheckerInterface |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->getMockBuilder(GiftCardItemsChecker::class) |
|
|
|
|
|
|
155
|
|
|
->enableProxyingToOriginalMethods() |
|
156
|
|
|
->getMock(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceInterface |
|
161
|
|
|
*/ |
|
162
|
|
|
protected function createShipmentServiceMock(): CheckoutPageToShipmentServiceInterface |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->getMockBuilder(CheckoutPageToShipmentServiceBridge::class) |
|
|
|
|
|
|
165
|
|
|
->setConstructorArgs([$this->tester->getShipmentService()]) |
|
166
|
|
|
->enableProxyingToOriginalMethods() |
|
167
|
|
|
->getMock(); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return array<\SprykerShop\Yves\CheckoutPageExtension\Dependency\Plugin\CheckoutShipmentStepEnterPreCheckPluginInterface> |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getCheckoutShipmentStepEnterPreCheckPlugins(): array |
|
174
|
|
|
{ |
|
175
|
|
|
return [ |
|
176
|
|
|
$this->getQuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPluginMock(), |
|
177
|
|
|
]; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPageExtension\Dependency\Plugin\CheckoutShipmentStepEnterPreCheckPluginInterface |
|
182
|
|
|
*/ |
|
183
|
|
|
protected function getQuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPluginMock(): CheckoutShipmentStepEnterPreCheckPluginInterface |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->getMockBuilder(QuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPlugin::class) |
|
|
|
|
|
|
186
|
|
|
->enableProxyingToOriginalMethods() |
|
187
|
|
|
->getMock(); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.