Skip to content

Fix syntax of expectException() calls #11099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function testBeforeSave($value, $errorMessage = null)
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
);
if ($errorMessage !== null) {
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage($errorMessage);
}
$model->setValue($value);
$object = $model->beforeSave();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ public function testSaveWithException()
*/
public function testSaveWithValidateCategoryException($error, $expectedException, $expectedExceptionMessage)
{
$this->expectException($expectedException, $expectedExceptionMessage);
$this->expectException($expectedException);
$this->expectExceptionMessage($expectedExceptionMessage);
$categoryId = 5;
$categoryMock = $this->createMock(\Magento\Catalog\Model\Category::class);
$this->extensibleDataObjectConverterMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function testExecuteWithAdapterErrorThrowsException()
$tableSwitcherMock
);

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

$model->execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function testExecuteWithAdapterErrorThrowsException()
]
);

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

$model->execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public function testRenderCellTemplateWrongColumnName()

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

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

$this->object->renderCellTemplate($columnName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public function testProcess()
*/
public function testProcessWithValidatorException(LocalizedException $exception)
{
$this->expectException(ValidatorException::class, 'Some error');
$this->expectException(ValidatorException::class);
$this->expectExceptionMessage('Some error');
$this->scopeValidatorMock->expects($this->once())
->method('isValid')
->willThrowException($exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function testConvertWithInvalidRelativePath()

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

$this->expectException('InvalidArgumentException', $exceptionMessage);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage($exceptionMessage);
$this->_sut->convert($nodePath, $relativePath);
}

Expand All @@ -35,7 +36,8 @@ public function testConvertWithInvalidRelativePath()
*/
public function testConvertWithInvalidArguments($nodePath, $relativePath)
{
$this->expectException('InvalidArgumentException', 'Invalid arguments');
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid arguments');
$this->_sut->convert($nodePath, $relativePath);
}

Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Config/Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public function testSetDataByPathEmpty()
public function testSetDataByPathWrongDepth($path, $expectedException)
{
$expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $expectedException;
$this->expectException('\UnexpectedValueException', $expectedException);
$this->expectException('\UnexpectedValueException');
$this->expectExceptionMessage($expectedException);
$value = 'value';
$this->_model->setDataByPath($path, $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ public function testGetListNotConfigurableProduct()
*/
public function testValidateNewOptionData($attributeId, $label, $optionValues, $msg)
{
$this->expectException(\Magento\Framework\Exception\InputException::class, $msg);
$this->expectException(\Magento\Framework\Exception\InputException::class);
$this->expectExceptionMessage($msg);
$optionValueMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\OptionValueInterface::class)
->setMethods(['getValueIndex', 'getPricingValue', 'getIsPercent'])
->getMockForAbstractClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ protected function setUp()

public function testGetWithScalar()
{
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Provided argument is not an object');
$this->model->getTags('scalar');
}

public function testGetTagsWithObject()
{
$this->expectException(\InvalidArgumentException::class, 'Provided argument must be a product');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Provided argument must be a product');
$this->model->getTags(new \stdClass());
}

Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Customer/Test/Unit/Model/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function testLog($customerId, $data)
$data = array_filter($data);

if (!$data) {
$this->expectException('\InvalidArgumentException', 'Log data is empty');
$this->expectException('\InvalidArgumentException');
$this->expectExceptionMessage('Log data is empty');
$this->logger->log($customerId, $data);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ protected function setUp()
*/
public function testConstructorException(array $configData, $expectedException)
{
$this->expectException('InvalidArgumentException', $expectedException);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage($expectedException);
new \Magento\Directory\Model\Currency\Import\Config($configData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function testValidateWithExistingName($attributeSetName, $exceptionMessag
{
$this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false));

$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage($exceptionMessage);
$this->_model->setAttributeSetName($attributeSetName);
$this->_model->validate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ public function testGetterMethodUnknownField(
array $fixtureFields = [],
$argument = null
) {
$this->expectException('UnexpectedValueException', $expectedException);
$this->expectException('UnexpectedValueException');
$this->expectExceptionMessage($expectedException);
$dataStorage = $this->createPartialMock(\Magento\Email\Model\Template\Config\Data::class, ['get']);
$dataStorage->expects(
$this->atLeastOnce()
Expand Down
12 changes: 8 additions & 4 deletions app/code/Magento/Integration/Test/Unit/Model/Oauth/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public function testValidateIfNotCallbackEstablishedAndNotValid()
$this->validatorMock->expects($this->once())->method('isValid')->willReturn(false);
$this->validatorMock->expects($this->once())->method('getMessages')->willReturn([$exceptionMessage]);

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

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

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

$this->tokenModel->validate();
}
Expand All @@ -429,7 +431,8 @@ public function testValidateIfTokenNotValid()
]
);
$this->validatorKeyLengthMock->expects($this->once())->method('getMessages')->willReturn([$exceptionMessage]);
$this->expectException(\Magento\Framework\Oauth\Exception::class, $exceptionMessage);
$this->expectException(\Magento\Framework\Oauth\Exception::class);
$this->expectExceptionMessage($exceptionMessage);

$this->tokenModel->validate();
}
Expand Down Expand Up @@ -459,7 +462,8 @@ public function testValidateIfVerifierNotValid()
]
);
$this->validatorKeyLengthMock->expects($this->once())->method('getMessages')->willReturn([$exceptionMessage]);
$this->expectException(\Magento\Framework\Oauth\Exception::class, $exceptionMessage);
$this->expectException(\Magento\Framework\Oauth\Exception::class);
$this->expectExceptionMessage($exceptionMessage);

$this->tokenModel->validate();
}
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ protected function _invokeNvpProperty(\Magento\Paypal\Model\Api\Nvp $nvpObject,
public function testCall($response, $processableErrors, $exception, $exceptionMessage = '', $exceptionCode = null)
{
if (isset($exception)) {
$this->expectException($exception, $exceptionMessage, $exceptionCode);
$this->expectException($exception);
$this->expectExceptionMessage($exceptionMessage, $exceptionCode);
}
$this->curl->expects($this->once())
->method('read')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function testCreateExceptionClass()
->expects($this->never())
->method('create');

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

$this->conditionFactory->create($type);
}
Expand All @@ -92,7 +93,8 @@ public function testCreateExceptionType()
->method('create')
->with($type)
->willReturn(new \stdClass());
$this->expectException(\InvalidArgumentException::class, 'Class does not implement condition interface');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Class does not implement condition interface');
$this->conditionFactory->create($type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public function testSaveWithExceptions($exceptionObject, $exceptionName, $except
$this->resource->expects($this->once())->method('save')->with($coupon)
->willThrowException($exceptionObject);
}
$this->expectException($exceptionName, $exceptionMessage);
$this->expectException($exceptionName);
$this->expectExceptionMessage($exceptionMessage);
$this->model->save($coupon);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ public function testSaveThrowsExceptionIfCannotSaveTitles($expectedException, $e
->with($rateTitles)
->willThrowException($expectedException);
$this->rateRegistryMock->expects($this->never())->method('registerTaxRate')->with($rateMock);
$this->expectException($exceptionType, $exceptionMessage);
$this->expectException($exceptionType);
$this->expectExceptionMessage($exceptionMessage);
$this->model->save($rateMock);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected function setUp()
*/
public function testExceptionOfValidation($exceptionMessage, $data)
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage($exceptionMessage);
$rate = $this->objectHelper->getObject(
\Magento\Tax\Model\Calculation\Rate::class,
['resource' => $this->resourceMock]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public function testSaveWithExceptions($exceptionObject, $exceptionName, $except
->willThrowException($exceptionObject);
$this->taxRuleRegistry->expects($this->never())->method('registerTaxRule');

$this->expectException($exceptionName, $exceptionMessage);
$this->expectException($exceptionName);
$this->expectExceptionMessage($exceptionMessage);
$this->model->save($rule);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public function testCleanThemeRelatedContentException()

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function testSaveWithException()
->method('save')
->with($this->bookmarkMock)
->willThrowException(new \Exception($exceptionMessage));
$this->expectException(\Magento\Framework\Exception\CouldNotSaveException::class, __($exceptionMessage));
$this->expectException(\Magento\Framework\Exception\CouldNotSaveException::class);
$this->expectExceptionMessage($exceptionMessage);
$this->bookmarkRepository->save($this->bookmarkMock);
}

Expand Down Expand Up @@ -143,7 +144,8 @@ public function testDeleteWithException()
->method('delete')
->with($this->bookmarkMock)
->willThrowException(new \Exception($exceptionMessage));
$this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class, __($exceptionMessage));
$this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class);
$this->expectExceptionMessage($exceptionMessage);
$this->assertTrue($this->bookmarkRepository->delete($this->bookmarkMock));
}

Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Webapi/Test/Unit/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function testConstruct()
*/
public function testConstructInvalidHttpCode($httpCode)
{
$this->expectException('InvalidArgumentException', "The specified HTTP code \"{$httpCode}\" is invalid.");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("The specified HTTP code \"{$httpCode}\" is invalid.");
/** Create \Magento\Framework\Webapi\Exception object with invalid code. */
/** Valid codes range is from 400 to 599. */
new \Magento\Framework\Webapi\Exception(__('Message'), 0, $httpCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function testValidate($data, $expected)
->will($this->returnValue($taxes));

// Exception caught
$this->expectException('Exception', $expected);
$this->expectException('Exception');
$this->expectExceptionMessage($expected);
$modelMock->validate($productMock);
}

Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ public function testSetAndSaveItemOptions()

public function testGetProductWithException()
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, __('Cannot specify product.'));
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage('Cannot specify product.');
$this->model->getProduct();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,11 @@ public function testGetListForAbsentSku()
'sku' => $productSku,
];
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
$this->expectException('SoapFault', 'Requested product doesn\'t exist');
$this->expectException('SoapFault');
$this->expectExceptionMessage('Requested product doesn\'t exist');
} else {
$this->expectException('Exception', '', 404);
$this->expectException('Exception');
$this->expectExceptionCode(404);
}
$this->_webApiCall($serviceInfo, $requestData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public function testCustomAttributeWrongType()
];

if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
$this->expectException('Exception', 'Attribute "meta_title" has invalid value.');
$this->expectException('Exception');
$this->expectExceptionMessage('Attribute "meta_title" has invalid value.');
} else {
$this->expectException('Exception', 'Attribute \"meta_title\" has invalid value.');
$this->expectException('Exception');
$this->expectExceptionMessage('Attribute \"meta_title\" has invalid value.');
}

$this->_webApiCall($serviceInfo, $this->getRequestData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,15 @@ public function testAddNegative($optionData)

if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
if (isset($optionDataPost['title']) && empty($optionDataPost['title'])) {
$this->expectException('SoapFault', 'Missed values for option required fields');
$this->expectException('SoapFault');
$this->expectExceptionMessage('Missed values for option required fields');
} else {
$this->expectException('SoapFault', 'Invalid option');
$this->expectException('SoapFault');
$this->expectExceptionMessage('Invalid option');
}
} else {
$this->expectException('Exception', '', 400);
$this->expectException('Exception');
$this->expectExceptionMessage('', 400);
}
$this->_webApiCall($serviceInfo, ['option' => $optionDataPost]);
}
Expand Down Expand Up @@ -388,8 +391,9 @@ public function validOptionDataProvider()
* @dataProvider optionNegativeUpdateDataProvider
* @param array $optionData
* @param string $message
* @param int $exceptionCode
*/
public function testUpdateNegative($optionData, $message)
public function testUpdateNegative($optionData, $message, $exceptionCode)
{
$this->_markTestAsRestOnly();
$productSku = 'simple';
Expand All @@ -406,7 +410,9 @@ public function testUpdateNegative($optionData, $message)
],
];

$this->expectException('Exception', $message, 400);
$this->expectException('Exception');
$this->expectExceptionMessage($message);
$this->expectExceptionCode($exceptionCode);
$this->_webApiCall($serviceInfo, ['option' => $optionData]);
}

Expand Down
Loading