Skip to content

Commit 61298aa

Browse files
committed
MAGETWO-90103: Fix syntax of expectException() calls #11099
1 parent 94ccd58 commit 61298aa

File tree

51 files changed

+155
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+155
-76
lines changed

app/code/Magento/Ui/Test/Unit/Model/ResourceModel/BookmarkRepositoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public function testSaveWithException()
9494
->method('save')
9595
->with($this->bookmarkMock)
9696
->willThrowException(new \Exception($exceptionMessage));
97-
$this->expectException(\Magento\Framework\Exception\CouldNotSaveException::class, __($exceptionMessage));
97+
$this->expectException(\Magento\Framework\Exception\CouldNotSaveException::class);
98+
$this->expectExceptionMessage($exceptionMessage);
9899
$this->bookmarkRepository->save($this->bookmarkMock);
99100
}
100101

@@ -143,7 +144,8 @@ public function testDeleteWithException()
143144
->method('delete')
144145
->with($this->bookmarkMock)
145146
->willThrowException(new \Exception($exceptionMessage));
146-
$this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class, __($exceptionMessage));
147+
$this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class);
148+
$this->expectExceptionMessage($exceptionMessage);
147149
$this->assertTrue($this->bookmarkRepository->delete($this->bookmarkMock));
148150
}
149151

app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ public function testSetAndSaveItemOptions()
299299

300300
public function testGetProductWithException()
301301
{
302-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, __('Cannot specify product.'));
302+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
303+
$this->expectExceptionMessage('Cannot specify product.');
303304
$this->model->getProduct();
304305
}
305306

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionRepositoryTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ public function testAddNegative($optionData)
209209

210210
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
211211
if (isset($optionDataPost['title']) && empty($optionDataPost['title'])) {
212-
$this->expectException('SoapFault', 'Missed values for option required fields');
212+
$this->expectException('SoapFault');
213+
$this->expectExceptionMessage('Missed values for option required fields');
213214
} else {
214-
$this->expectException('SoapFault', 'Invalid option');
215+
$this->expectException('SoapFault');
216+
$this->expectExceptionMessage('Invalid option');
215217
}
216218
} else {
217-
$this->expectException('Exception', '', 400);
219+
$this->expectException('Exception');
220+
$this->expectExceptionMessage('', 400);
218221
}
219222
$this->_webApiCall($serviceInfo, ['option' => $optionDataPost]);
220223
}
@@ -386,8 +389,9 @@ public function validOptionDataProvider()
386389
* @dataProvider optionNegativeUpdateDataProvider
387390
* @param array $optionData
388391
* @param string $message
392+
* @param int $exceptionCode
389393
*/
390-
public function testUpdateNegative($optionData, $message)
394+
public function testUpdateNegative($optionData, $message, $exceptionCode)
391395
{
392396
$this->_markTestAsRestOnly();
393397
$productSku = 'simple';
@@ -404,7 +408,9 @@ public function testUpdateNegative($optionData, $message)
404408
],
405409
];
406410

407-
$this->expectException('Exception', $message, 400);
411+
$this->expectException('Exception');
412+
$this->expectExceptionMessage($message);
413+
$this->expectExceptionCode($exceptionCode);
408414
$this->_webApiCall($serviceInfo, ['option' => $optionData]);
409415
}
410416

dev/tests/api-functional/testsuite/Magento/Catalog/Api/_files/product_options_update_negative.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,31 @@
55
*/
66

77
return [
8-
'missed_product_sku' =>
8+
'missing_product_sku' => [
99
[
10-
[
11-
'title' => 'title',
12-
'type' => 'field',
13-
'sort_order' => 1,
14-
'is_require' => 1,
15-
'price' => 10.0,
16-
'price_type' => 'fixed',
17-
'sku' => 'sku1',
18-
'max_characters' => 10,
19-
],
20-
'The ProductSku is empty. Set the ProductSku and try again.',
21-
]
10+
'title' => 'title',
11+
'type' => 'field',
12+
'sort_order' => 1,
13+
'is_require' => 1,
14+
'price' => 10.0,
15+
'price_type' => 'fixed',
16+
'max_characters' => 10,
17+
],
18+
'ProductSku should be specified',
19+
400
20+
],
21+
'invalid_product_sku' => [
22+
[
23+
'title' => 'title',
24+
'type' => 'field',
25+
'sort_order' => 1,
26+
'is_require' => 1,
27+
'price' => 10.0,
28+
'price_type' => 'fixed',
29+
'product_sku' => 'sku1',
30+
'max_characters' => 10,
31+
],
32+
'The product that was requested doesn\'t exist. Verify the product and try again.',
33+
404
34+
],
2235
];

lib/internal/Magento/Framework/App/Test/Unit/Cache/Tag/ResolverTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ protected function setUp()
4040

4141
public function testGetTagsForNotObject()
4242
{
43-
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
43+
$this->expectException(\InvalidArgumentException::class);
44+
$this->expectExceptionMessage('Provided argument is not an object');
4445
$this->model->getTags('some scalar');
4546
}
4647

lib/internal/Magento/Framework/App/Test/Unit/Cache/Tag/Strategy/DummyTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ protected function setUp()
2020

2121
public function testGetTagsWithScalar()
2222
{
23-
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
23+
$this->expectException(\InvalidArgumentException::class);
24+
$this->expectExceptionMessage('Provided argument is not an object');
2425
$this->model->getTags('scalar');
2526
}
2627

lib/internal/Magento/Framework/App/Test/Unit/Cache/Tag/Strategy/FactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ protected function setUp()
4949

5050
public function testGetStrategyWithScalar()
5151
{
52-
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
52+
$this->expectException(\InvalidArgumentException::class);
53+
$this->expectExceptionMessage('Provided argument is not an object');
5354
$this->model->getStrategy('some scalar');
5455
}
5556

lib/internal/Magento/Framework/App/Test/Unit/Cache/Tag/Strategy/IdentifierTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ protected function setUp()
2222

2323
public function testGetWithScalar()
2424
{
25-
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
25+
$this->expectException(\InvalidArgumentException::class);
26+
$this->expectExceptionMessage('Provided argument is not an object');
2627
$this->model->getTags('scalar');
2728
}
2829

lib/internal/Magento/Framework/App/Test/Unit/ErrorHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public function testHandlerException($errorNo, $errorPhrase)
5454
$errorLine = 'test_error_line';
5555

5656
$exceptedExceptionMessage = sprintf('%s: %s in %s on line %s', $errorPhrase, $errorStr, $errorFile, $errorLine);
57-
$this->expectException('Exception', $exceptedExceptionMessage);
57+
$this->expectException('Exception');
58+
$this->expectExceptionMessage($exceptedExceptionMessage);
5859

5960
$this->object->handler($errorNo, $errorStr, $errorFile, $errorLine);
6061
}

lib/internal/Magento/Framework/App/Test/Unit/SetupInfoTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class SetupInfoTest extends \PHPUnit\Framework\TestCase
2424
*/
2525
public function testConstructorExceptions($server, $expectedError)
2626
{
27-
$this->expectException('\InvalidArgumentException', $expectedError);
27+
$this->expectException('\InvalidArgumentException');
28+
$this->expectExceptionMessage($expectedError);
2829
new SetupInfo($server);
2930
}
3031

0 commit comments

Comments
 (0)