Skip to content

Commit 948e5fa

Browse files
schmenglerMastiuhin Oleksandr
authored andcommitted
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
}

0 commit comments

Comments
 (0)