Skip to content

Commit 38ec4cb

Browse files
committed
[squash] Add tests for the changes in "catch" behaviour affected by the new exceptions
1 parent 97a04e6 commit 38ec4cb

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@ final class AbstractArrayDeclarationSniffTest extends PolyfilledTestCase
4040
'processComma',
4141
];
4242

43+
/**
44+
* Test receiving an expected exception when an non-integer token pointer is passed.
45+
*
46+
* @return void
47+
*/
48+
public function testNonIntegerToken()
49+
{
50+
$this->expectException('PHPCSUtils\Exceptions\TypeError');
51+
$this->expectExceptionMessage('Argument #2 ($stackPtr) must be of type integer, boolean given');
52+
53+
$mockObj = $this->getMockedClassUnderTest();
54+
55+
$mockObj->expects($this->never())
56+
->method('processOpenClose');
57+
58+
$mockObj->expects($this->never())
59+
->method('processKey');
60+
61+
$mockObj->expects($this->never())
62+
->method('processNoKey');
63+
64+
$mockObj->expects($this->never())
65+
->method('processArrow');
66+
67+
$mockObj->expects($this->never())
68+
->method('processValue');
69+
70+
$mockObj->expects($this->never())
71+
->method('processComma');
72+
73+
$mockObj->process(self::$phpcsFile, false);
74+
}
75+
4376
/**
4477
* Test receiving an expected exception when an invalid token pointer is passed.
4578
*

Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@
2525
final class SplitAndMergeImportUseStatementTest extends UtilityMethodTestCase
2626
{
2727

28+
/**
29+
* Test passing a non-integer token pointer.
30+
*
31+
* @return void
32+
*/
33+
public function testNonIntegerToken()
34+
{
35+
$this->expectException('PHPCSUtils\Exceptions\TypeError');
36+
$this->expectExceptionMessage('Argument #2 ($stackPtr) must be of type integer, NULL given');
37+
38+
UseStatements::splitAndMergeImportUseStatement(self::$phpcsFile, null, []);
39+
}
40+
2841
/**
2942
* Test passing a non-existent token pointer.
3043
*

0 commit comments

Comments
 (0)