1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||||||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||||||
6 | */ |
||||||
7 | |||||||
8 | namespace SprykerTest\Zed\Availability\Business\Model; |
||||||
9 | |||||||
10 | use Codeception\Test\Unit; |
||||||
11 | use Generated\Shared\Transfer\StoreTransfer; |
||||||
12 | use Spryker\DecimalObject\Decimal; |
||||||
13 | use Spryker\Zed\Availability\Business\Model\AvailabilityHandler; |
||||||
14 | use Spryker\Zed\Availability\Business\Model\AvailabilityHandlerInterface; |
||||||
15 | use Spryker\Zed\Availability\Business\Model\ProductAvailabilityCalculatorInterface; |
||||||
16 | use Spryker\Zed\Availability\Dependency\Facade\AvailabilityToEventFacadeInterface; |
||||||
17 | use Spryker\Zed\Availability\Dependency\Facade\AvailabilityToOmsFacadeInterface; |
||||||
18 | use Spryker\Zed\Availability\Dependency\Facade\AvailabilityToProductFacadeInterface; |
||||||
19 | use Spryker\Zed\Availability\Dependency\Facade\AvailabilityToStockFacadeInterface; |
||||||
20 | use Spryker\Zed\Availability\Dependency\Facade\AvailabilityToTouchFacadeInterface; |
||||||
21 | use Spryker\Zed\Availability\Persistence\AvailabilityEntityManagerInterface; |
||||||
22 | use Spryker\Zed\Availability\Persistence\AvailabilityRepositoryInterface; |
||||||
23 | |||||||
24 | /** |
||||||
25 | * Auto-generated group annotations |
||||||
26 | * |
||||||
27 | * @group SprykerTest |
||||||
28 | * @group Zed |
||||||
29 | * @group Availability |
||||||
30 | * @group Business |
||||||
31 | * @group Model |
||||||
32 | * @group AvailabilityHandlerTest |
||||||
33 | * Add your own group annotations below this line |
||||||
34 | */ |
||||||
35 | class AvailabilityHandlerTest extends Unit |
||||||
36 | { |
||||||
37 | /** |
||||||
38 | * @var string |
||||||
39 | */ |
||||||
40 | public const PRODUCT_ABSTRACT_SKU = 'sku-123'; |
||||||
41 | |||||||
42 | /** |
||||||
43 | * @var string |
||||||
44 | */ |
||||||
45 | public const PRODUCT_SKU = 'sku-123-321'; |
||||||
46 | |||||||
47 | /** |
||||||
48 | * @var string |
||||||
49 | */ |
||||||
50 | protected const STORE_NAME = 'DE'; |
||||||
51 | |||||||
52 | /** |
||||||
53 | * @var \SprykerTest\Zed\Availability\AvailabilityBusinessTester |
||||||
54 | */ |
||||||
55 | protected $tester; |
||||||
56 | |||||||
57 | /** |
||||||
58 | * @return void |
||||||
59 | */ |
||||||
60 | public function testUpdateAvailabilityShouldTouchWhenStockUpdated(): void |
||||||
61 | { |
||||||
62 | $productTransfer = $this->tester->haveProduct(); |
||||||
63 | $availabilityCalculatorMock = $this->createAvailabilityCalculatorMock(); |
||||||
64 | $availabilityCalculatorMock->method('calculateAvailabilityForProductConcrete')->willReturn(new Decimal(15)); |
||||||
0 ignored issues
–
show
|
|||||||
65 | |||||||
66 | $availabilityRepositoryMock = $this->createAvailabilityRepositoryMock(); |
||||||
67 | $availabilityRepositoryMock->method('getAbstractSkuFromProductConcrete') |
||||||
0 ignored issues
–
show
The method
method() does not exist on Spryker\Zed\Availability...lityRepositoryInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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.
Loading history...
|
|||||||
68 | ->willReturn($productTransfer->getAbstractSku()); |
||||||
69 | $availabilityRepositoryMock->method('findIdProductAbstractAvailabilityBySku') |
||||||
70 | ->willReturn($productTransfer->getFkProductAbstract()); |
||||||
71 | |||||||
72 | $availabilityEntityManagerMock = $this->createAvailabilityEntityManagerMock(); |
||||||
73 | $availabilityEntityManagerMock->method('saveProductConcreteAvailability') |
||||||
0 ignored issues
–
show
The method
method() does not exist on Spryker\Zed\Availability...yEntityManagerInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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.
Loading history...
|
|||||||
74 | ->willReturn(true); |
||||||
75 | |||||||
76 | $stockFacadeMock = $this->createAvailabilityToStockFacadeMock(); |
||||||
77 | $stockFacadeMock->method('getStoresWhereProductStockIsDefined') |
||||||
78 | ->willReturn([$this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME])]); |
||||||
79 | |||||||
80 | $touchFacadeMock = $this->createTouchFacadeMock(); |
||||||
81 | $touchFacadeMock->expects($this->once())->method('touchActive'); |
||||||
82 | |||||||
83 | $availabilityHandler = $this->createAvailabilityHandler( |
||||||
84 | $availabilityRepositoryMock, |
||||||
85 | $availabilityEntityManagerMock, |
||||||
86 | $availabilityCalculatorMock, |
||||||
87 | $touchFacadeMock, |
||||||
88 | $stockFacadeMock, |
||||||
89 | ); |
||||||
90 | |||||||
91 | $availabilityHandler->updateAvailability($productTransfer->getSku()); |
||||||
92 | } |
||||||
93 | |||||||
94 | /** |
||||||
95 | * @return void |
||||||
96 | */ |
||||||
97 | public function testUpdateAvailabilityShouldTouchAndUpdate(): void |
||||||
98 | { |
||||||
99 | $availabilityCalculatorMock = $this->createAvailabilityCalculatorMock(); |
||||||
100 | $availabilityCalculatorMock->method('calculateAvailabilityForProductConcrete')->willReturn(new Decimal(5)); |
||||||
101 | |||||||
102 | $availabilityRepositoryMock = $this->createAvailabilityRepositoryMock(); |
||||||
103 | $availabilityRepositoryMock->method('getAbstractSkuFromProductConcrete') |
||||||
104 | ->willReturn(static::PRODUCT_ABSTRACT_SKU); |
||||||
105 | $availabilityRepositoryMock->method('findIdProductAbstractAvailabilityBySku') |
||||||
106 | ->willReturn(123); |
||||||
107 | |||||||
108 | $availabilityEntityManagerMock = $this->createAvailabilityEntityManagerMock(); |
||||||
109 | $availabilityEntityManagerMock->method('saveProductConcreteAvailability') |
||||||
110 | ->willReturn(true); |
||||||
111 | |||||||
112 | $stockFacadeMock = $this->createAvailabilityToStockFacadeMock(); |
||||||
113 | $stockFacadeMock->method('getStoresWhereProductStockIsDefined') |
||||||
114 | ->willReturn([$this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME])]); |
||||||
115 | |||||||
116 | $touchFacadeMock = $this->createTouchFacadeMock(); |
||||||
117 | $touchFacadeMock->expects($this->once())->method('touchActive'); |
||||||
118 | |||||||
119 | $availabilityHandler = $this->createAvailabilityHandler( |
||||||
120 | $availabilityRepositoryMock, |
||||||
121 | $availabilityEntityManagerMock, |
||||||
122 | $availabilityCalculatorMock, |
||||||
123 | $touchFacadeMock, |
||||||
124 | $stockFacadeMock, |
||||||
125 | ); |
||||||
126 | |||||||
127 | $availabilityHandler->updateAvailability(static::PRODUCT_SKU); |
||||||
128 | } |
||||||
129 | |||||||
130 | /** |
||||||
131 | * @param \Spryker\Zed\Availability\Persistence\AvailabilityRepositoryInterface $availabilityRepositoryMock |
||||||
132 | * @param \Spryker\Zed\Availability\Persistence\AvailabilityEntityManagerInterface $availabilityEntityManagerMock |
||||||
133 | * @param \Spryker\Zed\Availability\Business\Model\ProductAvailabilityCalculatorInterface $availabilityCalculatorMock |
||||||
134 | * @param \Spryker\Zed\Availability\Dependency\Facade\AvailabilityToTouchFacadeInterface $touchFacade |
||||||
135 | * @param \Spryker\Zed\Availability\Dependency\Facade\AvailabilityToStockFacadeInterface|null $availabilityToStockFacade |
||||||
136 | * @param \Spryker\Zed\Availability\Dependency\Facade\AvailabilityToEventFacadeInterface|null $availabilityToEventFacade |
||||||
137 | * |
||||||
138 | * @return \Spryker\Zed\Availability\Business\Model\AvailabilityHandlerInterface |
||||||
139 | */ |
||||||
140 | protected function createAvailabilityHandler( |
||||||
141 | AvailabilityRepositoryInterface $availabilityRepositoryMock, |
||||||
142 | AvailabilityEntityManagerInterface $availabilityEntityManagerMock, |
||||||
143 | ProductAvailabilityCalculatorInterface $availabilityCalculatorMock, |
||||||
144 | AvailabilityToTouchFacadeInterface $touchFacade, |
||||||
145 | ?AvailabilityToStockFacadeInterface $availabilityToStockFacade = null, |
||||||
146 | ?AvailabilityToEventFacadeInterface $availabilityToEventFacade = null |
||||||
147 | ): AvailabilityHandlerInterface { |
||||||
148 | if ($availabilityToStockFacade === null) { |
||||||
149 | $availabilityToStockFacade = $this->createAvailabilityToStockFacadeMock(); |
||||||
150 | } |
||||||
151 | |||||||
152 | if ($availabilityToEventFacade === null) { |
||||||
153 | $availabilityToEventFacade = $this->createAvailabilityToEventFacade(); |
||||||
154 | } |
||||||
155 | |||||||
156 | return new AvailabilityHandler( |
||||||
157 | $availabilityRepositoryMock, |
||||||
158 | $availabilityEntityManagerMock, |
||||||
159 | $availabilityCalculatorMock, |
||||||
160 | $touchFacade, |
||||||
161 | $availabilityToStockFacade, |
||||||
162 | $availabilityToEventFacade, |
||||||
163 | $this->getProductFacadeMock(), |
||||||
164 | ); |
||||||
165 | } |
||||||
166 | |||||||
167 | /** |
||||||
168 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Dependency\Facade\AvailabilityToOmsFacadeInterface |
||||||
169 | */ |
||||||
170 | protected function createOmsFacadeMock(): AvailabilityToOmsFacadeInterface |
||||||
171 | { |
||||||
172 | return $this->getMockBuilder(AvailabilityToOmsFacadeInterface::class) |
||||||
173 | ->getMock(); |
||||||
174 | } |
||||||
175 | |||||||
176 | /** |
||||||
177 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Dependency\Facade\AvailabilityToTouchFacadeInterface |
||||||
178 | */ |
||||||
179 | protected function createTouchFacadeMock(): AvailabilityToTouchFacadeInterface |
||||||
180 | { |
||||||
181 | return $this->getMockBuilder(AvailabilityToTouchFacadeInterface::class) |
||||||
182 | ->getMock(); |
||||||
183 | } |
||||||
184 | |||||||
185 | /** |
||||||
186 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Business\Model\ProductAvailabilityCalculatorInterface |
||||||
187 | */ |
||||||
188 | protected function createAvailabilityCalculatorMock(): ProductAvailabilityCalculatorInterface |
||||||
189 | { |
||||||
190 | return $this->getMockBuilder(ProductAvailabilityCalculatorInterface::class) |
||||||
191 | ->getMock(); |
||||||
192 | } |
||||||
193 | |||||||
194 | /** |
||||||
195 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Persistence\AvailabilityRepositoryInterface |
||||||
196 | */ |
||||||
197 | protected function createAvailabilityRepositoryMock(): AvailabilityRepositoryInterface |
||||||
198 | { |
||||||
199 | return $this->getMockBuilder(AvailabilityRepositoryInterface::class) |
||||||
200 | ->getMock(); |
||||||
201 | } |
||||||
202 | |||||||
203 | /** |
||||||
204 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Persistence\AvailabilityEntityManagerInterface |
||||||
205 | */ |
||||||
206 | protected function createAvailabilityEntityManagerMock(): AvailabilityEntityManagerInterface |
||||||
207 | { |
||||||
208 | return $this->getMockBuilder(AvailabilityEntityManagerInterface::class) |
||||||
209 | ->getMock(); |
||||||
210 | } |
||||||
211 | |||||||
212 | /** |
||||||
213 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Dependency\Facade\AvailabilityToEventFacadeInterface |
||||||
214 | */ |
||||||
215 | protected function createAvailabilityToEventFacade(): AvailabilityToEventFacadeInterface |
||||||
216 | { |
||||||
217 | return $this->getMockBuilder(AvailabilityToEventFacadeInterface::class) |
||||||
218 | ->getMock(); |
||||||
219 | } |
||||||
220 | |||||||
221 | /** |
||||||
222 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Dependency\Facade\AvailabilityToProductFacadeInterface |
||||||
223 | */ |
||||||
224 | protected function getProductFacadeMock(): AvailabilityToProductFacadeInterface |
||||||
225 | { |
||||||
226 | return $this->getMockBuilder(AvailabilityToProductFacadeInterface::class) |
||||||
227 | ->getMock(); |
||||||
228 | } |
||||||
229 | |||||||
230 | /** |
||||||
231 | * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Availability\Dependency\Facade\AvailabilityToStockFacadeInterface |
||||||
232 | */ |
||||||
233 | protected function createAvailabilityToStockFacadeMock(): AvailabilityToStockFacadeInterface |
||||||
234 | { |
||||||
235 | return $this->getMockBuilder(AvailabilityToStockFacadeInterface::class) |
||||||
236 | ->getMock(); |
||||||
237 | } |
||||||
238 | } |
||||||
239 |
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.