|
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\Zed\Product\Business; |
|
11
|
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\PriceProductTransfer; |
|
|
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\ProductConcreteTransfer; |
|
|
|
|
|
|
14
|
|
|
use Generated\Shared\Transfer\ProductImageSetTransfer; |
|
|
|
|
|
|
15
|
|
|
use Generated\Shared\Transfer\ProductImageTransfer; |
|
|
|
|
|
|
16
|
|
|
use Generated\Shared\Transfer\StockProductTransfer; |
|
|
|
|
|
|
17
|
|
|
use Orm\Zed\Product\Persistence\SpyProduct; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Auto-generated group annotations |
|
21
|
|
|
* |
|
22
|
|
|
* @group PyzTest |
|
23
|
|
|
* @group Zed |
|
24
|
|
|
* @group Product |
|
25
|
|
|
* @group Business |
|
26
|
|
|
* @group ProductConcreteManagerTest |
|
27
|
|
|
* Add your own group annotations below this line |
|
28
|
|
|
*/ |
|
29
|
|
|
class ProductConcreteManagerTest extends ProductTestAbstract |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testCreateProductConcreteShouldCreateProductAndTriggerPlugins(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$idProductAbstract = $this->productAbstractManager->createProductAbstract($this->productAbstractTransfer); |
|
37
|
|
|
$this->productConcreteTransfer->setFkProductAbstract($idProductAbstract); |
|
38
|
|
|
|
|
39
|
|
|
$idProductConcrete = $this->productConcreteManager->createProductConcrete($this->productConcreteTransfer); |
|
40
|
|
|
$this->productConcreteTransfer->setIdProductConcrete($idProductConcrete); |
|
41
|
|
|
$this->productConcreteTransfer->setFkProductAbstract($idProductAbstract); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertTrue($idProductConcrete > 0); |
|
44
|
|
|
$this->productConcreteTransfer->setIdProductConcrete($idProductConcrete); |
|
45
|
|
|
$this->assertCreateProductConcrete($this->productConcreteTransfer); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testSaveProductConcreteShouldUpdateProductAndTriggerPlugins(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$idProductAbstract = $this->productAbstractManager->createProductAbstract($this->productAbstractTransfer); |
|
54
|
|
|
$this->productConcreteTransfer->setFkProductAbstract($idProductAbstract); |
|
55
|
|
|
|
|
56
|
|
|
$idProductConcrete = $this->productConcreteManager->createProductConcrete($this->productConcreteTransfer); |
|
57
|
|
|
$this->productConcreteTransfer->setIdProductConcrete($idProductConcrete); |
|
58
|
|
|
$this->productConcreteTransfer->setFkProductAbstract($idProductAbstract); |
|
59
|
|
|
|
|
60
|
|
|
foreach ($this->productConcreteTransfer->getLocalizedAttributes() as $localizedAttribute) { |
|
61
|
|
|
$localizedAttribute->setName( |
|
62
|
|
|
self::UPDATED_PRODUCT_ABSTRACT_NAME[$localizedAttribute->getLocale()->getLocaleName()], |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$idProductConcrete = $this->productConcreteManager->saveProductConcrete($this->productConcreteTransfer); |
|
67
|
|
|
|
|
68
|
|
|
$this->productConcreteTransfer->setIdProductConcrete($idProductConcrete); |
|
69
|
|
|
$this->assertSaveProductConcrete($this->productConcreteTransfer); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testGetConcreteProductsByAbstractProductIdShouldReturnFullyLoadedTransferObject(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->setupDefaultProducts(); |
|
78
|
|
|
|
|
79
|
|
|
$concreteCollection = $this->productConcreteManager->getConcreteProductsByAbstractProductId( |
|
80
|
|
|
$this->productAbstractTransfer->getIdProductAbstract(), |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
foreach ($concreteCollection as $concreteProduct) { |
|
84
|
|
|
$this->assertReadProductConcrete($concreteProduct); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param int $idProductConcrete |
|
90
|
|
|
* |
|
91
|
|
|
* @return \Orm\Zed\Product\Persistence\SpyProduct |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getProductConcreteEntityById(int $idProductConcrete): SpyProduct |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->productQueryContainer |
|
96
|
|
|
->queryProduct() |
|
97
|
|
|
->filterByIdProduct($idProductConcrete) |
|
98
|
|
|
->findOne(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer |
|
103
|
|
|
* |
|
104
|
|
|
* @return void |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function assertCreateProductConcrete(ProductConcreteTransfer $productConcreteTransfer): void |
|
107
|
|
|
{ |
|
108
|
|
|
$createdProductEntity = $this->getProductConcreteEntityById($productConcreteTransfer->getIdProductConcrete()); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertNotNull($createdProductEntity); |
|
111
|
|
|
$this->assertSame($productConcreteTransfer->getSku(), $createdProductEntity->getSku()); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer |
|
116
|
|
|
* |
|
117
|
|
|
* @return void |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function assertSaveProductConcrete(ProductConcreteTransfer $productConcreteTransfer): void |
|
120
|
|
|
{ |
|
121
|
|
|
$updatedProductEntity = $this->getProductConcreteEntityById($productConcreteTransfer->getIdProductConcrete()); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertNotNull($updatedProductEntity); |
|
124
|
|
|
$this->assertSame($this->productConcreteTransfer->getSku(), $updatedProductEntity->getSku()); |
|
125
|
|
|
|
|
126
|
|
|
foreach ($productConcreteTransfer->getLocalizedAttributes() as $localizedAttribute) { |
|
127
|
|
|
$expectedProductName = self::UPDATED_PRODUCT_ABSTRACT_NAME[$localizedAttribute->getLocale()->getLocaleName()]; |
|
128
|
|
|
|
|
129
|
|
|
$this->assertSame($expectedProductName, $localizedAttribute->getName()); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer |
|
135
|
|
|
* |
|
136
|
|
|
* @return void |
|
137
|
|
|
*/ |
|
138
|
|
|
protected function assertReadProductConcrete(ProductConcreteTransfer $productConcreteTransfer): void |
|
139
|
|
|
{ |
|
140
|
|
|
$this->assertProductPrice($productConcreteTransfer); |
|
141
|
|
|
$this->assertProductStock($productConcreteTransfer); |
|
142
|
|
|
$this->assertProductImages($productConcreteTransfer); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer |
|
147
|
|
|
* |
|
148
|
|
|
* @return void |
|
149
|
|
|
*/ |
|
150
|
|
|
protected function assertProductPrice(ProductConcreteTransfer $productConcreteTransfer): void |
|
151
|
|
|
{ |
|
152
|
|
|
foreach ($productConcreteTransfer->getPrices() as $priceProductTransfer) { |
|
153
|
|
|
$this->assertInstanceOf(PriceProductTransfer::class, $priceProductTransfer); |
|
154
|
|
|
$this->assertNotNull($priceProductTransfer->getIdProduct()); |
|
155
|
|
|
$this->assertNotNull($priceProductTransfer->getPriceTypeName()); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer |
|
161
|
|
|
* |
|
162
|
|
|
* @return void |
|
163
|
|
|
*/ |
|
164
|
|
|
protected function assertProductStock(ProductConcreteTransfer $productConcreteTransfer): void |
|
165
|
|
|
{ |
|
166
|
|
|
$stockCollection = $productConcreteTransfer->getStocks(); |
|
167
|
|
|
|
|
168
|
|
|
foreach ($stockCollection as $stock) { |
|
169
|
|
|
$this->assertInstanceOf(StockProductTransfer::class, $stock); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer |
|
175
|
|
|
* |
|
176
|
|
|
* @return void |
|
177
|
|
|
*/ |
|
178
|
|
|
protected function assertProductImages(ProductConcreteTransfer $productConcreteTransfer): void |
|
179
|
|
|
{ |
|
180
|
|
|
/** @var array<\Generated\Shared\Transfer\ProductImageSetTransfer> $imageSetCollection */ |
|
181
|
|
|
$imageSetCollection = (array)$productConcreteTransfer->getImageSets(); |
|
182
|
|
|
$this->assertNotEmpty($imageSetCollection); |
|
183
|
|
|
|
|
184
|
|
|
/** @var \Generated\Shared\Transfer\ProductImageSetTransfer $imageSet */ |
|
185
|
|
|
$imageSet = $imageSetCollection[0]; |
|
186
|
|
|
$this->assertInstanceOf(ProductImageSetTransfer::class, $imageSet); |
|
187
|
|
|
$this->assertNotNull($imageSet->getIdProductImageSet()); |
|
188
|
|
|
$this->assertSame($productConcreteTransfer->getIdProductConcrete(), $imageSet->getIdProduct()); |
|
189
|
|
|
|
|
190
|
|
|
$productImageCollection = (array)$imageSet->getProductImages(); |
|
191
|
|
|
$this->assertNotEmpty($imageSetCollection); |
|
192
|
|
|
|
|
193
|
|
|
/** @var \Generated\Shared\Transfer\ProductImageTransfer $productImage */ |
|
194
|
|
|
$productImage = $productImageCollection[0]; |
|
195
|
|
|
$this->assertInstanceOf(ProductImageTransfer::class, $productImage); |
|
196
|
|
|
$this->assertSame(self::IMAGE_URL_LARGE, $productImage->getExternalUrlLarge()); |
|
197
|
|
|
$this->assertSame(self::IMAGE_URL_SMALL, $productImage->getExternalUrlSmall()); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths