Skip to content

Commit b3ea947

Browse files
author
Yu Tang
committed
MAGETWO-28254: ConfigurableProduct Integration API
- Fixed exception handling in api functional test
1 parent 9dc34f0 commit b3ea947

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ public function testUpdateConfigurableProductLinks()
278278

279279
/**
280280
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
281-
* @expectedException \Exception
282-
* @expectedExceptionMessage Product with id "%1" does not exist.
283281
*/
284282
public function testUpdateConfigurableProductLinksWithNonExistingProduct()
285283
{
@@ -292,13 +290,26 @@ public function testUpdateConfigurableProductLinksWithNonExistingProduct()
292290
$response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [
293291
$productId1, $nonExistingId
294292
];
295-
$this->saveProduct($response);
293+
294+
$expectedMessage = 'Product with id "%1" does not exist.';
295+
try {
296+
$this->saveProduct($response);
297+
$this->fail("Expected exception");
298+
} catch (\SoapFault $e) {
299+
$this->assertContains(
300+
$expectedMessage,
301+
$e->getMessage(),
302+
"SoapFault does not contain expected message."
303+
);
304+
} catch (\Exception $e) {
305+
$errorObj = $this->processRestExceptionResult($e);
306+
$this->assertEquals($expectedMessage, $errorObj['message']);
307+
$this->assertEquals(['0' => '999'], $errorObj['parameters']);
308+
}
296309
}
297310

298311
/**
299312
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
300-
* @expectedException \Exception
301-
* @expectedExceptionMessage Products "%1" and %2 have the same set of attribute values.
302313
*/
303314
public function testUpdateConfigurableProductLinksWithDuplicateAttributes()
304315
{
@@ -323,7 +334,22 @@ public function testUpdateConfigurableProductLinksWithDuplicateAttributes()
323334
$response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [
324335
$productId1, $productId2
325336
];
326-
$this->saveProduct($response);
337+
338+
$expectedMessage = 'Products "%1" and %2 have the same set of attribute values.';
339+
try {
340+
$this->saveProduct($response);
341+
$this->fail("Expected exception");
342+
} catch (\SoapFault $e) {
343+
$this->assertContains(
344+
$expectedMessage,
345+
$e->getMessage(),
346+
"SoapFault does not contain expected message."
347+
);
348+
} catch (\Exception $e) {
349+
$errorObj = $this->processRestExceptionResult($e);
350+
$this->assertEquals($expectedMessage, $errorObj['message']);
351+
$this->assertEquals(['0' => 20, '1' => 10], $errorObj['parameters']);
352+
}
327353
}
328354

329355
/**

0 commit comments

Comments
 (0)