Skip to content

Commit b03bf36

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

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
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: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace PHPCSUtils\Tests\Utils\UseStatements;
1212

13-
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
13+
use PHPCSUtils\Tests\PolyfilledTestCase;
1414
use PHPCSUtils\Utils\UseStatements;
1515

1616
/**
@@ -22,9 +22,22 @@
2222
*
2323
* @since 1.0.0
2424
*/
25-
final class SplitAndMergeImportUseStatementTest extends UtilityMethodTestCase
25+
final class SplitAndMergeImportUseStatementTest extends PolyfilledTestCase
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)