17 private $attributeResource;
22 private $attributeRepository;
27 private $productAttribute;
32 private $productIdLocator;
42 private $metadataPool;
56 $this->attributeResource = $this->getMockBuilder(\
Magento\Catalog\Model\
ResourceModel\Attribute::class)
57 ->disableOriginalConstructor()->getMock();
58 $this->attributeRepository = $this->getMockBuilder(
59 \
Magento\Catalog\Api\ProductAttributeRepositoryInterface::class
61 ->disableOriginalConstructor()
62 ->getMockForAbstractClass();
63 $this->productIdLocator = $this->getMockBuilder(\
Magento\Catalog\Model\ProductIdLocatorInterface::class)
64 ->disableOriginalConstructor()->getMockForAbstractClass();
65 $this->metadataPool = $this->getMockBuilder(\
Magento\Framework\EntityManager\MetadataPool::class)
66 ->disableOriginalConstructor()
67 ->setMethods([
'getLinkField',
'getMetadata'])
69 $this->connection = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
70 ->disableOriginalConstructor()->getMockForAbstractClass();
71 $this->productAttribute = $this->getMockBuilder(\
Magento\Catalog\Api\Data\ProductAttributeInterface::class)
72 ->disableOriginalConstructor()->getMockForAbstractClass();
74 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
78 'attributeResource' => $this->attributeResource,
79 'attributeRepository' => $this->attributeRepository,
80 'productIdLocator' => $this->productIdLocator,
81 'metadataPool' => $this->metadataPool,
94 $skus = [
'sku_1',
'sku_2'];
97 1 => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
100 2 => \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
103 $select = $this->getMockBuilder(\
Magento\Framework\DB\Select::class)
104 ->disableOriginalConstructor()->getMock();
105 $this->productIdLocator
106 ->expects($this->once())
107 ->method(
'retrieveProductIdsBySkus')->with(
$skus)
108 ->willReturn($idsBySku);
109 $this->attributeResource->expects($this->atLeastOnce())->method(
'getConnection')->willReturn($this->connection);
110 $this->connection->expects($this->once())->method(
'select')->willReturn(
$select);
111 $this->attributeResource
112 ->expects($this->once())
114 ->with(
'catalog_product_entity_decimal')
115 ->willReturn(
'catalog_product_entity_decimal');
116 $select->expects($this->once())->method(
'from')->with(
'catalog_product_entity_decimal')->willReturnSelf();
117 $this->attributeRepository->expects($this->once())->method(
'get')->willReturn($this->productAttribute);
118 $this->productAttribute->expects($this->once())->method(
'getAttributeId')->willReturn($attributeId);
120 ->expects($this->atLeastOnce())
122 ->withConsecutive([
'row_id IN (?)', [1, 2]], [
'attribute_id = ?', $attributeId])
124 $this->metadataPool->expects($this->atLeastOnce())->method(
'getMetadata')->willReturnSelf();
125 $this->metadataPool->expects($this->atLeastOnce())->method(
'getLinkField')->willReturn(
'row_id');
126 $this->model->get(
$skus);
144 $this->attributeRepository->expects($this->once())->method(
'get')->willReturn($this->productAttribute);
145 $this->productAttribute->expects($this->once())->method(
'getAttributeId')->willReturn($attributeId);
146 $this->attributeResource->expects($this->atLeastOnce())->method(
'getConnection')->willReturn($this->connection);
147 $this->connection->expects($this->once())->method(
'beginTransaction')->willReturnSelf();
148 $this->attributeResource
149 ->expects($this->once())
151 ->with(
'catalog_product_entity_decimal')
152 ->willReturn(
'catalog_product_entity_decimal');
154 ->expects($this->once())
155 ->method(
'insertOnDuplicate')
157 'catalog_product_entity_decimal',
169 $this->connection->expects($this->once())->method(
'commit')->willReturnSelf();
189 $this->attributeRepository->expects($this->once())->method(
'get')->willReturn($this->productAttribute);
190 $this->productAttribute->expects($this->once())->method(
'getAttributeId')->willReturn($attributeId);
191 $this->attributeResource->expects($this->atLeastOnce())->method(
'getConnection')->willReturn($this->connection);
192 $this->connection->expects($this->once())->method(
'beginTransaction')->willReturnSelf();
193 $this->attributeResource
194 ->expects($this->once())
196 ->with(
'catalog_product_entity_decimal')
197 ->willReturn(
'catalog_product_entity_decimal');
199 ->expects($this->once())
200 ->method(
'insertOnDuplicate')
202 'catalog_product_entity_decimal',
214 $this->connection->expects($this->once())->method(
'commit')->willThrowException(
new \
Exception());
215 $this->connection->expects($this->once())->method(
'rollback')->willReturnSelf();
227 $skus = [
'sku_1',
'sku_2'];
230 1 => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
233 2 => \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
236 $this->productIdLocator
237 ->expects($this->once())
238 ->method(
'retrieveProductIdsBySkus')->with(
$skus)
239 ->willReturn($idsBySku);
240 $this->attributeRepository->expects($this->once())->method(
'get')->willReturn($this->productAttribute);
241 $this->productAttribute->expects($this->once())->method(
'getAttributeId')->willReturn($attributeId);
242 $this->attributeResource->expects($this->atLeastOnce())->method(
'getConnection')->willReturn($this->connection);
243 $this->connection->expects($this->once())->method(
'beginTransaction')->willReturnSelf();
244 $this->attributeResource
245 ->expects($this->once())
247 ->with(
'catalog_product_entity_decimal')
248 ->willReturn(
'catalog_product_entity_decimal');
250 ->expects($this->once())
253 'catalog_product_entity_decimal',
255 'attribute_id = ?' => $attributeId,
256 'row_id IN (?)' => [1, 2]
260 $this->connection->expects($this->once())->method(
'commit')->willReturnSelf();
261 $this->metadataPool->expects($this->atLeastOnce())->method(
'getMetadata')->willReturnSelf();
262 $this->metadataPool->expects($this->atLeastOnce())->method(
'getLinkField')->willReturn(
'row_id');
263 $this->model->delete(
$skus);
275 $skus = [
'sku_1',
'sku_2'];
278 1 => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
281 2 => \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
284 $this->productIdLocator
285 ->expects($this->once())
286 ->method(
'retrieveProductIdsBySkus')->with(
$skus)
287 ->willReturn($idsBySku);
288 $this->attributeRepository->expects($this->once())->method(
'get')->willReturn($this->productAttribute);
289 $this->productAttribute->expects($this->once())->method(
'getAttributeId')->willReturn($attributeId);
290 $this->attributeResource->expects($this->atLeastOnce(2))->method(
'getConnection')
291 ->willReturn($this->connection);
292 $this->connection->expects($this->once())->method(
'beginTransaction')->willReturnSelf();
293 $this->attributeResource
294 ->expects($this->once())
296 ->with(
'catalog_product_entity_decimal')
297 ->willReturn(
'catalog_product_entity_decimal');
299 ->expects($this->once())
302 'catalog_product_entity_decimal',
304 'attribute_id = ?' => $attributeId,
305 'row_id IN (?)' => [1, 2]
309 $this->connection->expects($this->once())->method(
'commit')->willThrowException(
new \
Exception());
310 $this->connection->expects($this->once())->method(
'rollBack')->willReturnSelf();
311 $this->metadataPool->expects($this->atLeastOnce())->method(
'getMetadata')->willReturnSelf();
312 $this->metadataPool->expects($this->atLeastOnce())->method(
'getLinkField')->willReturn(
'row_id');
313 $this->model->delete(
$skus);
326 $this->productIdLocator
327 ->expects($this->once())
328 ->method(
'retrieveProductIdsBySkus')
331 $this->assertEquals($expectedResult, $this->model->retrieveSkuById(
$id,
$skus));
345 [
'sku_1' => [1 => 1]]
350 [
'sku_1' => [1 => 1]]
355 [
'sku_1' => [2 => 1]]
testUpdateWithException()
testDeleteWithException()
foreach($websiteCodes as $websiteCode) $skus
testRetrieveSkuById($expectedResult, $id, array $skus)
dataProviderRetrieveSkuById()