Skip to content

Commit d2e0d44

Browse files
committed
Replace expectException(, ) in unit tests
expectException(); expectExceptionMessage()
1 parent 304c734 commit d2e0d44

File tree

24 files changed

+60
-30
lines changed

24 files changed

+60
-30
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
@@ -20,7 +20,8 @@ public function testBeforeSave($value, $errorMessage = null)
2020
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
2121
);
2222
if ($errorMessage !== null) {
23-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
23+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
24+
$this->expectExceptionMessage($errorMessage);
2425
}
2526
$model->setValue($value);
2627
$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/Console/Command/ConfigSet/ProcessorFacadeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public function testProcess()
132132
*/
133133
public function testProcessWithValidatorException(LocalizedException $exception)
134134
{
135-
$this->expectException(ValidatorException::class, 'Some error');
135+
$this->expectException(ValidatorException::class);
136+
$this->expectExceptionMessage('Some error');
136137
$this->scopeValidatorMock->expects($this->once())
137138
->method('isValid')
138139
->willThrowException($exception);

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
@@ -356,7 +356,8 @@ public function testGetListNotConfigurableProduct()
356356
*/
357357
public function testValidateNewOptionData($attributeId, $label, $optionValues, $msg)
358358
{
359-
$this->expectException(\Magento\Framework\Exception\InputException::class, $msg);
359+
$this->expectException(\Magento\Framework\Exception\InputException::class);
360+
$this->expectExceptionMessage($msg);
360361
$optionValueMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\OptionValueInterface::class)
361362
->setMethods(['getValueIndex', 'getPricingValue', 'getIsPercent'])
362363
->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

0 commit comments

Comments
 (0)