Skip to content

Commit 4b77eb3

Browse files
committed
Tests/Tokenizer: make failure messages more descriptive
Most Tokenizer tests first assert that the token `'code'` is correct and after that, that the token `'type'` is correct. When the first assertion fails, an error message like this will be displayed: `Failed asserting that 357 is identical to 313.` That's because the PHP native token constants are integers. And even if someone would memorize all token constant integers, the integer values are different depending on the PHP version being used. All in all, that makes error messages like the above hard to decipher. To mitigate this, a number of the Tokenizer tests already used the `$msg` parameter for the `assertSame()` call. This commit adds this `$msg` parameter to more assertions to make the failure messages actually useful. Includes introducing an interim `$tokenArray` variable in a lot of these tests to keep the line length in check.
1 parent 529cd87 commit 4b77eb3

13 files changed

+162
-107
lines changed

tests/Core/Tokenizer/BackfillEnumTest.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ final class BackfillEnumTest extends AbstractMethodUnitTest
3030
*/
3131
public function testEnums($testMarker, $testContent, $openerOffset, $closerOffset)
3232
{
33-
$tokens = self::$phpcsFile->getTokens();
33+
$tokens = self::$phpcsFile->getTokens();
34+
$enum = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent);
35+
$tokenArray = $tokens[$enum];
3436

35-
$enum = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent);
37+
$this->assertSame(T_ENUM, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_ENUM (code)');
38+
$this->assertSame('T_ENUM', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_ENUM (type)');
3639

37-
$this->assertSame(T_ENUM, $tokens[$enum]['code']);
38-
$this->assertSame('T_ENUM', $tokens[$enum]['type']);
40+
$this->assertArrayHasKey('scope_condition', $tokenArray);
41+
$this->assertArrayHasKey('scope_opener', $tokenArray);
42+
$this->assertArrayHasKey('scope_closer', $tokenArray);
3943

40-
$this->assertArrayHasKey('scope_condition', $tokens[$enum]);
41-
$this->assertArrayHasKey('scope_opener', $tokens[$enum]);
42-
$this->assertArrayHasKey('scope_closer', $tokens[$enum]);
44+
$this->assertSame($enum, $tokenArray['scope_condition']);
4345

44-
$this->assertSame($enum, $tokens[$enum]['scope_condition']);
45-
46-
$scopeOpener = $tokens[$enum]['scope_opener'];
47-
$scopeCloser = $tokens[$enum]['scope_closer'];
46+
$scopeOpener = $tokenArray['scope_opener'];
47+
$scopeCloser = $tokenArray['scope_closer'];
4848

4949
$expectedScopeOpener = ($enum + $openerOffset);
5050
$expectedScopeCloser = ($enum + $closerOffset);
@@ -138,11 +138,12 @@ public static function dataEnums()
138138
*/
139139
public function testNotEnums($testMarker, $testContent)
140140
{
141-
$tokens = self::$phpcsFile->getTokens();
141+
$tokens = self::$phpcsFile->getTokens();
142+
$target = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent);
143+
$tokenArray = $tokens[$target];
142144

143-
$target = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent);
144-
$this->assertSame(T_STRING, $tokens[$target]['code']);
145-
$this->assertSame('T_STRING', $tokens[$target]['type']);
145+
$this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)');
146+
$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)');
146147

147148
}//end testNotEnums()
148149

tests/Core/Tokenizer/BackfillNumericSeparatorTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

1212
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13+
use PHP_CodeSniffer\Util\Tokens;
1314

1415
final class BackfillNumericSeparatorTest extends AbstractMethodUnitTest
1516
{
@@ -29,12 +30,13 @@ final class BackfillNumericSeparatorTest extends AbstractMethodUnitTest
2930
*/
3031
public function testBackfill($marker, $type, $value)
3132
{
32-
$tokens = self::$phpcsFile->getTokens();
33-
$number = $this->getTargetToken($marker, [T_LNUMBER, T_DNUMBER]);
33+
$tokens = self::$phpcsFile->getTokens();
34+
$number = $this->getTargetToken($marker, [T_LNUMBER, T_DNUMBER]);
35+
$tokenArray = $tokens[$number];
3436

35-
$this->assertSame(constant($type), $tokens[$number]['code']);
36-
$this->assertSame($type, $tokens[$number]['type']);
37-
$this->assertSame($value, $tokens[$number]['content']);
37+
$this->assertSame(constant($type), $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not '.$type.' (code)');
38+
$this->assertSame($type, $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not '.$type.' (type)');
39+
$this->assertSame($value, $tokenArray['content']);
3840

3941
}//end testBackfill()
4042

@@ -153,7 +155,11 @@ public function testNoBackfill($testMarker, $expectedTokens)
153155

154156
foreach ($expectedTokens as $key => $expectedToken) {
155157
$i = ($number + $key);
156-
$this->assertSame($expectedToken['code'], $tokens[$i]['code']);
158+
$this->assertSame(
159+
$expectedToken['code'],
160+
$tokens[$i]['code'],
161+
'Token tokenized as '.Tokens::tokenName($tokens[$i]['code']).', not '.Tokens::tokenName($expectedToken['code'])
162+
);
157163
$this->assertSame($expectedToken['content'], $tokens[$i]['content']);
158164
}
159165

tests/Core/Tokenizer/BackfillReadonlyTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ final class BackfillReadonlyTest extends AbstractMethodUnitTest
2929
*/
3030
public function testReadonly($testMarker, $testContent='readonly')
3131
{
32-
$tokens = self::$phpcsFile->getTokens();
32+
$tokens = self::$phpcsFile->getTokens();
33+
$target = $this->getTargetToken($testMarker, [T_READONLY, T_STRING], $testContent);
34+
$tokenArray = $tokens[$target];
3335

34-
$target = $this->getTargetToken($testMarker, [T_READONLY, T_STRING], $testContent);
35-
$this->assertSame(T_READONLY, $tokens[$target]['code']);
36-
$this->assertSame('T_READONLY', $tokens[$target]['type']);
36+
$this->assertSame(T_READONLY, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_READONLY (code)');
37+
$this->assertSame('T_READONLY', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_READONLY (type)');
3738

3839
}//end testReadonly()
3940

@@ -174,11 +175,12 @@ public static function dataReadonly()
174175
*/
175176
public function testNotReadonly($testMarker, $testContent='readonly')
176177
{
177-
$tokens = self::$phpcsFile->getTokens();
178+
$tokens = self::$phpcsFile->getTokens();
179+
$target = $this->getTargetToken($testMarker, [T_READONLY, T_STRING], $testContent);
180+
$tokenArray = $tokens[$target];
178181

179-
$target = $this->getTargetToken($testMarker, [T_READONLY, T_STRING], $testContent);
180-
$this->assertSame(T_STRING, $tokens[$target]['code']);
181-
$this->assertSame('T_STRING', $tokens[$target]['type']);
182+
$this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)');
183+
$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)');
182184

183185
}//end testNotReadonly()
184186

tests/Core/Tokenizer/BitwiseOrTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ final class BitwiseOrTest extends AbstractMethodUnitTest
2727
*/
2828
public function testBitwiseOr($testMarker)
2929
{
30-
$tokens = self::$phpcsFile->getTokens();
30+
$tokens = self::$phpcsFile->getTokens();
31+
$target = $this->getTargetToken($testMarker, [T_BITWISE_OR, T_TYPE_UNION]);
32+
$tokenArray = $tokens[$target];
3133

32-
$opener = $this->getTargetToken($testMarker, [T_BITWISE_OR, T_TYPE_UNION]);
33-
$this->assertSame(T_BITWISE_OR, $tokens[$opener]['code']);
34-
$this->assertSame('T_BITWISE_OR', $tokens[$opener]['type']);
34+
$this->assertSame(T_BITWISE_OR, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_BITWISE_OR (code)');
35+
$this->assertSame('T_BITWISE_OR', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_BITWISE_OR (type)');
3536

3637
}//end testBitwiseOr()
3738

@@ -78,11 +79,12 @@ public static function dataBitwiseOr()
7879
*/
7980
public function testTypeUnion($testMarker)
8081
{
81-
$tokens = self::$phpcsFile->getTokens();
82+
$tokens = self::$phpcsFile->getTokens();
83+
$target = $this->getTargetToken($testMarker, [T_BITWISE_OR, T_TYPE_UNION]);
84+
$tokenArray = $tokens[$target];
8285

83-
$opener = $this->getTargetToken($testMarker, [T_BITWISE_OR, T_TYPE_UNION]);
84-
$this->assertSame(T_TYPE_UNION, $tokens[$opener]['code']);
85-
$this->assertSame('T_TYPE_UNION', $tokens[$opener]['type']);
86+
$this->assertSame(T_TYPE_UNION, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_TYPE_UNION (code)');
87+
$this->assertSame('T_TYPE_UNION', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_TYPE_UNION (type)');
8688

8789
}//end testTypeUnion()
8890

tests/Core/Tokenizer/ContextSensitiveKeywordsTest.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ final class ContextSensitiveKeywordsTest extends AbstractMethodUnitTest
2828
*/
2929
public function testStrings($testMarker)
3030
{
31-
$tokens = self::$phpcsFile->getTokens();
31+
$tokens = self::$phpcsFile->getTokens();
32+
$target = $this->getTargetToken($testMarker, (Tokens::$contextSensitiveKeywords + [T_STRING, T_NULL, T_FALSE, T_TRUE, T_PARENT, T_SELF]));
33+
$tokenArray = $tokens[$target];
3234

33-
$token = $this->getTargetToken($testMarker, (Tokens::$contextSensitiveKeywords + [T_STRING, T_NULL, T_FALSE, T_TRUE, T_PARENT, T_SELF]));
34-
35-
$this->assertSame(T_STRING, $tokens[$token]['code']);
36-
$this->assertSame('T_STRING', $tokens[$token]['type']);
35+
$this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)');
36+
$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)');
3737

3838
}//end testStrings()
3939

@@ -167,15 +167,23 @@ public static function dataStrings()
167167
*/
168168
public function testKeywords($testMarker, $expectedTokenType)
169169
{
170-
$tokens = self::$phpcsFile->getTokens();
171-
172-
$token = $this->getTargetToken(
170+
$tokens = self::$phpcsFile->getTokens();
171+
$target = $this->getTargetToken(
173172
$testMarker,
174173
(Tokens::$contextSensitiveKeywords + [T_ANON_CLASS, T_MATCH_DEFAULT, T_PARENT, T_SELF, T_STRING, T_NULL, T_FALSE, T_TRUE])
175174
);
175+
$tokenArray = $tokens[$target];
176176

177-
$this->assertSame(constant($expectedTokenType), $tokens[$token]['code']);
178-
$this->assertSame($expectedTokenType, $tokens[$token]['type']);
177+
$this->assertSame(
178+
constant($expectedTokenType),
179+
$tokenArray['code'],
180+
'Token tokenized as '.$tokenArray['type'].', not '.$expectedTokenType.' (code)'
181+
);
182+
$this->assertSame(
183+
$expectedTokenType,
184+
$tokenArray['type'],
185+
'Token tokenized as '.$tokenArray['type'].', not '.$expectedTokenType.' (type)'
186+
);
179187

180188
}//end testKeywords()
181189

tests/Core/Tokenizer/EnumCaseTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ final class EnumCaseTest extends AbstractMethodUnitTest
2828
*/
2929
public function testEnumCases($testMarker)
3030
{
31-
$tokens = self::$phpcsFile->getTokens();
31+
$tokens = self::$phpcsFile->getTokens();
32+
$enumCase = $this->getTargetToken($testMarker, [T_ENUM_CASE, T_CASE]);
33+
$tokenArray = $tokens[$enumCase];
3234

33-
$enumCase = $this->getTargetToken($testMarker, [T_ENUM_CASE, T_CASE]);
35+
$this->assertSame(T_ENUM_CASE, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_ENUM_CASE (code)');
36+
$this->assertSame('T_ENUM_CASE', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_ENUM_CASE (type)');
3437

35-
$this->assertSame(T_ENUM_CASE, $tokens[$enumCase]['code']);
36-
$this->assertSame('T_ENUM_CASE', $tokens[$enumCase]['type']);
37-
38-
$this->assertArrayNotHasKey('scope_condition', $tokens[$enumCase], 'Scope condition is set');
39-
$this->assertArrayNotHasKey('scope_opener', $tokens[$enumCase], 'Scope opener is set');
40-
$this->assertArrayNotHasKey('scope_closer', $tokens[$enumCase], 'Scope closer is set');
38+
$this->assertArrayNotHasKey('scope_condition', $tokenArray, 'Scope condition is set');
39+
$this->assertArrayNotHasKey('scope_opener', $tokenArray, 'Scope opener is set');
40+
$this->assertArrayNotHasKey('scope_closer', $tokenArray, 'Scope closer is set');
4141

4242
}//end testEnumCases()
4343

@@ -77,16 +77,16 @@ public static function dataEnumCases()
7777
*/
7878
public function testNotEnumCases($testMarker)
7979
{
80-
$tokens = self::$phpcsFile->getTokens();
81-
82-
$case = $this->getTargetToken($testMarker, [T_ENUM_CASE, T_CASE]);
80+
$tokens = self::$phpcsFile->getTokens();
81+
$case = $this->getTargetToken($testMarker, [T_ENUM_CASE, T_CASE]);
82+
$tokenArray = $tokens[$case];
8383

84-
$this->assertSame(T_CASE, $tokens[$case]['code']);
85-
$this->assertSame('T_CASE', $tokens[$case]['type']);
84+
$this->assertSame(T_CASE, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_CASE (code)');
85+
$this->assertSame('T_CASE', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_CASE (type)');
8686

87-
$this->assertArrayHasKey('scope_condition', $tokens[$case], 'Scope condition is not set');
88-
$this->assertArrayHasKey('scope_opener', $tokens[$case], 'Scope opener is not set');
89-
$this->assertArrayHasKey('scope_closer', $tokens[$case], 'Scope closer is not set');
87+
$this->assertArrayHasKey('scope_condition', $tokenArray, 'Scope condition is not set');
88+
$this->assertArrayHasKey('scope_opener', $tokenArray, 'Scope opener is not set');
89+
$this->assertArrayHasKey('scope_closer', $tokenArray, 'Scope closer is not set');
9090

9191
}//end testNotEnumCases()
9292

@@ -125,12 +125,12 @@ public static function dataNotEnumCases()
125125
*/
126126
public function testKeywordAsEnumCaseNameShouldBeString($testMarker)
127127
{
128-
$tokens = self::$phpcsFile->getTokens();
129-
128+
$tokens = self::$phpcsFile->getTokens();
130129
$enumCaseName = $this->getTargetToken($testMarker, [T_STRING, T_INTERFACE, T_TRAIT, T_ENUM, T_FUNCTION, T_FALSE, T_DEFAULT, T_ARRAY]);
130+
$tokenArray = $tokens[$enumCaseName];
131131

132-
$this->assertSame(T_STRING, $tokens[$enumCaseName]['code']);
133-
$this->assertSame('T_STRING', $tokens[$enumCaseName]['type']);
132+
$this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)');
133+
$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)');
134134

135135
}//end testKeywordAsEnumCaseNameShouldBeString()
136136

tests/Core/Tokenizer/FinallyTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ final class FinallyTest extends AbstractMethodUnitTest
2727
*/
2828
public function testFinallyKeyword($testMarker)
2929
{
30-
$tokens = self::$phpcsFile->getTokens();
30+
$tokens = self::$phpcsFile->getTokens();
31+
$target = $this->getTargetToken($testMarker, [T_FINALLY, T_STRING]);
32+
$tokenArray = $tokens[$target];
3133

32-
$target = $this->getTargetToken($testMarker, [T_FINALLY, T_STRING]);
33-
$this->assertSame(T_FINALLY, $tokens[$target]['code']);
34-
$this->assertSame('T_FINALLY', $tokens[$target]['type']);
34+
$this->assertSame(T_FINALLY, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_FINALLY (code)');
35+
$this->assertSame('T_FINALLY', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_FINALLY (type)');
3536

3637
}//end testFinallyKeyword()
3738

@@ -66,11 +67,12 @@ public static function dataFinallyKeyword()
6667
*/
6768
public function testFinallyNonKeyword($testMarker)
6869
{
69-
$tokens = self::$phpcsFile->getTokens();
70+
$tokens = self::$phpcsFile->getTokens();
71+
$target = $this->getTargetToken($testMarker, [T_FINALLY, T_STRING]);
72+
$tokenArray = $tokens[$target];
7073

71-
$target = $this->getTargetToken($testMarker, [T_FINALLY, T_STRING]);
72-
$this->assertSame(T_STRING, $tokens[$target]['code']);
73-
$this->assertSame('T_STRING', $tokens[$target]['type']);
74+
$this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)');
75+
$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)');
7476

7577
}//end testFinallyNonKeyword()
7678

tests/Core/Tokenizer/GotoLabelTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ public static function dataGotoDeclaration()
120120
*/
121121
public function testNotAGotoDeclaration($testMarker, $testContent)
122122
{
123-
$tokens = self::$phpcsFile->getTokens();
124-
$target = $this->getTargetToken($testMarker, [T_GOTO_LABEL, T_STRING], $testContent);
123+
$tokens = self::$phpcsFile->getTokens();
124+
$target = $this->getTargetToken($testMarker, [T_GOTO_LABEL, T_STRING], $testContent);
125+
$tokenArray = $tokens[$target];
125126

126-
$this->assertSame(T_STRING, $tokens[$target]['code']);
127-
$this->assertSame('T_STRING', $tokens[$target]['type']);
127+
$this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)');
128+
$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)');
128129

129130
}//end testNotAGotoDeclaration()
130131

tests/Core/Tokenizer/ShortArrayTest.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ final class ShortArrayTest extends AbstractMethodUnitTest
2727
*/
2828
public function testSquareBrackets($testMarker)
2929
{
30-
$tokens = self::$phpcsFile->getTokens();
30+
$tokens = self::$phpcsFile->getTokens();
31+
$opener = $this->getTargetToken($testMarker, [T_OPEN_SQUARE_BRACKET, T_OPEN_SHORT_ARRAY]);
32+
$tokenArray = $tokens[$opener];
3133

32-
$opener = $this->getTargetToken($testMarker, [T_OPEN_SQUARE_BRACKET, T_OPEN_SHORT_ARRAY]);
33-
$this->assertSame(T_OPEN_SQUARE_BRACKET, $tokens[$opener]['code']);
34-
$this->assertSame('T_OPEN_SQUARE_BRACKET', $tokens[$opener]['type']);
34+
$this->assertSame(T_OPEN_SQUARE_BRACKET, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_OPEN_SQUARE_BRACKET (code)');
35+
$this->assertSame('T_OPEN_SQUARE_BRACKET', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_OPEN_SQUARE_BRACKET (type)');
3536

3637
if (isset($tokens[$opener]['bracket_closer']) === true) {
37-
$closer = $tokens[$opener]['bracket_closer'];
38-
$this->assertSame(T_CLOSE_SQUARE_BRACKET, $tokens[$closer]['code']);
39-
$this->assertSame('T_CLOSE_SQUARE_BRACKET', $tokens[$closer]['type']);
38+
$closer = $tokens[$opener]['bracket_closer'];
39+
$tokenArray = $tokens[$closer];
40+
41+
$this->assertSame(T_CLOSE_SQUARE_BRACKET, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_CLOSE_SQUARE_BRACKET (code)');
42+
$this->assertSame('T_CLOSE_SQUARE_BRACKET', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_CLOSE_SQUARE_BRACKET (type)');
4043
}
4144

4245
}//end testSquareBrackets()
@@ -92,16 +95,19 @@ public static function dataSquareBrackets()
9295
*/
9396
public function testShortArrays($testMarker)
9497
{
95-
$tokens = self::$phpcsFile->getTokens();
98+
$tokens = self::$phpcsFile->getTokens();
99+
$opener = $this->getTargetToken($testMarker, [T_OPEN_SQUARE_BRACKET, T_OPEN_SHORT_ARRAY]);
100+
$tokenArray = $tokens[$opener];
96101

97-
$opener = $this->getTargetToken($testMarker, [T_OPEN_SQUARE_BRACKET, T_OPEN_SHORT_ARRAY]);
98-
$this->assertSame(T_OPEN_SHORT_ARRAY, $tokens[$opener]['code']);
99-
$this->assertSame('T_OPEN_SHORT_ARRAY', $tokens[$opener]['type']);
102+
$this->assertSame(T_OPEN_SHORT_ARRAY, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_OPEN_SHORT_ARRAY (code)');
103+
$this->assertSame('T_OPEN_SHORT_ARRAY', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_OPEN_SHORT_ARRAY (type)');
100104

101105
if (isset($tokens[$opener]['bracket_closer']) === true) {
102-
$closer = $tokens[$opener]['bracket_closer'];
103-
$this->assertSame(T_CLOSE_SHORT_ARRAY, $tokens[$closer]['code']);
104-
$this->assertSame('T_CLOSE_SHORT_ARRAY', $tokens[$closer]['type']);
106+
$closer = $tokens[$opener]['bracket_closer'];
107+
$tokenArray = $tokens[$closer];
108+
109+
$this->assertSame(T_CLOSE_SHORT_ARRAY, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_CLOSE_SHORT_ARRAY (code)');
110+
$this->assertSame('T_CLOSE_SHORT_ARRAY', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_CLOSE_SHORT_ARRAY (type)');
105111
}
106112

107113
}//end testShortArrays()

0 commit comments

Comments
 (0)