Skip to content

[Forwardport] Fix syntax of expectException() calls #14621

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 10 commits into from
Apr 17, 2018
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 @@ -21,7 +21,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 @@ -54,12 +54,10 @@ public function testCreateNegative()
$this->returnValue($defaultCaptchaMock)
);

$this->expectException(
'InvalidArgumentException',
'Magento\Captcha\Model\\' . ucfirst(
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Magento\Captcha\Model\\' . ucfirst(
$captchaType
) . ' does not implement \Magento\Captcha\Model\CaptchaInterface'
);
) . ' does not implement \Magento\Captcha\Model\CaptchaInterface');

$this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ protected function setUp()

public function testCreateWithInvalidType()
{
$this->expectException(
'\InvalidArgumentException',
\Magento\Framework\DataObject::class . ' does not implement ' .
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\HandlerInterface::class
);
$this->expectException('\InvalidArgumentException');
$this->expectExceptionMessage(\Magento\Framework\DataObject::class . ' does not implement ' .
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\HandlerInterface::class);
$this->_objectManagerMock->expects($this->never())->method('create');
$this->_model->create(\Magento\Framework\DataObject::class);
}
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 Expand Up @@ -284,7 +285,8 @@ public function saveWithValidateCategoryExceptionDataProvider()
return [
[
true, \Magento\Framework\Exception\CouldNotSaveException::class,
'Could not save category: Attribute "ValidateCategoryTest" is required.',
'Could not save category: Attribute The "ValidateCategoryTest" attribute is required.' .
'Enter and try again.',
], [
'Something went wrong', \Magento\Framework\Exception\CouldNotSaveException::class,
'Could not save category: Something went wrong'
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 @@ -27,8 +27,8 @@ protected function setUp()

public function testCreateWithInvalidType()
{
$this->expectException(
'\InvalidArgumentException',
$this->expectException('\InvalidArgumentException');
$this->expectExceptionMessage(
'Magento\Framework\DataObject does not implement \Magento\Catalog\Model\Product\CopyConstructorInterface'
);
$this->_objectManagerMock->expects($this->never())->method('create');
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
6 changes: 2 additions & 4 deletions app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,8 @@ public function testGetCurrentPath($pathId, $expectedPath, $isExist)

public function testGetCurrentPathThrowException()
{
$this->expectException(
\Magento\Framework\Exception\LocalizedException::class,
'The directory PATH/wysiwyg is not writable by server.'
);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage('The directory PATH is not writable by server.');

$this->directoryWriteMock->expects($this->once())
->method('isExist')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ public function testGetResizeHeight()
*/
public function testDeleteDirectoryOverRoot()
{
$this->expectException(
\Magento\Framework\Exception\LocalizedException::class,
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage(
sprintf('Directory %s is not under storage root path.', self::INVALID_DIRECTORY_OVER_ROOT)
);
$this->imagesStorage->deleteDirectory(self::INVALID_DIRECTORY_OVER_ROOT);
Expand All @@ -251,10 +251,9 @@ public function testDeleteDirectoryOverRoot()
*/
public function testDeleteRootDirectory()
{
$this->expectException(
\Magento\Framework\Exception\LocalizedException::class,
sprintf('We can\'t delete root directory %s right now.', self::STORAGE_ROOT_DIR)
);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage(sprintf('We can\'t delete root directory %s right now.', self::STORAGE_ROOT_DIR));

$this->imagesStorage->deleteDirectory(self::STORAGE_ROOT_DIR);
}

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 @@ -31,10 +31,8 @@ public function testMap($sourceData, $resultData)

public function testMapWithBadPath()
{
$this->expectException(
'InvalidArgumentException',
'Invalid path in extends attribute of config/system/sections/section1 node'
);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid path in extends attribute of config/system/sections/section1 node');
$sourceData = [
'config' => [
'system' => ['sections' => ['section1' => ['extends' => 'nonExistentSection2']]],
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 @@ -357,7 +357,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
28 changes: 10 additions & 18 deletions app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,19 +757,15 @@ public function testCreateAccountWithPasswordInputException(
->willReturn(iconv_strlen($password, 'UTF-8'));

if ($testNumber == 1) {
$this->expectException(
\Magento\Framework\Exception\InputException::class,
'The password needs at least ' . $minPasswordLength . ' characters. '
. 'Create a new password and try again.'
);
$this->expectException(\Magento\Framework\Exception\InputException::class);
$this->expectExceptionMessage('The password needs at least ' . $minPasswordLength . ' characters. '
. 'Create a new password and try again.');
}

if ($testNumber == 2) {
$this->expectException(
\Magento\Framework\Exception\InputException::class,
'Minimum of different classes of characters in password is ' . $minCharacterSetsNum .
'. Classes of characters: Lower Case, Upper Case, Digits, Special Characters.'
);
$this->expectException(\Magento\Framework\Exception\InputException::class);
$this->expectExceptionMessage('Minimum of different classes of characters in password is ' . $minCharacterSetsNum .
'. Classes of characters: Lower Case, Upper Case, Digits, Special Characters.');
}

$customer = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)->getMock();
Expand All @@ -787,10 +783,8 @@ public function testCreateAccountInputExceptionExtraLongPassword()
->with($password)
->willReturn(iconv_strlen($password, 'UTF-8'));

$this->expectException(
\Magento\Framework\Exception\InputException::class,
'Please enter a password with at most 256 characters.'
);
$this->expectException(\Magento\Framework\Exception\InputException::class);
$this->expectExceptionMessage('Please enter a password with at most 256 characters.');

$customer = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)->getMock();
$this->accountManagement->createAccount($customer, $password);
Expand Down Expand Up @@ -1568,10 +1562,8 @@ public function testChangePasswordException()
->with($email)
->willThrowException($exception);

$this->expectException(
\Magento\Framework\Exception\InvalidEmailOrPasswordException::class,
'Invalid login or password.'
);
$this->expectException(\Magento\Framework\Exception\InvalidEmailOrPasswordException::class);
$this->expectExceptionMessage('Invalid login or password.');

$this->accountManagement->changePassword($email, $currentPassword, $newPassword);
}
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 @@ -93,10 +93,8 @@ public function testIteratorNegative()
{
$filePath = $this->filePaths[0];

$this->expectException(
'UnexpectedValueException',
sprintf("Unable to determine a module, file '%s' belongs to.", $filePath)
);
$this->expectException('UnexpectedValueException');
$this->expectExceptionMessage(sprintf("Unable to determine a module, file '%s' belongs to.", $filePath));

$this->moduleDirResolverMock->expects($this->at(0))
->method('getModuleName')
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
8 changes: 3 additions & 5 deletions app/code/Magento/Integration/Test/Unit/Oauth/OauthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,9 @@ public function testBuildAuthorizationHeader()
*/
public function testMissingParamForBuildAuthorizationHeader($expectedMessage, $request)
{
$this->expectException(
\Magento\Framework\Oauth\OauthInputException::class,
$expectedMessage,
0
);
$this->expectException(\Magento\Framework\Oauth\OauthInputException::class);
$this->expectExceptionMessage($expectedMessage);
$this->expectExceptionCode(0);

$requestUrl = 'http://www.example.com/endpoint';
$this->_oauth->buildAuthorizationHeader($request, $requestUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ public function testGetMethodSuccess()

public function testGetMethodNotTransparentInterface()
{
$this->expectException(
\Magento\Framework\Exception\LocalizedException::class,
__('We cannot retrieve the transparent payment method model object.')
);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage((string)__('We cannot retrieve the transparent payment method model object.'));

$methodMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
->getMockForAbstractClass();
Expand Down
4 changes: 3 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 @@ -132,7 +132,9 @@ 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);
$this->expectExceptionCode($exceptionCode);
}
$this->curl->expects($this->once())
->method('read')
Expand Down
Loading