Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: cover NoSuchEntityException handling in InvalidSkuProcessor
  • Loading branch information
kapil971390 committed Nov 17, 2026
commit eb592e269275e12b61c7eeb4e348961b0ebca001
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor;
use Magento\Catalog\Model\Product\Type;
use Magento\Catalog\Model\ProductIdLocatorInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -98,4 +99,73 @@ public function testRetrieveInvalidSkuList()
$this->invalidSkuProcessor->retrieveInvalidSkuList($skus, $allowedProductTypes, $allowedPriceTypeValue)
);
}

/**
* A bundle product can be deleted between the retrieveProductIdsBySkus() lookup and the
* productRepository->get() call a few lines later. Before this fix, the resulting
* NoSuchEntityException propagated uncaught and failed the whole batch instead of just
* this one SKU.
*
* @return void
*/
public function testRetrieveInvalidSkuListWhenBundleProductDeletedConcurrently()
{
$deletedSku = 'DELETED-BUNDLE-SKU';
$idsBySku = [$deletedSku => [235235235 => Type::TYPE_BUNDLE]];
$this->productIdLocator->expects($this->atLeastOnce())->method('retrieveProductIdsBySkus')
->willReturn($idsBySku);
$this->productRepository->expects($this->atLeastOnce())->method('get')
->willThrowException(new NoSuchEntityException());

// array_values(): retrieveInvalidSkuList() never guarantees zero-based
// keys (array_udiff()'s internal next-index counter isn't reset just
// because the filtered result is empty) and no caller relies on the
// keys, only the values -- same as filterSkuList()'s own array_diff().
$this->assertEquals(
[$deletedSku],
array_values($this->invalidSkuProcessor->retrieveInvalidSkuList(
[$deletedSku],
[Type::TYPE_BUNDLE],
true
))
);
}

/**
* One bundle product being deleted mid-batch must not stop the rest of the batch from
* being processed normally.
*
* @return void
*/
public function testRetrieveInvalidSkuListContinuesBatchWhenOneBundleProductIsDeletedConcurrently()
{
$deletedSku = 'DELETED-BUNDLE-SKU';
$validSku = 'VALID-BUNDLE-SKU';
$idsBySku = [
$deletedSku => [235235235 => Type::TYPE_BUNDLE],
$validSku => [235235236 => Type::TYPE_BUNDLE],
];
$this->productIdLocator->expects($this->atLeastOnce())->method('retrieveProductIdsBySkus')
->willReturn($idsBySku);

$validProduct = $this->createPartialMockWithReflection(Product::class, ['getPriceType']);
$validProduct->method('getPriceType')->willReturn(true);

$this->productRepository->method('get')
->willReturnCallback(function ($sku) use ($deletedSku, $validProduct) {
if ($sku === $deletedSku) {
throw new NoSuchEntityException();
}
return $validProduct;
});

$this->assertEquals(
[$deletedSku],
array_values($this->invalidSkuProcessor->retrieveInvalidSkuList(
[$deletedSku, $validSku],
[Type::TYPE_BUNDLE],
true
))
);
}
}