Skip to content

Commit 948e5fa

Browse files
schmenglerMastiuhin Oleksandr
authored and
Mastiuhin Oleksandr
committed
Replace expectException(, ) in unit tests
expectException(); expectExceptionMessage() (cherry picked from commit d2e0d44)
1 parent 94ccd58 commit 948e5fa

File tree

23 files changed

+58
-29
lines changed

23 files changed

+58
-29
lines changed

app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function testBeforeSave($value, $errorMessage = null)
2121
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
2222
);
2323
if ($errorMessage !== null) {
24-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
24+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
25+
$this->expectExceptionMessage($errorMessage);
2526
}
2627
$model->setValue($value);
2728
$object = $model->beforeSave();

app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ public function testSaveWithException()
255255
*/
256256
public function testSaveWithValidateCategoryException($error, $expectedException, $expectedExceptionMessage)
257257
{
258-
$this->expectException($expectedException, $expectedExceptionMessage);
258+
$this->expectException($expectedException);
259+
$this->expectExceptionMessage($expectedExceptionMessage);
259260
$categoryId = 5;
260261
$categoryMock = $this->createMock(\Magento\Catalog\Model\Category::class);
261262
$this->extensibleDataObjectConverterMock

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public function testExecuteWithAdapterErrorThrowsException()
4848
$tableSwitcherMock
4949
);
5050

51-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
51+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
52+
$this->expectExceptionMessage($exceptionMessage);
5253

5354
$model->execute();
5455
}

app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/FullTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function testExecuteWithAdapterErrorThrowsException()
4444
]
4545
);
4646

47-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
47+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
48+
$this->expectExceptionMessage($exceptionMessage);
4849

4950
$model->execute();
5051
}

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/RegexceptionsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public function testRenderCellTemplateWrongColumnName()
128128

129129
$this->object->addColumn($wrongColumnName, $this->cellParameters);
130130

131-
$this->expectException('\Exception', 'Wrong column name specified.');
131+
$this->expectException('\Exception');
132+
$this->expectExceptionMessage('Wrong column name specified.');
132133

133134
$this->object->renderCellTemplate($columnName);
134135
}

app/code/Magento/Config/Test/Unit/Model/Config/Structure/Mapper/Helper/RelativePathConverterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function testConvertWithInvalidRelativePath()
2424

2525
$exceptionMessage = sprintf('Invalid relative path %s in %s node', $relativePath, $nodePath);
2626

27-
$this->expectException('InvalidArgumentException', $exceptionMessage);
27+
$this->expectException('InvalidArgumentException');
28+
$this->expectExceptionMessage($exceptionMessage);
2829
$this->_sut->convert($nodePath, $relativePath);
2930
}
3031

@@ -35,7 +36,8 @@ public function testConvertWithInvalidRelativePath()
3536
*/
3637
public function testConvertWithInvalidArguments($nodePath, $relativePath)
3738
{
38-
$this->expectException('InvalidArgumentException', 'Invalid arguments');
39+
$this->expectException('InvalidArgumentException');
40+
$this->expectExceptionMessage('Invalid arguments');
3941
$this->_sut->convert($nodePath, $relativePath);
4042
}
4143

app/code/Magento/Config/Test/Unit/Model/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ public function testSetDataByPathEmpty()
280280
public function testSetDataByPathWrongDepth($path, $expectedException)
281281
{
282282
$expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $expectedException;
283-
$this->expectException('\UnexpectedValueException', $expectedException);
283+
$this->expectException('\UnexpectedValueException');
284+
$this->expectExceptionMessage($expectedException);
284285
$value = 'value';
285286
$this->_model->setDataByPath($path, $value);
286287
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ public function testGetListNotConfigurableProduct()
357357
*/
358358
public function testValidateNewOptionData($attributeId, $label, $optionValues, $msg)
359359
{
360-
$this->expectException(\Magento\Framework\Exception\InputException::class, $msg);
360+
$this->expectException(\Magento\Framework\Exception\InputException::class);
361+
$this->expectExceptionMessage($msg);
361362
$optionValueMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\OptionValueInterface::class)
362363
->setMethods(['getValueIndex', 'getPricingValue', 'getIsPercent'])
363364
->getMockForAbstractClass();

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Cache/Tag/ConfigurableTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ protected function setUp()
3232

3333
public function testGetWithScalar()
3434
{
35-
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
35+
$this->expectException(\InvalidArgumentException::class);
36+
$this->expectExceptionMessage('Provided argument is not an object');
3637
$this->model->getTags('scalar');
3738
}
3839

3940
public function testGetTagsWithObject()
4041
{
41-
$this->expectException(\InvalidArgumentException::class, 'Provided argument must be a product');
42+
$this->expectException(\InvalidArgumentException::class);
43+
$this->expectExceptionMessage('Provided argument must be a product');
4244
$this->model->getTags(new \stdClass());
4345
}
4446

app/code/Magento/Customer/Test/Unit/Model/LoggerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function testLog($customerId, $data)
7171
$data = array_filter($data);
7272

7373
if (!$data) {
74-
$this->expectException('\InvalidArgumentException', 'Log data is empty');
74+
$this->expectException('\InvalidArgumentException');
75+
$this->expectExceptionMessage('Log data is empty');
7576
$this->logger->log($customerId, $data);
7677
return;
7778
}

app/code/Magento/Directory/Test/Unit/Model/Currency/Import/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ protected function setUp()
2929
*/
3030
public function testConstructorException(array $configData, $expectedException)
3131
{
32-
$this->expectException('InvalidArgumentException', $expectedException);
32+
$this->expectException('InvalidArgumentException');
33+
$this->expectExceptionMessage($expectedException);
3334
new \Magento\Directory\Model\Currency\Import\Config($configData);
3435
}
3536

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function testValidateWithExistingName($attributeSetName, $exceptionMessag
4444
{
4545
$this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false));
4646

47-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
47+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
48+
$this->expectExceptionMessage($exceptionMessage);
4849
$this->_model->setAttributeSetName($attributeSetName);
4950
$this->_model->validate();
5051
}

app/code/Magento/Email/Test/Unit/Model/Template/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ public function testGetterMethodUnknownField(
311311
array $fixtureFields = [],
312312
$argument = null
313313
) {
314-
$this->expectException('UnexpectedValueException', $expectedException);
314+
$this->expectException('UnexpectedValueException');
315+
$this->expectExceptionMessage($expectedException);
315316
$dataStorage = $this->createPartialMock(\Magento\Email\Model\Template\Config\Data::class, ['get']);
316317
$dataStorage->expects(
317318
$this->atLeastOnce()

app/code/Magento/Integration/Test/Unit/Model/Oauth/TokenTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ public function testValidateIfNotCallbackEstablishedAndNotValid()
384384
$this->validatorMock->expects($this->once())->method('isValid')->willReturn(false);
385385
$this->validatorMock->expects($this->once())->method('getMessages')->willReturn([$exceptionMessage]);
386386

387-
$this->expectException(\Magento\Framework\Oauth\Exception::class, $exceptionMessage);
387+
$this->expectException(\Magento\Framework\Oauth\Exception::class);
388+
$this->expectExceptionMessage($exceptionMessage);
388389

389390
$this->tokenModel->validate();
390391
}
@@ -402,7 +403,8 @@ public function testValidateIfSecretNotValid()
402403
$this->validatorKeyLengthMock->expects($this->once())->method('isValid')->willReturn(false);
403404
$this->validatorKeyLengthMock->expects($this->once())->method('getMessages')->willReturn([$exceptionMessage]);
404405

405-
$this->expectException(\Magento\Framework\Oauth\Exception::class, $exceptionMessage);
406+
$this->expectException(\Magento\Framework\Oauth\Exception::class);
407+
$this->expectExceptionMessage($exceptionMessage);
406408

407409
$this->tokenModel->validate();
408410
}
@@ -429,7 +431,8 @@ public function testValidateIfTokenNotValid()
429431
]
430432
);
431433
$this->validatorKeyLengthMock->expects($this->once())->method('getMessages')->willReturn([$exceptionMessage]);
432-
$this->expectException(\Magento\Framework\Oauth\Exception::class, $exceptionMessage);
434+
$this->expectException(\Magento\Framework\Oauth\Exception::class);
435+
$this->expectExceptionMessage($exceptionMessage);
433436

434437
$this->tokenModel->validate();
435438
}
@@ -459,7 +462,8 @@ public function testValidateIfVerifierNotValid()
459462
]
460463
);
461464
$this->validatorKeyLengthMock->expects($this->once())->method('getMessages')->willReturn([$exceptionMessage]);
462-
$this->expectException(\Magento\Framework\Oauth\Exception::class, $exceptionMessage);
465+
$this->expectException(\Magento\Framework\Oauth\Exception::class);
466+
$this->expectExceptionMessage($exceptionMessage);
463467

464468
$this->tokenModel->validate();
465469
}

app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ protected function _invokeNvpProperty(\Magento\Paypal\Model\Api\Nvp $nvpObject,
132132
public function testCall($response, $processableErrors, $exception, $exceptionMessage = '', $exceptionCode = null)
133133
{
134134
if (isset($exception)) {
135-
$this->expectException($exception, $exceptionMessage, $exceptionCode);
135+
$this->expectException($exception);
136+
$this->expectExceptionMessage($exceptionMessage, $exceptionCode);
136137
}
137138
$this->curl->expects($this->once())
138139
->method('read')

app/code/Magento/Rule/Test/Unit/Model/ConditionFactoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function testCreateExceptionClass()
7878
->expects($this->never())
7979
->method('create');
8080

81-
$this->expectException(\InvalidArgumentException::class, 'Class does not exist');
81+
$this->expectException(\InvalidArgumentException::class);
82+
$this->expectExceptionMessage('Class does not exist');
8283

8384
$this->conditionFactory->create($type);
8485
}
@@ -92,7 +93,8 @@ public function testCreateExceptionType()
9293
->method('create')
9394
->with($type)
9495
->willReturn(new \stdClass());
95-
$this->expectException(\InvalidArgumentException::class, 'Class does not implement condition interface');
96+
$this->expectException(\InvalidArgumentException::class);
97+
$this->expectExceptionMessage('Class does not implement condition interface');
9698
$this->conditionFactory->create($type);
9799
}
98100
}

app/code/Magento/SalesRule/Test/Unit/Model/CouponRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public function testSaveWithExceptions($exceptionObject, $exceptionName, $except
150150
$this->resource->expects($this->once())->method('save')->with($coupon)
151151
->willThrowException($exceptionObject);
152152
}
153-
$this->expectException($exceptionName, $exceptionMessage);
153+
$this->expectException($exceptionName);
154+
$this->expectExceptionMessage($exceptionMessage);
154155
$this->model->save($coupon);
155156
}
156157

app/code/Magento/Tax/Test/Unit/Model/Calculation/RateRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ public function testSaveThrowsExceptionIfCannotSaveTitles($expectedException, $e
307307
->with($rateTitles)
308308
->willThrowException($expectedException);
309309
$this->rateRegistryMock->expects($this->never())->method('registerTaxRate')->with($rateMock);
310-
$this->expectException($exceptionType, $exceptionMessage);
310+
$this->expectException($exceptionType);
311+
$this->expectExceptionMessage($exceptionMessage);
311312
$this->model->save($rateMock);
312313
}
313314

app/code/Magento/Tax/Test/Unit/Model/Calculation/RateTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ protected function setUp()
4747
*/
4848
public function testExceptionOfValidation($exceptionMessage, $data)
4949
{
50-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
50+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
51+
$this->expectExceptionMessage($exceptionMessage);
5152
$rate = $this->objectHelper->getObject(
5253
\Magento\Tax\Model\Calculation\Rate::class,
5354
['resource' => $this->resourceMock]

app/code/Magento/Tax/Test/Unit/Model/TaxRuleRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ public function testSaveWithExceptions($exceptionObject, $exceptionName, $except
163163
->willThrowException($exceptionObject);
164164
$this->taxRuleRegistry->expects($this->never())->method('registerTaxRule');
165165

166-
$this->expectException($exceptionName, $exceptionMessage);
166+
$this->expectException($exceptionName);
167+
$this->expectExceptionMessage($exceptionMessage);
167168
$this->model->save($rule);
168169
}
169170

app/code/Magento/Theme/Test/Unit/Observer/CleanThemeRelatedContentObserverTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public function testCleanThemeRelatedContentException()
105105

106106
$this->themeConfig->expects($this->any())->method('isThemeAssignedToStore')->with($themeMock)->willReturn(true);
107107

108-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, 'Theme isn\'t deletable.');
108+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
109+
$this->expectExceptionMessage('Theme isn\'t deletable.');
109110
$this->themeObserver->execute($observerMock);
110111
}
111112

app/code/Magento/Webapi/Test/Unit/ExceptionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function testConstruct()
4343
*/
4444
public function testConstructInvalidHttpCode($httpCode)
4545
{
46-
$this->expectException('InvalidArgumentException', "The specified HTTP code \"{$httpCode}\" is invalid.");
46+
$this->expectException('InvalidArgumentException');
47+
$this->expectExceptionMessage("The specified HTTP code \"{$httpCode}\" is invalid.");
4748
/** Create \Magento\Framework\Webapi\Exception object with invalid code. */
4849
/** Valid codes range is from 400 to 599. */
4950
new \Magento\Framework\Webapi\Exception(__('Message'), 0, $httpCode);

app/code/Magento/Weee/Test/Unit/Model/Attribute/Backend/Weee/TaxTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public function testValidate($data, $expected)
8080
->will($this->returnValue($taxes));
8181

8282
// Exception caught
83-
$this->expectException('Exception', $expected);
83+
$this->expectException('Exception');
84+
$this->expectExceptionMessage($expected);
8485
$modelMock->validate($productMock);
8586
}
8687

0 commit comments

Comments
 (0)