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();

app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public function testCall($response, $processableErrors, $exception, $exceptionMe
133133
{
134134
if (isset($exception)) {
135135
$this->expectException($exception);
136-
$this->expectExceptionMessage($exceptionMessage, $exceptionCode);
136+
$this->expectExceptionMessage($exceptionMessage);
137+
$this->expectExceptionCode($exceptionCode);
137138
}
138139
$this->curl->expects($this->once())
139140
->method('read')

app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/Handler/HandlerCompositeTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ public function testConstructorSuccess()
2323

2424
public function testConstructorException()
2525
{
26-
$this->expectException(
27-
'LogicException',
28-
'Type mismatch. Expected type: HandlerInterface. Actual: string, Code: weird_handler'
29-
);
26+
$this->expectException('LogicException');
27+
$this->expectExceptionMessage('Type mismatch. Expected type: HandlerInterface. Actual: string, Code: weird_handler');
3028

3129
new HandlerComposite(
3230
['weird_handler' => 'some value']

app/code/Magento/Security/Test/Unit/Model/SecurityManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public function testConstructorException()
126126
{
127127
$securityChecker = $this->createMock(\Magento\Framework\Message\ManagerInterface::class);
128128

129-
$this->expectException(
130-
\Magento\Framework\Exception\LocalizedException::class,
129+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
130+
$this->expectExceptionMessage(
131131
__('Incorrect Security Checker class. It has to implement SecurityCheckerInterface')
132132
);
133133

app/code/Magento/Signifyd/Test/Unit/Model/SignifydGateway/GatewayTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ public function testCreateCaseWithFailedApiCall()
121121
->method('makeApiCall')
122122
->willThrowException(new ApiCallException($apiCallFailureMessage));
123123

124-
$this->expectException(
125-
GatewayException::class,
126-
$apiCallFailureMessage
127-
);
124+
$this->expectException(GatewayException::class);
125+
$this->expectExceptionMessage($apiCallFailureMessage);
128126
$this->gateway->createCase($dummyOrderId);
129127
}
130128

@@ -197,10 +195,8 @@ public function testSubmitCaseForGuaranteeWithFailedApiCall()
197195
->method('makeApiCall')
198196
->willThrowException(new ApiCallException($apiCallFailureMessage));
199197

200-
$this->expectException(
201-
GatewayException::class,
202-
$apiCallFailureMessage
203-
);
198+
$this->expectException(GatewayException::class);
199+
$this->expectExceptionMessage($apiCallFailureMessage);
204200
$result = $this->gateway->submitCaseForGuarantee($dummySygnifydCaseId);
205201
$this->assertEquals('Api call failed', $result);
206202
}

app/code/Magento/Tax/Test/Unit/Model/TaxClass/FactoryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ public function testCreateWithWrongClassType()
7070

7171
$taxClassFactory = new \Magento\Tax\Model\TaxClass\Factory($objectManager);
7272

73-
$this->expectException(
74-
\Magento\Framework\Exception\LocalizedException::class,
75-
sprintf('Invalid type of tax class "%s"', $wrongClassType)
76-
);
73+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
74+
$this->expectExceptionMessage(sprintf('Invalid type of tax class "%s"', $wrongClassType));
7775
$taxClassFactory->create($classMock);
7876
}
7977
}

app/code/Magento/Ui/Test/Unit/Model/ManagerTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,8 @@ public function testGetReader()
152152

153153
public function testPrepareDataWithoutName()
154154
{
155-
$this->expectException(
156-
\Magento\Framework\Exception\LocalizedException::class,
157-
__('The "" UI component element name is invalid. Verify the name and try again.')
158-
);
155+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
156+
$this->expectExceptionMessage(__('The "" UI component element name is invalid. Verify the name and try again.'));
159157
$this->manager->prepareData(null);
160158
}
161159

app/code/Magento/Ui/Test/Unit/Model/ResourceModel/BookmarkRepositoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function testSaveWithException()
9595
->with($this->bookmarkMock)
9696
->willThrowException(new \Exception($exceptionMessage));
9797
$this->expectException(\Magento\Framework\Exception\CouldNotSaveException::class);
98+
$this->expectExceptionMessage(__($exceptionMessage));
9899
$this->expectExceptionMessage($exceptionMessage);
99100
$this->bookmarkRepository->save($this->bookmarkMock);
100101
}
@@ -122,8 +123,8 @@ public function testGetByIdWithException()
122123
->method('load')
123124
->with($this->bookmarkMock, $notExistsBookmarkId)
124125
->willReturn($this->bookmarkMock);
125-
$this->expectException(
126-
\Magento\Framework\Exception\NoSuchEntityException::class,
126+
$this->expectException(\Magento\Framework\Exception\NoSuchEntityException::class);
127+
$this->expectExceptionMessage(
127128
__('The bookmark with "%1" ID doesn\'t exist. Verify your information and try again.', $notExistsBookmarkId)
128129
);
129130
$this->bookmarkRepository->getById($notExistsBookmarkId);
@@ -145,6 +146,7 @@ public function testDeleteWithException()
145146
->with($this->bookmarkMock)
146147
->willThrowException(new \Exception($exceptionMessage));
147148
$this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class);
149+
$this->expectExceptionMessage(__($exceptionMessage));
148150
$this->expectExceptionMessage($exceptionMessage);
149151
$this->assertTrue($this->bookmarkRepository->delete($this->bookmarkMock));
150152
}

app/code/Magento/User/Test/Unit/Model/UserTest.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,9 @@ public function testVerifyIdentityInactiveRecord()
350350
->with($password, $this->model->getPassword())
351351
->willReturn(true);
352352
$this->model->setIsActive(false);
353-
$this->expectException(
354-
\Magento\Framework\Exception\AuthenticationException::class,
355-
'The account sign-in was incorrect or your account is disabled temporarily. '
356-
. 'Please wait and try again later.'
357-
);
353+
$this->expectException(\Magento\Framework\Exception\AuthenticationException::class);
354+
$this->expectExceptionMessage('The account sign-in was incorrect or your account is disabled temporarily. '
355+
. 'Please wait and try again later.');
358356
$this->model->verifyIdentity($password);
359357
}
360358

@@ -371,10 +369,8 @@ public function testVerifyIdentityNoAssignedRoles()
371369
->willReturn(true);
372370
$this->model->setIsActive(true);
373371
$this->resourceMock->expects($this->once())->method('hasAssigned2Role')->willReturn(false);
374-
$this->expectException(
375-
\Magento\Framework\Exception\AuthenticationException::class,
376-
'More permissions are needed to access this.'
377-
);
372+
$this->expectException(\Magento\Framework\Exception\AuthenticationException::class);
373+
$this->expectExceptionMessage('More permissions are needed to access this.');
378374
$this->model->verifyIdentity($password);
379375
}
380376

@@ -782,15 +778,13 @@ public function testPerformIdentityCheck($verifyIdentityResult, $lockExpires)
782778
->willReturnSelf();
783779

784780
if ($lockExpires) {
785-
$this->expectException(
786-
\Magento\Framework\Exception\State\UserLockedException::class,
787-
__('Your account is temporarily disabled. Please try again later.')
788-
);
781+
$this->expectException(\Magento\Framework\Exception\State\UserLockedException::class);
782+
$this->expectExceptionMessage(__('Your account is temporarily disabled. Please try again later.'));
789783
}
790784

791785
if (!$verifyIdentityResult) {
792-
$this->expectException(
793-
\Magento\Framework\Exception\AuthenticationException::class,
786+
$this->expectException(\Magento\Framework\Exception\AuthenticationException::class);
787+
$this->expectExceptionMessage(
794788
__('The password entered for the current user is invalid. Verify the password and try again.')
795789
);
796790
}

app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ public function testSetAndSaveItemOptions()
300300
public function testGetProductWithException()
301301
{
302302
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
303+
$this->expectExceptionMessage(__('Cannot specify product.'));
303304
$this->expectExceptionMessage('Cannot specify product.');
304305
$this->model->getProduct();
305306
}

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function testAddNegative($optionData)
217217
}
218218
} else {
219219
$this->expectException('Exception');
220-
$this->expectExceptionMessage('', 400);
220+
$this->expectExceptionMessage(400);
221221
}
222222
$this->_webApiCall($serviceInfo, ['option' => $optionDataPost]);
223223
}

dev/tests/api-functional/testsuite/Magento/Customer/Api/AddressRepositoryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ public function testDeleteAddress()
114114
$response = $this->_webApiCall($serviceInfo, $requestData);
115115
$this->assertTrue($response, 'Expected response should be true.');
116116

117-
$this->expectException(
118-
\Magento\Framework\Exception\NoSuchEntityException::class,
119-
'No such entity with addressId = 1'
120-
);
117+
$this->expectException(\Magento\Framework\Exception\NoSuchEntityException::class);
118+
$this->expectExceptionMessage('No such entity with addressId = 1');
121119
$this->addressRepository->getById($fixtureAddressId);
122120
}
123121

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerRepositoryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ public function testDeleteCustomer()
217217
$this->assertTrue($response);
218218

219219
//Verify if the customer is deleted
220-
$this->expectException(
221-
\Magento\Framework\Exception\NoSuchEntityException::class,
222-
sprintf("No such entity with customerId = %s", $customerData[Customer::ID])
223-
);
220+
$this->expectException(\Magento\Framework\Exception\NoSuchEntityException::class);
221+
$this->expectExceptionMessage(sprintf("No such entity with customerId = %s", $customerData[Customer::ID]));
224222
$this->_getCustomerData($customerData[Customer::ID]);
225223
}
226224

0 commit comments

Comments
 (0)