Skip to content

Commit e80819f

Browse files
committed
ACP2E-3009: async.operations.all executed and created an error.
1 parent ef6d9c8 commit e80819f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

app/code/Magento/Catalog/Model/ProductLink/Repository.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ public function __construct(
133133
*/
134134
public function save(\Magento\Catalog\Api\Data\ProductLinkInterface $entity)
135135
{
136+
if (!$entity->getSku()) {
137+
throw new NoSuchEntityException(__('ProductSku should be specified'));
138+
}
136139
if (!$entity->getLinkedProductSku()) {
137140
throw new NoSuchEntityException(__('The linked product SKU is invalid. Verify the data and try again.'));
138141
}

app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testSave()
132132
['linkedProduct', false, null, false, $linkedProductMock],
133133
]);
134134
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('linkedProduct');
135-
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
135+
$entityMock->expects($this->exactly(2))->method('getSku')->willReturn('product');
136136
$entityMock->expects($this->exactly(1))->method('getLinkType')->willReturn('linkType');
137137
$this->linkTypeProvider->expects($this->once())->method('getLinkTypes')->willReturn(['linkType' => $typeId]);
138138
$this->metadataPoolMock->expects($this->once())->method('getHydrator')->willReturn($this->hydratorMock);
@@ -164,7 +164,7 @@ public function testSaveWithException()
164164
['linkedProduct', false, null, false, $linkedProductMock],
165165
]);
166166
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('linkedProduct');
167-
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
167+
$entityMock->expects($this->exactly(2))->method('getSku')->willReturn('product');
168168
$entityMock->expects($this->exactly(1))->method('getLinkType')->willReturn('linkType');
169169
$this->linkTypeProvider->expects($this->once())->method('getLinkTypes')->willReturn(['linkType' => $typeId]);
170170
$this->metadataPoolMock->expects($this->once())->method('getHydrator')->willReturn($this->hydratorMock);
@@ -185,10 +185,21 @@ public function testSaveWithoutLinkedProductSku()
185185
$this->expectException('Magento\Framework\Exception\NoSuchEntityException');
186186
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
187187
$entityMock = $this->createMock(\Magento\Catalog\Model\ProductLink\Link::class);
188+
$entityMock->expects($this->any())->method('getSku')->willReturn('sku1');
188189
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('');
189190
$this->model->save($entityMock);
190191
}
191192

193+
public function testSaveWithoutProductSku()
194+
{
195+
$this->expectException('Magento\Framework\Exception\NoSuchEntityException');
196+
$this->expectExceptionMessage('ProductSku should be specified');
197+
$entityMock = $this->createMock(\Magento\Catalog\Model\ProductLink\Link::class);
198+
$entityMock->expects($this->any())->method('getSku')->willReturn('');
199+
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn('linkedProductSku');
200+
$this->model->save($entityMock);
201+
}
202+
192203
/**
193204
* Test method
194205
*/

0 commit comments

Comments
 (0)