From 284ca91e992c939e5f522bfe62d3ff66b838ea21 Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Wed, 23 Jul 2025 15:06:58 +0100 Subject: [PATCH 01/11] fix: Add SKU or ID to NoSuchEntityException in ProductRepository (fixes #40090) --- app/code/Magento/Catalog/Model/ProductRepository.php | 4 ++-- .../Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index 4343917f250a0..e0d8dab0e80ae 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -285,7 +285,7 @@ public function get($sku, $editMode = false, $storeId = null, $forceReload = fal $productId = $this->resourceModel->getIdBySku($sku); if (!$productId) { throw new NoSuchEntityException( - __("The product that was requested doesn't exist. Verify the product and try again.") + __("The product with SKU \"%1\" does not exist.", $sku) ); } if ($editMode) { @@ -319,7 +319,7 @@ public function getById($productId, $editMode = false, $storeId = null, $forceRe $product->load($productId); if (!$product->getId()) { throw new NoSuchEntityException( - __("The product that was requested doesn't exist. Verify the product and try again.") + __("The product with ID \"%1\" does not exist.", $productId) ); } $this->cacheProduct($cacheKey, $product); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php index e201f46287d67..7b9b4f11d1c07 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php @@ -440,7 +440,7 @@ public function testGetAbsentProduct(): void { $this->expectException('Magento\Framework\Exception\NoSuchEntityException'); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "test_sku" does not exist.' ); $this->productFactory->expects($this->once())->method('create') ->willReturn($this->product); @@ -521,7 +521,7 @@ public function testGetByIdAbsentProduct(): void { $this->expectException('Magento\Framework\Exception\NoSuchEntityException'); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with ID "product_id" does not exist.' ); $this->productFactory->expects($this->once())->method('create') ->willReturn($this->product); From a4bf82fa4b7ff156a9937819a8a18bcc8b5f92d3 Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Wed, 23 Jul 2025 17:42:08 +0100 Subject: [PATCH 02/11] fix: Add SKU or ID to NoSuchEntityException in ProductRepository (fixes #40090) - Update --- .../Catalog/Test/Unit/Model/ProductLink/ManagementTest.php | 4 ++-- ...ProductAttributeMediaGalleryManagementInterfaceTest.php | 6 +++--- .../Catalog/Api/_files/product_options_update_negative.php | 2 +- .../ConfigurableProduct/Api/OptionRepositoryTest.php | 2 +- .../ConfigurableProduct/Api/ProductRepositoryTest.php | 4 ++-- .../Magento/Downloadable/Api/LinkRepositoryTest.php | 7 ++++--- .../Magento/Downloadable/Api/SampleRepositoryTest.php | 4 ++-- .../Magento/GraphQl/SendFriend/SendFriendTest.php | 4 ++-- .../Controller/Adminhtml/Product/Set/DeleteTest.php | 2 +- .../Quote/Model/Quote/Item/CartItemPersisterTest.php | 2 +- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php index e98c129fa9884..037af6a39115d 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php @@ -289,13 +289,13 @@ public function testSetProductLinksNoProductException() ->method('get') ->willThrowException( new NoSuchEntityException( - __("The product that was requested doesn't exist. Verify the product and try again.") + __('The product with SKU "' . $productSku . '" does not exist.') ) ); $this->expectException(NoSuchEntityException::class); $this->expectExceptionMessage( - "The product that was requested doesn't exist. Verify the product and try again." + 'The product with SKU " ' . $productSku . ' " does not exist.' ); $this->model->setProductLinks($productSku, $links); diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index 85a4f91fdb962..ca94a2dad22ab 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -500,7 +500,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "wrong_product_sku" does not exist.' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media'; @@ -557,7 +557,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "wrong_product_sku" does not exist..' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media' @@ -613,7 +613,7 @@ public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "wrong_product_sku" does not exist.' ); $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999'; diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php index b10957dcb7ed2..5de648df469b9 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php @@ -29,7 +29,7 @@ 'product_sku' => 'sku1', 'max_characters' => 10, ], - 'The product that was requested doesn\'t exist. Verify the product and try again.', + 'The product with SKU "sku1" does not exist.', 404, ], ]; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php index 8c9d6f35075e0..f5b35738e0a7f 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php @@ -102,7 +102,7 @@ public function testGetUndefinedProduct(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "product_not_exist" does not exist.' ); $productSku = 'product_not_exist'; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php index e1fdf4a1a42f6..9b94cbfab2c3c 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php @@ -383,7 +383,7 @@ public function testUpdateConfigurableProductLinksWithNonExistingProduct() $nonExistingId, ]; - $expectedMessage = 'The product that was requested doesn\'t exist. Verify the product and try again.'; + $expectedMessage = 'The product with SKU "wrong_product_sku" does not exist.'; try { $this->saveProduct($response); $this->fail("Expected exception"); @@ -461,7 +461,7 @@ public function testUpdateConfigurableProductLinksWithWithoutVariationAttributes $productId2, ]; - $expectedMessage = 'The product that was requested doesn\'t exist. Verify the product and try again.'; + $expectedMessage = 'The product with SKU "product_not_exist" does not exist.'; try { $this->saveProduct($response); $this->fail("Expected exception"); diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php index 3f7ccca9236da..b6ab006e6967b 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php @@ -751,7 +751,8 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "wrong-sku" does not exist.' + ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/1'; @@ -1001,7 +1002,7 @@ public function testGetListForAbsentProduct($urlTail, $method) $requestData = ['sku' => $sku]; - $expectedMessage = "The product that was requested doesn't exist. Verify the product and try again."; + $expectedMessage = 'The product with SKU "' . $sku . '" does not exist.'; try { $this->_webApiCall($serviceInfo, $requestData); } catch (\SoapFault $e) { @@ -1072,7 +1073,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "wrong-sku" does not exist.' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links'; diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php index 0c286719feeec..b429b791a2ab5 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php @@ -551,7 +551,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "wrong-sku" does not exist.' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples'; @@ -574,7 +574,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "wrong-sku" does not exist.' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples/1'; diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php index 0db7c72561e33..3daa6eee358a8 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php @@ -123,7 +123,7 @@ public function testSendWithoutExistProduct() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with ID "2018" does not exist.' ); $productId = 2018; @@ -284,7 +284,7 @@ public function testSendProductWithoutVisibility() }'; $query = $this->getQuery($productId, $recipients); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with SKU "simple_product_without_visibility" does not exist.' ); $this->graphQlMutation($query, [], '', $this->getHeaderMap()); } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php index dfe1115f1d167..964480b1f6b7f 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php @@ -109,7 +109,7 @@ public function testProductIsDeletedAfterDeleteItsAttributeSet(): void $this->deleteAttributeSetByNameAndAssert('new_attribute_set'); $this->expectExceptionObject( new NoSuchEntityException( - __('The product that was requested doesn\'t exist. Verify the product and try again.') + __('The product with SKU "simple" does not exist.') ) ); $this->productRepository->get('simple'); diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php index 42a786e48a61e..8247f3425675d 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php @@ -125,7 +125,7 @@ public function testSaveQuoteItemWithNotExistingProduct(): void $item->setSku('not_existing_product_sku')->setQty(1); $this->expectExceptionObject( new NoSuchEntityException( - __('The product that was requested doesn\'t exist. Verify the product and try again.') + __('The product with SKU "not_existing_product_sku" does not exist.') ) ); $this->model->save($quote, $item); From f2ce1d3124a4cdcbc7c3bc03d6b26616a71b9928 Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Wed, 23 Jul 2025 19:55:46 +0100 Subject: [PATCH 03/11] fix test api --- ...roductAttributeMediaGalleryManagementInterfaceTest.php | 8 ++++---- .../Catalog/Api/ProductRepositoryInterfaceTest.php | 4 ++-- .../ConfigurableProduct/Api/OptionRepositoryTest.php | 2 +- .../ConfigurableProduct/Api/ProductRepositoryTest.php | 4 ++-- .../Magento/Downloadable/Api/LinkRepositoryTest.php | 4 ++-- .../Magento/Downloadable/Api/SampleRepositoryTest.php | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index ca94a2dad22ab..f0c4014ba4e7a 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -500,7 +500,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "wrong_product_sku" does not exist.' + 'The product with SKU "%1" does not exist.' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media'; @@ -557,7 +557,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "wrong_product_sku" does not exist..' + 'The product with SKU "%1" does not exist.' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media' @@ -613,7 +613,7 @@ public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "wrong_product_sku" does not exist.' + 'The product with SKU "%1" does not exist.' ); $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999'; @@ -778,7 +778,7 @@ public function testGetListForAbsentSku() if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { $this->expectException('SoapFault'); $this->expectExceptionMessage( - "The product that was requested doesn't exist. Verify the product and try again." + 'The product with SKU "%1" does not exist.' ); } else { $this->expectException('Exception'); diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index 4d82910557625..6e79a11a5b2ec 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -186,7 +186,7 @@ public function testGetNoSuchEntityException() ], ]; - $expectedMessage = "The product that was requested doesn't exist. Verify the product and try again."; + $expectedMessage = 'The product with SKU "%1" does not exist.'; try { $this->_webApiCall($serviceInfo, ['sku' => $invalidSku]); @@ -546,7 +546,7 @@ public function testDeleteAllStoreCode($fixtureProduct) $this->saveProduct($fixtureProduct); $this->expectException('Exception'); $this->expectExceptionMessage( - "The product that was requested doesn't exist. Verify the product and try again." + 'The product with SKU "%1" does not exist.' ); // Delete all with 'all' store code diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php index f5b35738e0a7f..1d8654ce14a70 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php @@ -102,7 +102,7 @@ public function testGetUndefinedProduct(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "product_not_exist" does not exist.' + 'The product with SKU "%1" does not exist.' ); $productSku = 'product_not_exist'; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php index 9b94cbfab2c3c..dbd23123ca933 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php @@ -383,7 +383,7 @@ public function testUpdateConfigurableProductLinksWithNonExistingProduct() $nonExistingId, ]; - $expectedMessage = 'The product with SKU "wrong_product_sku" does not exist.'; + $expectedMessage = 'The product with ID "%1" does not exist.'; try { $this->saveProduct($response); $this->fail("Expected exception"); @@ -461,7 +461,7 @@ public function testUpdateConfigurableProductLinksWithWithoutVariationAttributes $productId2, ]; - $expectedMessage = 'The product with SKU "product_not_exist" does not exist.'; + $expectedMessage = 'The product with ID "%1" does not exist.'; try { $this->saveProduct($response); $this->fail("Expected exception"); diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php index b6ab006e6967b..9c2595236a804 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php @@ -1002,7 +1002,7 @@ public function testGetListForAbsentProduct($urlTail, $method) $requestData = ['sku' => $sku]; - $expectedMessage = 'The product with SKU "' . $sku . '" does not exist.'; + $expectedMessage = 'The product with SKU "%1" does not exist.'; try { $this->_webApiCall($serviceInfo, $requestData); } catch (\SoapFault $e) { @@ -1073,7 +1073,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "wrong-sku" does not exist.' + 'The product with SKU "%1" does not exist.' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links'; diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php index b429b791a2ab5..bf6717988abfe 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php @@ -551,7 +551,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "wrong-sku" does not exist.' + 'The product with SKU "%1" does not exist.' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples'; @@ -574,7 +574,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "wrong-sku" does not exist.' + 'The product with SKU "%1" does not exist.' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples/1'; From 700d73031dd1cda0a7e909b7b666b4716a044f7e Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Wed, 23 Jul 2025 21:54:51 +0100 Subject: [PATCH 04/11] fix test api --- .../ProductAttributeMediaGalleryManagementInterfaceTest.php | 4 +--- .../testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php | 2 +- .../testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index f0c4014ba4e7a..92dd4c72401f7 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -612,9 +612,7 @@ public function testUpdateThrowsExceptionIfThereIsNoImageWithGivenId() public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); - $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' - ); + $this->expectExceptionMessage('The product with SKU "wrong_product_sku" does not exist.'); $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999'; $requestData = [ diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php index 9c2595236a804..57e3240329665 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php @@ -751,7 +751,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "wrong-sku" does not exist.' + 'The product with SKU "%1" does not exist.' ); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php index 3daa6eee358a8..0db7c72561e33 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php @@ -123,7 +123,7 @@ public function testSendWithoutExistProduct() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with ID "2018" does not exist.' + 'The product that was requested doesn\'t exist. Verify the product and try again.' ); $productId = 2018; @@ -284,7 +284,7 @@ public function testSendProductWithoutVisibility() }'; $query = $this->getQuery($productId, $recipients); $this->expectExceptionMessage( - 'The product with SKU "simple_product_without_visibility" does not exist.' + 'The product that was requested doesn\'t exist. Verify the product and try again.' ); $this->graphQlMutation($query, [], '', $this->getHeaderMap()); } From 2ebb202ffc9fbc0786dcc009e0b4965bbe12d19d Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Thu, 24 Jul 2025 07:03:41 +0100 Subject: [PATCH 05/11] fix test api --- ...roductAttributeMediaGalleryManagementInterfaceTest.php | 8 ++++---- .../Catalog/Api/ProductRepositoryInterfaceTest.php | 4 ++-- .../Api/_files/product_options_update_negative.php | 2 +- .../ConfigurableProduct/Api/OptionRepositoryTest.php | 2 +- .../ConfigurableProduct/Api/ProductRepositoryTest.php | 4 ++-- .../Magento/Downloadable/Api/LinkRepositoryTest.php | 6 +++--- .../Magento/Downloadable/Api/SampleRepositoryTest.php | 4 ++-- .../Magento/GraphQl/SendFriend/SendFriendTest.php | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index 92dd4c72401f7..b566c5a0b8a00 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -500,7 +500,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media'; @@ -557,7 +557,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media' @@ -612,7 +612,7 @@ public function testUpdateThrowsExceptionIfThereIsNoImageWithGivenId() public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); - $this->expectExceptionMessage('The product with SKU "wrong_product_sku" does not exist.'); + $this->expectExceptionMessage("The product with SKU \"%1\" does not exist."); $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999'; $requestData = [ @@ -776,7 +776,7 @@ public function testGetListForAbsentSku() if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { $this->expectException('SoapFault'); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); } else { $this->expectException('Exception'); diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index 6e79a11a5b2ec..8b60e6fe87b70 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -186,7 +186,7 @@ public function testGetNoSuchEntityException() ], ]; - $expectedMessage = 'The product with SKU "%1" does not exist.'; + $expectedMessage = "The product with SKU \"%1\" does not exist."; try { $this->_webApiCall($serviceInfo, ['sku' => $invalidSku]); @@ -546,7 +546,7 @@ public function testDeleteAllStoreCode($fixtureProduct) $this->saveProduct($fixtureProduct); $this->expectException('Exception'); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); // Delete all with 'all' store code diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php index 5de648df469b9..2886bbb079e39 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php @@ -29,7 +29,7 @@ 'product_sku' => 'sku1', 'max_characters' => 10, ], - 'The product with SKU "sku1" does not exist.', + "The product with SKU \"%1\" does not exist.", 404, ], ]; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php index 1d8654ce14a70..c2c4f317b0b6b 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php @@ -102,7 +102,7 @@ public function testGetUndefinedProduct(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); $productSku = 'product_not_exist'; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php index dbd23123ca933..a774d12dd7d2e 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php @@ -383,7 +383,7 @@ public function testUpdateConfigurableProductLinksWithNonExistingProduct() $nonExistingId, ]; - $expectedMessage = 'The product with ID "%1" does not exist.'; + $expectedMessage = "The product with ID \"%1\" does not exist."; try { $this->saveProduct($response); $this->fail("Expected exception"); @@ -461,7 +461,7 @@ public function testUpdateConfigurableProductLinksWithWithoutVariationAttributes $productId2, ]; - $expectedMessage = 'The product with ID "%1" does not exist.'; + $expectedMessage = "The product with ID \"%1\" does not exist."; try { $this->saveProduct($response); $this->fail("Expected exception"); diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php index 57e3240329665..1ea57990ee24f 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php @@ -751,7 +751,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); @@ -1002,7 +1002,7 @@ public function testGetListForAbsentProduct($urlTail, $method) $requestData = ['sku' => $sku]; - $expectedMessage = 'The product with SKU "%1" does not exist.'; + $expectedMessage = "The product with SKU \"%1\" does not exist."; try { $this->_webApiCall($serviceInfo, $requestData); } catch (\SoapFault $e) { @@ -1073,7 +1073,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links'; diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php index bf6717988abfe..1dc3eb0f1618f 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php @@ -551,7 +551,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples'; @@ -574,7 +574,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' + "The product with SKU \"%1\" does not exist." ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples/1'; diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php index 0db7c72561e33..d65c91ed0db7b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php @@ -123,7 +123,7 @@ public function testSendWithoutExistProduct() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - 'The product that was requested doesn\'t exist. Verify the product and try again.' + 'The product with ID "2018" does not exist.' ); $productId = 2018; From 415ec32efe09321d27fe8a63cc639b274ae010d6 Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Thu, 24 Jul 2025 09:50:16 +0100 Subject: [PATCH 06/11] fix test api --- ...ctAttributeMediaGalleryManagementInterfaceTest.php | 6 +++--- .../Catalog/Api/ProductRepositoryInterfaceTest.php | 7 +++---- .../Api/_files/product_options_update_negative.php | 6 +++--- .../ConfigurableProduct/Api/OptionRepositoryTest.php | 7 +++---- .../Magento/Downloadable/Api/LinkRepositoryTest.php | 11 +++++------ .../Magento/Downloadable/Api/SampleRepositoryTest.php | 8 ++++---- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index b566c5a0b8a00..db05d7504fb5d 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -500,7 +500,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media'; @@ -557,7 +557,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media' @@ -612,7 +612,7 @@ public function testUpdateThrowsExceptionIfThereIsNoImageWithGivenId() public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); - $this->expectExceptionMessage("The product with SKU \"%1\" does not exist."); + $this->expectExceptionMessage('{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}'); $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999'; $requestData = [ diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index 8b60e6fe87b70..c3fd96d015f3c 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -1,8 +1,7 @@ saveProduct($fixtureProduct); $this->expectException('Exception'); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["' . $sku . '"]}' ); // Delete all with 'all' store code diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php index 2886bbb079e39..5921c9a2e2220 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php @@ -1,7 +1,7 @@ 'sku1', 'max_characters' => 10, ], - "The product with SKU \"%1\" does not exist.", + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}', 404, ], ]; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php index c2c4f317b0b6b..dfa94bf13074f 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php @@ -1,8 +1,7 @@ expectException(\Exception::class); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["product_not_exist"]}' ); $productSku = 'product_not_exist'; diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php index 1ea57990ee24f..5a3d79433efc1 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php @@ -1,7 +1,7 @@ expectException(\Exception::class); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." - + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/1'; @@ -1002,7 +1001,7 @@ public function testGetListForAbsentProduct($urlTail, $method) $requestData = ['sku' => $sku]; - $expectedMessage = "The product with SKU \"%1\" does not exist."; + $expectedMessage = '{"message":"The product with SKU \"%1\" does not exist.","parameters":["' . $sku . ' "]}'; try { $this->_webApiCall($serviceInfo, $requestData); } catch (\SoapFault $e) { @@ -1073,7 +1072,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links'; diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php index 1dc3eb0f1618f..921c708c1c139 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php @@ -1,7 +1,7 @@ expectException(\Exception::class); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' ); $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples'; @@ -574,7 +574,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - "The product with SKU \"%1\" does not exist." + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples/1'; From fb12e38f10beef3842aad22c086d24731501199e Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Fri, 25 Jul 2025 09:02:09 +0100 Subject: [PATCH 07/11] fix validation errors --- .../Test/Unit/Model/ProductLink/ManagementTest.php | 12 ++++++------ ...tAttributeMediaGalleryManagementInterfaceTest.php | 4 +++- .../Catalog/Api/ProductRepositoryInterfaceTest.php | 12 ++++++------ .../ConfigurableProduct/Api/OptionRepositoryTest.php | 2 +- .../Api/ProductRepositoryTest.php | 12 ++++++------ .../Magento/Downloadable/Api/LinkRepositoryTest.php | 4 ++-- .../Downloadable/Api/SampleRepositoryTest.php | 2 +- .../Magento/GraphQl/SendFriend/SendFriendTest.php | 4 ++-- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php index 037af6a39115d..907a0c533eb47 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php @@ -24,11 +24,11 @@ */ class ManagementTest extends TestCase { - const STUB_PRODUCT_SKU_1 = 'Simple Product 1'; - const STUB_PRODUCT_SKU_2 = 'Simple Product 2'; - const STUB_PRODUCT_TYPE = 'simple'; - const STUB_LINK_TYPE = 'related'; - const STUB_BAD_TYPE = 'bad type'; + private const STUB_PRODUCT_SKU_1 = 'Simple Product 1'; + private const STUB_PRODUCT_SKU_2 = 'Simple Product 2'; + private const STUB_PRODUCT_TYPE = 'simple'; + private const STUB_LINK_TYPE = 'related'; + private const STUB_BAD_TYPE = 'bad type'; /** * @var Management @@ -295,7 +295,7 @@ public function testSetProductLinksNoProductException() $this->expectException(NoSuchEntityException::class); $this->expectExceptionMessage( - 'The product with SKU " ' . $productSku . ' " does not exist.' + 'The product with SKU "' . $productSku . '" does not exist.' ); $this->model->setProductLinks($productSku, $links); diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index db05d7504fb5d..08d2d0f6b5d17 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -612,7 +612,9 @@ public function testUpdateThrowsExceptionIfThereIsNoImageWithGivenId() public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); - $this->expectExceptionMessage('{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}'); + $this->expectExceptionMessage( + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}' + ); $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999'; $requestData = [ diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index c3fd96d015f3c..0d3cae9a9c2df 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -45,13 +45,13 @@ */ class ProductRepositoryInterfaceTest extends WebapiAbstract { - const SERVICE_NAME = 'catalogProductRepositoryV1'; - const SERVICE_VERSION = 'V1'; - const RESOURCE_PATH = '/V1/products'; + private const SERVICE_NAME = 'catalogProductRepositoryV1'; + private const SERVICE_VERSION = 'V1'; + private const RESOURCE_PATH = '/V1/products'; - const KEY_TIER_PRICES = 'tier_prices'; - const KEY_SPECIAL_PRICE = 'special_price'; - const KEY_CATEGORY_LINKS = 'category_links'; + private const KEY_TIER_PRICES = 'tier_prices'; + private const KEY_SPECIAL_PRICE = 'special_price'; + private const KEY_CATEGORY_LINKS = 'category_links'; /** * @var array diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php index dfa94bf13074f..14bce21f7e077 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php @@ -101,7 +101,7 @@ public function testGetUndefinedProduct(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["product_not_exist"]}' + 'The product with SKU "%1" does not exist.' ); $productSku = 'product_not_exist'; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php index a774d12dd7d2e..78318cebd166e 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php @@ -1,7 +1,7 @@ expectException(\Exception::class); $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' + 'The product with SKU "%1" does not exist.' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/1'; @@ -1001,7 +1001,7 @@ public function testGetListForAbsentProduct($urlTail, $method) $requestData = ['sku' => $sku]; - $expectedMessage = '{"message":"The product with SKU \"%1\" does not exist.","parameters":["' . $sku . ' "]}'; + $expectedMessage = 'The product with SKU "%1" does not exist.'; try { $this->_webApiCall($serviceInfo, $requestData); } catch (\SoapFault $e) { diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php index 921c708c1c139..54a5fc8e7ffec 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php @@ -574,7 +574,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { $this->expectException(\Exception::class); $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' + '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' ); $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples/1'; diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php index d65c91ed0db7b..56ba0c8114f10 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php @@ -1,7 +1,7 @@ Date: Sat, 26 Jul 2025 06:26:55 +0100 Subject: [PATCH 08/11] fix static issues --- .../ProductRepositoryCategoryLinksTest.php | 104 ++++++++++++++++++ .../Api/ProductRepositoryInterfaceTest.php | 82 -------------- .../Catalog/Helper/Product/CompositeTest.php | 7 +- .../Catalog/Model/ProductRepositoryTest.php | 6 +- .../Quote/Item/CartItemPersisterTest.php | 4 +- 5 files changed, 112 insertions(+), 91 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryCategoryLinksTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryCategoryLinksTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryCategoryLinksTest.php new file mode 100644 index 0000000000000..400b5b1fa5290 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryCategoryLinksTest.php @@ -0,0 +1,104 @@ +getSimpleProductData(); + $productData[ProductInterface::EXTENSION_ATTRIBUTES_KEY] = [ + self::KEY_CATEGORY_LINKS => [['category_id' => 333, 'position' => 0]], + ]; + $response = $this->saveProduct($productData); + $this->assertEquals( + [['category_id' => 333, 'position' => 0]], + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] + ); + $response = $this->getProduct($productData[ProductInterface::SKU]); + $this->assertArrayHasKey(ProductInterface::EXTENSION_ATTRIBUTES_KEY, $response); + $extensionAttributes = $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]; + $this->assertArrayHasKey(self::KEY_CATEGORY_LINKS, $extensionAttributes); + $this->assertEquals([['category_id' => 333, 'position' => 0]], $extensionAttributes[self::KEY_CATEGORY_LINKS]); + } + + /** + * Test update product category without categories + * + * @magentoApiDataFixture Magento/Catalog/_files/category_product.php + */ + public function testUpdateProductCategoryLinksNullOrNotExists() + { + $response = $this->getProduct('simple333'); + // update product without category_link or category_link is null + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] = null; + $response = $this->updateProduct($response); + $this->assertEquals( + [['category_id' => 333, 'position' => 0]], + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] + ); + unset($response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS]); + $response = $this->updateProduct($response); + $this->assertEquals( + [['category_id' => 333, 'position' => 0]], + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] + ); + } + + /** + * Test update product category links position + * + * @magentoApiDataFixture Magento/Catalog/_files/category_product.php + */ + public function testUpdateProductCategoryLinksPosition() + { + $response = $this->getProduct('simple333'); + // update category_link position + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] = [ + ['category_id' => 333, 'position' => 10], + ]; + $response = $this->updateProduct($response); + $this->assertEquals( + [['category_id' => 333, 'position' => 10]], + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] + ); + } + + /** + * Test update product category links unassing + * + * @magentoApiDataFixture Magento/Catalog/_files/category_product.php + */ + public function testUpdateProductCategoryLinksUnassign() + { + $response = $this->getProduct('simple333'); + // unassign category_links from product + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] = []; + $response = $this->updateProduct($response); + $this->assertArrayNotHasKey( + self::KEY_CATEGORY_LINKS, + $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY] + ); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index 0d3cae9a9c2df..d9eb8a7cb5460 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -48,10 +48,8 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract private const SERVICE_NAME = 'catalogProductRepositoryV1'; private const SERVICE_VERSION = 'V1'; private const RESOURCE_PATH = '/V1/products'; - private const KEY_TIER_PRICES = 'tier_prices'; private const KEY_SPECIAL_PRICE = 'special_price'; - private const KEY_CATEGORY_LINKS = 'category_links'; /** * @var array @@ -1661,86 +1659,6 @@ private function getStockItemData() ]; } - /** - * Test product category links - * - * @magentoApiDataFixture Magento/Catalog/_files/category_product.php - */ - public function testProductCategoryLinks() - { - // Create simple product - $productData = $this->getSimpleProductData(); - $productData[ProductInterface::EXTENSION_ATTRIBUTES_KEY] = [ - self::KEY_CATEGORY_LINKS => [['category_id' => 333, 'position' => 0]], - ]; - $response = $this->saveProduct($productData); - $this->assertEquals( - [['category_id' => 333, 'position' => 0]], - $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] - ); - $response = $this->getProduct($productData[ProductInterface::SKU]); - $this->assertArrayHasKey(ProductInterface::EXTENSION_ATTRIBUTES_KEY, $response); - $extensionAttributes = $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]; - $this->assertArrayHasKey(self::KEY_CATEGORY_LINKS, $extensionAttributes); - $this->assertEquals([['category_id' => 333, 'position' => 0]], $extensionAttributes[self::KEY_CATEGORY_LINKS]); - } - - /** - * Test update product category without categories - * - * @magentoApiDataFixture Magento/Catalog/_files/category_product.php - */ - public function testUpdateProductCategoryLinksNullOrNotExists() - { - $response = $this->getProduct('simple333'); - // update product without category_link or category_link is null - $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] = null; - $response = $this->updateProduct($response); - $this->assertEquals( - [['category_id' => 333, 'position' => 0]], - $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] - ); - unset($response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS]); - $response = $this->updateProduct($response); - $this->assertEquals( - [['category_id' => 333, 'position' => 0]], - $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] - ); - } - - /** - * Test update product category links position - * - * @magentoApiDataFixture Magento/Catalog/_files/category_product.php - */ - public function testUpdateProductCategoryLinksPosistion() - { - $response = $this->getProduct('simple333'); - // update category_link position - $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] = [ - ['category_id' => 333, 'position' => 10], - ]; - $response = $this->updateProduct($response); - $this->assertEquals( - [['category_id' => 333, 'position' => 10]], - $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] - ); - } - - /** - * Test update product category links unassing - * - * @magentoApiDataFixture Magento/Catalog/_files/category_product.php - */ - public function testUpdateProductCategoryLinksUnassign() - { - $response = $this->getProduct('simple333'); - // unassign category_links from product - $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::KEY_CATEGORY_LINKS] = []; - $response = $this->updateProduct($response); - $this->assertArrayNotHasKey(self::KEY_CATEGORY_LINKS, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]); - } - /** * Get media gallery data * diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Helper/Product/CompositeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Helper/Product/CompositeTest.php index ef68a1ededc1f..70f676855c59f 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Helper/Product/CompositeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Helper/Product/CompositeTest.php @@ -1,7 +1,7 @@ [ 'ok' => true, ], - 'expectedErrorMessage' => 'The product that was requested doesn\'t exist.' - . ' Verify the product and try again.', + 'expectedErrorMessage' => 'The product with ID "" does not exist.', ], ]; } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php index 71a293c69246b..e90fd116fee74 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php @@ -1,7 +1,7 @@ expectExceptionObject(new NoSuchEntityException( - __("The product that was requested doesn't exist. Verify the product and try again.") + __('The product with SKU "' . $sku . '" does not exist.') )); $this->productRepository->get($sku); } diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php index 8247f3425675d..0cf38f32488fb 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php @@ -1,7 +1,7 @@ Date: Sat, 26 Jul 2025 08:04:54 +0100 Subject: [PATCH 09/11] fix static issues --- .../Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php index 964480b1f6b7f..059b85c0149d1 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php @@ -1,7 +1,7 @@ Date: Sat, 26 Jul 2025 13:37:41 +0100 Subject: [PATCH 10/11] fix test api --- ...uteMediaGalleryManagementInterfaceTest.php | 59 +++++++++++-------- .../Api/ProductCustomOptionRepositoryTest.php | 13 ++-- .../Api/ProductRepositoryInterfaceTest.php | 19 +++--- .../product_options_update_negative.php | 2 +- .../Api/OptionRepositoryTest.php | 16 +++-- .../Downloadable/Api/LinkRepositoryTest.php | 54 +++++++++++------ .../Downloadable/Api/SampleRepositoryTest.php | 44 +++++++++----- 7 files changed, 133 insertions(+), 74 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index 08d2d0f6b5d17..33627a771e94a 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -492,18 +492,22 @@ public function testCreateThrowsExceptionIfProvidedImageHasWrongMimeType() $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]); } + protected function assertMagentoProductNotFoundException(\Exception $e, string $sku): void + { + $expectedMessage = 'The product with SKU "%1" does not exist.'; + $this->assertEquals(404, $e->getCode()); + $this->assertStringContainsString($expectedMessage, $e->getMessage()); + $this->assertStringContainsString($sku, $e->getMessage()); + } + /** * Test create method if target product does not exist - * */ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}' - ); + $sku = 'wrong_product_sku'; - $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media'; + $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/' . $sku . '/media'; $requestData = [ 'id' => null, @@ -519,7 +523,12 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() ] ]; - $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]); + try { + $this->_webApiCall($this->createServiceInfo, ['sku' => $sku, 'entry' => $requestData]); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertMagentoProductNotFoundException($e, $sku); + } } /** @@ -551,19 +560,14 @@ public function testCreateThrowsExceptionIfProvidedImageNameContainsForbiddenCha /** * Test update() method if target product does not exist - * */ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}' - ); + $sku = 'wrong_product_sku'; - $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media' - . '/' . 'wrong-sku'; + $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/' . $sku . '/media/' . 'wrong-sku'; $requestData = [ - 'sku' => 'wrong_product_sku', + 'sku' => $sku, 'entry' => [ 'id' => 9999, 'media_type' => 'image', @@ -574,9 +578,15 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() ], ]; - $this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all'); + try { + $this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all'); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertMagentoProductNotFoundException($e, $sku); + } } + /** * Test update() method if there is no image with given id * @@ -607,22 +617,23 @@ public function testUpdateThrowsExceptionIfThereIsNoImageWithGivenId() /** * Test delete() method if target product does not exist - * */ public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}' - ); + $sku = 'wrong_product_sku'; - $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999'; + $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/' . $sku . '/media/9999'; $requestData = [ - 'sku' => 'wrong_product_sku', + 'sku' => $sku, 'entryId' => 9999, ]; - $this->_webApiCall($this->deleteServiceInfo, $requestData); + try { + $this->_webApiCall($this->deleteServiceInfo, $requestData); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertMagentoProductNotFoundException($e, $sku); + } } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionRepositoryTest.php index 6d12a10775df3..922724a57ec5a 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionRepositoryTest.php @@ -421,6 +421,7 @@ public function testUpdateNegative($optionData, $message, $exceptionCode) { $this->_markTestAsRestOnly(); $productSku = 'simple'; + /** @var ProductRepository $productRepository */ $productRepository = $this->objectManager->create(ProductRepository::class); $options = $productRepository->get($productSku, true)->getOptions(); @@ -434,10 +435,14 @@ public function testUpdateNegative($optionData, $message, $exceptionCode) ], ]; - $this->expectException('Exception'); - $this->expectExceptionMessage($message); - $this->expectExceptionCode($exceptionCode); - $this->_webApiCall($serviceInfo, ['option' => $optionData]); + try { + $this->_webApiCall($serviceInfo, ['option' => $optionData]); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertEquals($exceptionCode, $e->getCode()); + $this->assertStringContainsString($message, $e->getMessage()); + $this->assertStringContainsString($productSku, $e->getMessage()); + } } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index d9eb8a7cb5460..c7fa16fb01596 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -537,18 +537,23 @@ public function testCreateInvalidPriceFormat() * @dataProvider productCreationProvider * @magentoApiDataFixture Magento/Store/_files/fixture_store_with_catalogsearch_index.php */ - public function testDeleteAllStoreCode($fixtureProduct) + public function testDeleteAllStoreCode(array $fixtureProduct) { - $sku = $fixtureProduct[ProductInterface::SKU]; + $sku = $fixtureProduct[\Magento\Catalog\Api\Data\ProductInterface::SKU]; $this->saveProduct($fixtureProduct); - $this->expectException('Exception'); - $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["' . $sku . '"]}' - ); // Delete all with 'all' store code $this->deleteProduct($sku); - $this->getProduct($sku); + + try { + $this->getProduct($sku); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $expectedMessage = 'The product with SKU "%1" does not exist.'; + $this->assertEquals(404, $e->getCode()); + $this->assertStringContainsString($expectedMessage, $e->getMessage()); + $this->assertStringContainsString($sku, $e->getMessage()); + } } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php index 5921c9a2e2220..de20b158ba191 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php @@ -29,7 +29,7 @@ 'product_sku' => 'sku1', 'max_characters' => 10, ], - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong_product_sku"]}', + 'The product with SKU "%1" does not exist.', 404, ], ]; diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php index 14bce21f7e077..fc13b5a4bcb2e 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php @@ -99,13 +99,17 @@ public function testGetList(): void */ public function testGetUndefinedProduct(): void { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' - ); - $productSku = 'product_not_exist'; - $this->getList($productSku); + + try { + $this->getList($productSku); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $expectedTemplate = 'The product with SKU "%1" does not exist.'; + $this->assertEquals(404, $e->getCode()); + $this->assertStringContainsString($expectedTemplate, $e->getMessage()); + $this->assertStringContainsString($productSku, $e->getMessage()); + } } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php index 0cc174cbcb4e6..01b04ee7df397 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php @@ -745,19 +745,30 @@ public function testUpdateSavesDataInGlobalScopeAndDoesNotAffectValuesStoredInSt $this->assertEquals($requestData['link']['number_of_downloads'], $link->getNumberOfDownloads()); } + protected function assertMagentoProductNotFoundException(\Exception $e, string $sku): void + { + $expectedTemplate = 'The product with SKU "%1" does not exist.'; + + if ($e instanceof \SoapFault) { + $expectedMessage = str_replace('%1', $sku, $expectedTemplate); + $this->assertEquals($expectedMessage, $e->getMessage()); + } else { + $this->assertEquals(404, $e->getCode()); + $this->assertStringContainsString($expectedTemplate, $e->getMessage()); + $this->assertStringContainsString($sku, $e->getMessage()); + } + } + /** */ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - 'The product with SKU "%1" does not exist.' - ); + $sku = 'wrong-sku'; - $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/1'; + $this->updateServiceInfo['rest']['resourcePath'] = "/V1/products/{$sku}/downloadable-links/1"; $requestData = [ 'isGlobalScopeContent' => true, - 'sku' => 'wrong-sku', + 'sku' => $sku, 'link' => [ 'id' => 1, 'title' => 'Updated Title', @@ -769,7 +780,13 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() 'sample_type' => 'url', ], ]; - $this->_webApiCall($this->updateServiceInfo, $requestData); + + try { + $this->_webApiCall($this->updateServiceInfo, $requestData); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertMagentoProductNotFoundException($e, $sku); + } } /** @@ -1001,13 +1018,11 @@ public function testGetListForAbsentProduct($urlTail, $method) $requestData = ['sku' => $sku]; - $expectedMessage = 'The product with SKU "%1" does not exist.'; try { $this->_webApiCall($serviceInfo, $requestData); - } catch (\SoapFault $e) { - $this->assertEquals($expectedMessage, $e->getMessage()); + $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertStringContainsString($expectedMessage, $e->getMessage()); + $this->assertMagentoProductNotFoundException($e, $sku); } } @@ -1070,15 +1085,12 @@ public function testCreateThrowsExceptionIfTargetProductTypeIsNotDownloadable() */ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' - ); + $sku = 'wrong-sku'; - $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links'; + $this->createServiceInfo['rest']['resourcePath'] = "/V1/products/{$sku}/downloadable-links"; $requestData = [ 'isGlobalScopeContent' => false, - 'sku' => 'wrong-sku', + 'sku' => $sku, 'link' => [ 'title' => 'Link Title', 'sort_order' => 15, @@ -1091,6 +1103,12 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() 'link_url' => 'http://example.com/', ], ]; - $this->_webApiCall($this->createServiceInfo, $requestData); + + try { + $this->_webApiCall($this->createServiceInfo, $requestData); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertMagentoProductNotFoundException($e, $sku); + } } } diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php index 54a5fc8e7ffec..b1e5b8b431bbd 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php @@ -545,19 +545,25 @@ public function testCreateThrowsExceptionIfTargetProductTypeIsNotDownloadable() $this->_webApiCall($this->createServiceInfo, $requestData); } + protected function assertMagentoProductNotFoundException(\Exception $e, string $sku): void + { + $expectedMessage = 'The product with SKU "%1" does not exist.'; + $this->assertEquals(404, $e->getCode()); + $this->assertStringContainsString($expectedMessage, $e->getMessage()); + $this->assertStringContainsString($sku, $e->getMessage()); + } + /** + * Test create() method on downloadable sample when target product does not exist */ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' - ); + $sku = 'wrong-sku'; - $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples'; + $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/' . $sku . '/downloadable-links/samples'; $requestData = [ 'isGlobalScopeContent' => false, - 'sku' => 'wrong-sku', + 'sku' => $sku, 'sample' => [ 'title' => 'Title', 'sort_order' => 15, @@ -565,22 +571,26 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() 'sample_url' => 'http://example.com/', ], ]; - $this->_webApiCall($this->createServiceInfo, $requestData); + + try { + $this->_webApiCall($this->createServiceInfo, $requestData); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertMagentoProductNotFoundException($e, $sku); + } } /** + * Test update() method on downloadable sample when target product does not exist */ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - '{"message":"The product with SKU \"%1\" does not exist.","parameters":["wrong-sku"]}' - ); + $sku = 'wrong-sku'; - $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong-sku/downloadable-links/samples/1'; + $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/' . $sku . '/downloadable-links/samples/1'; $requestData = [ 'isGlobalScopeContent' => true, - 'sku' => 'wrong-sku', + 'sku' => $sku, 'sample' => [ 'id' => 1, 'title' => 'Updated Title', @@ -588,6 +598,12 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() 'sample_type' => 'url', ], ]; - $this->_webApiCall($this->updateServiceInfo, $requestData); + + try { + $this->_webApiCall($this->updateServiceInfo, $requestData); + $this->fail('Expected exception was not thrown.'); + } catch (\Exception $e) { + $this->assertMagentoProductNotFoundException($e, $sku); + } } } From 2977e72aa0c3d03c0b32de169d244b90f4568177 Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Sun, 27 Jul 2025 11:36:15 +0100 Subject: [PATCH 11/11] fix issue api --- ...ttributeMediaGalleryManagementInterfaceTest.php | 14 +++++++------- .../Api/OptionRepositoryTest.php | 13 +++++++++---- .../Downloadable/Api/LinkRepositoryTest.php | 14 +++++++------- .../Downloadable/Api/SampleRepositoryTest.php | 12 ++++++------ 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php index 33627a771e94a..f98d9e3fdcf5a 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php @@ -492,12 +492,12 @@ public function testCreateThrowsExceptionIfProvidedImageHasWrongMimeType() $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]); } - protected function assertMagentoProductNotFoundException(\Exception $e, string $sku): void + protected function assertProductNotFoundException(\Exception $e, string $sku): void { - $expectedMessage = 'The product with SKU "%1" does not exist.'; + $decoded = json_decode($e->getMessage(), true); + $this->assertEquals('The product with SKU "%1" does not exist.', $decoded['message']); + $this->assertContains($sku, $decoded['parameters']); $this->assertEquals(404, $e->getCode()); - $this->assertStringContainsString($expectedMessage, $e->getMessage()); - $this->assertStringContainsString($sku, $e->getMessage()); } /** @@ -527,7 +527,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() $this->_webApiCall($this->createServiceInfo, ['sku' => $sku, 'entry' => $requestData]); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } @@ -582,7 +582,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() $this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all'); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } @@ -632,7 +632,7 @@ public function testDeleteThrowsExceptionIfTargetProductDoesNotExist() $this->_webApiCall($this->deleteServiceInfo, $requestData); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php index fc13b5a4bcb2e..d65a774482e97 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php @@ -94,6 +94,14 @@ public function testGetList(): void } } + protected function assertProductNotFoundException(\Exception $e, string $sku): void + { + $decoded = json_decode($e->getMessage(), true); + $this->assertEquals('The product with SKU "%1" does not exist.', $decoded['message']); + $this->assertContains($sku, $decoded['parameters']); + $this->assertEquals(404, $e->getCode()); + } + /** * @return void */ @@ -105,10 +113,7 @@ public function testGetUndefinedProduct(): void $this->getList($productSku); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $expectedTemplate = 'The product with SKU "%1" does not exist.'; - $this->assertEquals(404, $e->getCode()); - $this->assertStringContainsString($expectedTemplate, $e->getMessage()); - $this->assertStringContainsString($productSku, $e->getMessage()); + $this->assertProductNotFoundException($e, $productSku); } } diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php index 01b04ee7df397..1dcd69c047189 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/LinkRepositoryTest.php @@ -745,17 +745,17 @@ public function testUpdateSavesDataInGlobalScopeAndDoesNotAffectValuesStoredInSt $this->assertEquals($requestData['link']['number_of_downloads'], $link->getNumberOfDownloads()); } - protected function assertMagentoProductNotFoundException(\Exception $e, string $sku): void + protected function assertProductNotFoundException(\Exception $e, string $sku): void { $expectedTemplate = 'The product with SKU "%1" does not exist.'; - if ($e instanceof \SoapFault) { $expectedMessage = str_replace('%1', $sku, $expectedTemplate); $this->assertEquals($expectedMessage, $e->getMessage()); } else { + $decoded = json_decode($e->getMessage(), true); + $this->assertEquals($expectedTemplate, $decoded['message']); + $this->assertContains($sku, $decoded['parameters']); $this->assertEquals(404, $e->getCode()); - $this->assertStringContainsString($expectedTemplate, $e->getMessage()); - $this->assertStringContainsString($sku, $e->getMessage()); } } @@ -785,7 +785,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() $this->_webApiCall($this->updateServiceInfo, $requestData); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } @@ -1022,7 +1022,7 @@ public function testGetListForAbsentProduct($urlTail, $method) $this->_webApiCall($serviceInfo, $requestData); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } @@ -1108,7 +1108,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() $this->_webApiCall($this->createServiceInfo, $requestData); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } } diff --git a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php index b1e5b8b431bbd..266778c4d99e5 100644 --- a/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php @@ -545,12 +545,12 @@ public function testCreateThrowsExceptionIfTargetProductTypeIsNotDownloadable() $this->_webApiCall($this->createServiceInfo, $requestData); } - protected function assertMagentoProductNotFoundException(\Exception $e, string $sku): void + protected function assertProductNotFoundException(\Exception $e, string $sku): void { - $expectedMessage = 'The product with SKU "%1" does not exist.'; + $decoded = json_decode($e->getMessage(), true); + $this->assertEquals('The product with SKU "%1" does not exist.', $decoded['message']); + $this->assertContains($sku, $decoded['parameters']); $this->assertEquals(404, $e->getCode()); - $this->assertStringContainsString($expectedMessage, $e->getMessage()); - $this->assertStringContainsString($sku, $e->getMessage()); } /** @@ -576,7 +576,7 @@ public function testCreateThrowsExceptionIfTargetProductDoesNotExist() $this->_webApiCall($this->createServiceInfo, $requestData); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } @@ -603,7 +603,7 @@ public function testUpdateThrowsExceptionIfTargetProductDoesNotExist() $this->_webApiCall($this->updateServiceInfo, $requestData); $this->fail('Expected exception was not thrown.'); } catch (\Exception $e) { - $this->assertMagentoProductNotFoundException($e, $sku); + $this->assertProductNotFoundException($e, $sku); } } }