Skip to content

Commit 87b3b58

Browse files
author
Mastiuhin Oleksandr
committed
Fix calling TestCase::expectException()
1 parent a205337 commit 87b3b58

File tree

66 files changed

+193
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+193
-275
lines changed

app/code/Magento/Captcha/Test/Unit/Model/CaptchaFactoryTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ public function testCreateNegative()
5454
$this->returnValue($defaultCaptchaMock)
5555
);
5656

57-
$this->expectException(
58-
'InvalidArgumentException',
59-
'Magento\Captcha\Model\\' . ucfirst(
57+
$this->expectException('InvalidArgumentException');
58+
$this->expectExceptionMessage('Magento\Captcha\Model\\' . ucfirst(
6059
$captchaType
61-
) . ' does not implement \Magento\Captcha\Model\CaptchaInterface'
62-
);
60+
) . ' does not implement \Magento\Captcha\Model\CaptchaInterface');
6361

6462
$this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
6563
}

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/HandlerFactoryTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ protected function setUp()
2727

2828
public function testCreateWithInvalidType()
2929
{
30-
$this->expectException(
31-
'\InvalidArgumentException',
32-
\Magento\Framework\DataObject::class . ' does not implement ' .
33-
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\HandlerInterface::class
34-
);
30+
$this->expectException('\InvalidArgumentException');
31+
$this->expectExceptionMessage(\Magento\Framework\DataObject::class . ' does not implement ' .
32+
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\HandlerInterface::class);
3533
$this->_objectManagerMock->expects($this->never())->method('create');
3634
$this->_model->create(\Magento\Framework\DataObject::class);
3735
}

app/code/Magento/Catalog/Test/Unit/Model/Product/CopyConstructorFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ protected function setUp()
2727

2828
public function testCreateWithInvalidType()
2929
{
30-
$this->expectException(
31-
'\InvalidArgumentException',
30+
$this->expectException('\InvalidArgumentException');
31+
$this->expectExceptionMessage(
3232
'Magento\Framework\DataObject does not implement \Magento\Catalog\Model\Product\CopyConstructorInterface'
3333
);
3434
$this->_objectManagerMock->expects($this->never())->method('create');

app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,8 @@ public function testGetCurrentPath($pathId, $expectedPath, $isExist)
379379

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

387385
$this->directoryWriteMock->expects($this->once())
388386
->method('isExist')

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public function testGetResizeHeight()
239239
*/
240240
public function testDeleteDirectoryOverRoot()
241241
{
242-
$this->expectException(
243-
\Magento\Framework\Exception\LocalizedException::class,
242+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
243+
$this->expectExceptionMessage(
244244
sprintf('Directory %s is not under storage root path.', self::INVALID_DIRECTORY_OVER_ROOT)
245245
);
246246
$this->imagesStorage->deleteDirectory(self::INVALID_DIRECTORY_OVER_ROOT);
@@ -251,10 +251,9 @@ public function testDeleteDirectoryOverRoot()
251251
*/
252252
public function testDeleteRootDirectory()
253253
{
254-
$this->expectException(
255-
\Magento\Framework\Exception\LocalizedException::class,
256-
sprintf('We can\'t delete root directory %s right now.', self::STORAGE_ROOT_DIR)
257-
);
254+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
255+
$this->expectExceptionMessage(sprintf('We can\'t delete root directory %s right now.', self::STORAGE_ROOT_DIR));
256+
258257
$this->imagesStorage->deleteDirectory(self::STORAGE_ROOT_DIR);
259258
}
260259

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public function testMap($sourceData, $resultData)
3131

3232
public function testMapWithBadPath()
3333
{
34-
$this->expectException(
35-
'InvalidArgumentException',
36-
'Invalid path in extends attribute of config/system/sections/section1 node'
37-
);
34+
$this->expectException('InvalidArgumentException');
35+
$this->expectExceptionMessage('Invalid path in extends attribute of config/system/sections/section1 node');
3836
$sourceData = [
3937
'config' => [
4038
'system' => ['sections' => ['section1' => ['extends' => 'nonExistentSection2']]],

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -757,19 +757,15 @@ public function testCreateAccountWithPasswordInputException(
757757
->willReturn(iconv_strlen($password, 'UTF-8'));
758758

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

767765
if ($testNumber == 2) {
768-
$this->expectException(
769-
\Magento\Framework\Exception\InputException::class,
770-
'Minimum of different classes of characters in password is ' . $minCharacterSetsNum .
771-
'. Classes of characters: Lower Case, Upper Case, Digits, Special Characters.'
772-
);
766+
$this->expectException(\Magento\Framework\Exception\InputException::class);
767+
$this->expectExceptionMessage('Minimum of different classes of characters in password is ' . $minCharacterSetsNum .
768+
'. Classes of characters: Lower Case, Upper Case, Digits, Special Characters.');
773769
}
774770

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

790-
$this->expectException(
791-
\Magento\Framework\Exception\InputException::class,
792-
'Please enter a password with at most 256 characters.'
793-
);
786+
$this->expectException(\Magento\Framework\Exception\InputException::class);
787+
$this->expectExceptionMessage('Please enter a password with at most 256 characters.');
794788

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

1571-
$this->expectException(
1572-
\Magento\Framework\Exception\InvalidEmailOrPasswordException::class,
1573-
'Invalid login or password.'
1574-
);
1565+
$this->expectException(\Magento\Framework\Exception\InvalidEmailOrPasswordException::class);
1566+
$this->expectExceptionMessage('Invalid login or password.');
15751567

15761568
$this->accountManagement->changePassword($email, $currentPassword, $newPassword);
15771569
}

app/code/Magento/Email/Test/Unit/Model/Template/Config/FileIteratorTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ public function testIteratorNegative()
9393
{
9494
$filePath = $this->filePaths[0];
9595

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

10199
$this->moduleDirResolverMock->expects($this->at(0))
102100
->method('getModuleName')

app/code/Magento/Integration/Test/Unit/Oauth/OauthTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,9 @@ public function testBuildAuthorizationHeader()
777777
*/
778778
public function testMissingParamForBuildAuthorizationHeader($expectedMessage, $request)
779779
{
780-
$this->expectException(
781-
\Magento\Framework\Oauth\OauthInputException::class,
782-
$expectedMessage,
783-
0
784-
);
780+
$this->expectException(\Magento\Framework\Oauth\OauthInputException::class);
781+
$this->expectExceptionMessage($expectedMessage);
782+
$this->expectExceptionCode(0);
785783

786784
$requestUrl = 'http://www.example.com/endpoint';
787785
$this->_oauth->buildAuthorizationHeader($request, $requestUrl);

app/code/Magento/Payment/Test/Unit/Block/Transparent/FormTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,8 @@ public function testGetMethodSuccess()
290290

291291
public function testGetMethodNotTransparentInterface()
292292
{
293-
$this->expectException(
294-
\Magento\Framework\Exception\LocalizedException::class,
295-
__('We cannot retrieve the transparent payment method model object.')
296-
);
293+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
294+
$this->expectExceptionMessage(__('We cannot retrieve the transparent payment method model object.'));
297295

298296
$methodMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
299297
->getMockForAbstractClass();

0 commit comments

Comments
 (0)