Skip to content

Commit b1effa3

Browse files
committed
Tests: use assertIs[Type] assertions
These assertions were introduced in PHPUnit 7.5.0 to replace the `assertInternalType()` assertion method. To not have PHPUnit version toggles everywhere, the assertions used native PHP in combination with `assertTrue()` for now. As support for PHPUnit < 8 has been dropped though, we can now use the PHPUnit native `assertIs[Type]()` assertions.
1 parent 1b50b47 commit b1effa3

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

tests/Core/Config/ReportWidthTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testReportWidthDefault()
3434
$config = new Config(['--standard=PSR1']);
3535

3636
// Can't test the exact value as "auto" will resolve differently depending on the machine running the tests.
37-
$this->assertTrue(is_int($config->reportWidth), 'Report width is not an integer');
37+
$this->assertIsInt($config->reportWidth, 'Report width is not an integer');
3838
$this->assertGreaterThan(0, $config->reportWidth, 'Report width is not greater than 0');
3939

4040
}//end testReportWidthDefault()
@@ -60,7 +60,7 @@ public function testReportWidthWillBeSetFromAutoWhenNotFoundInConfFile()
6060
$config = new Config(['--standard=PSR1']);
6161

6262
// Can't test the exact value as "auto" will resolve differently depending on the machine running the tests.
63-
$this->assertTrue(is_int($config->reportWidth), 'Report width is not an integer');
63+
$this->assertIsInt($config->reportWidth, 'Report width is not an integer');
6464
$this->assertGreaterThan(0, $config->reportWidth, 'Report width is not greater than 0');
6565

6666
}//end testReportWidthWillBeSetFromAutoWhenNotFoundInConfFile()
@@ -181,7 +181,7 @@ public function testReportWidthInputHandlingForAuto()
181181
$config->reportWidth = 'auto';
182182

183183
// Can't test the exact value as "auto" will resolve differently depending on the machine running the tests.
184-
$this->assertTrue(is_int($config->reportWidth), 'Report width is not an integer');
184+
$this->assertIsInt($config->reportWidth, 'Report width is not an integer');
185185
$this->assertGreaterThan(0, $config->reportWidth, 'Report width is not greater than 0');
186186

187187
}//end testReportWidthInputHandlingForAuto()

tests/Core/Ruleset/PopulateTokenListenersTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testSniffWithRegisterMethodReturningEmptyArrayIsSilentlyIgnored(
8383
$target = 'Fixtures\\TestStandard\\Sniffs\\ValidSniffs\\RegisterEmptyArraySniff';
8484

8585
foreach (self::$ruleset->tokenListeners as $token => $listeners) {
86-
$this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token));
86+
$this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token));
8787
$this->assertArrayNotHasKey(
8888
$target,
8989
$listeners,
@@ -172,7 +172,7 @@ public function testRegistersWhenADeprecatedSniffIsLoaded()
172172

173173
// Only verify there is one deprecated sniff registered.
174174
// There are other tests which test the deprecated sniff handling in more detail.
175-
$this->assertTrue(is_array($actualValue));
175+
$this->assertIsArray($actualValue);
176176
$this->assertCount(1, $actualValue);
177177

178178
}//end testRegistersWhenADeprecatedSniffIsLoaded()
@@ -261,7 +261,7 @@ public static function dataTriggersPropertySettingWhenPropertiesProvided()
261261
public function testSetsClassAndSourceIndexes()
262262
{
263263
foreach (self::$ruleset->tokenListeners as $token => $listeners) {
264-
$this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token));
264+
$this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token));
265265

266266
foreach ($listeners as $className => $details) {
267267
$this->assertArrayHasKey(
@@ -282,8 +282,8 @@ public function testSetsClassAndSourceIndexes()
282282
sprintf('"source" key missing for sniff class %s for token %s', $className, Tokens::tokenName($token))
283283
);
284284

285-
$this->assertTrue(
286-
is_string($details['source']),
285+
$this->assertIsString(
286+
$details['source'],
287287
sprintf('Value for "source" key is not a string for token %s', Tokens::tokenName($token))
288288
);
289289

@@ -310,7 +310,7 @@ public function testSetsIncludePatternsToEmptyArrayByDefault()
310310
$exclude = 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\NamingConventions\\UpperCaseConstantNameSniff';
311311

312312
foreach (self::$ruleset->tokenListeners as $token => $listeners) {
313-
$this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token));
313+
$this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token));
314314

315315
foreach ($listeners as $className => $details) {
316316
if ($className === $exclude) {
@@ -345,7 +345,7 @@ public function testSetsIgnorePatternsToEmptyArrayByDefault()
345345
$exclude = 'PHP_CodeSniffer\\Standards\\PSR1\\Sniffs\\Files\\SideEffectsSniff';
346346

347347
foreach (self::$ruleset->tokenListeners as $token => $listeners) {
348-
$this->assertTrue(is_array($listeners), 'No listeners registered for token'.Tokens::tokenName($token));
348+
$this->assertIsArray($listeners, 'No listeners registered for token'.Tokens::tokenName($token));
349349

350350
foreach ($listeners as $className => $details) {
351351
if ($className === $exclude) {

tests/Core/Ruleset/ProcessRuleShouldProcessElementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ private function verifyShouldProcessElement($expected)
616616
private function assertHasRulesetDirective($sniffCode, $key)
617617
{
618618
$this->assertArrayHasKey($sniffCode, self::$ruleset->ruleset, "Sniff $sniffCode not registered");
619-
$this->assertTrue(is_array(self::$ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array");
619+
$this->assertIsArray(self::$ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array");
620620
$this->assertArrayHasKey($key, self::$ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode");
621621

622622
}//end assertHasRulesetDirective()

tests/Core/Ruleset/ProcessRulesetTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ public function testIncludeSingleErrorCode()
159159

160160
$sniffCode = 'Generic.PHP.RequireStrictTypes';
161161
$this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered");
162-
$this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array");
162+
$this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array");
163163
$this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode");
164164
$this->assertSame(0, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode");
165165

166166
$sniffCode = 'Generic.PHP.RequireStrictTypes.MissingDeclaration';
167167
$this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered");
168-
$this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array");
168+
$this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array");
169169
$this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode");
170170
$this->assertSame(5, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode");
171171

@@ -187,19 +187,19 @@ public function testErrorCodeIncludeAfterExclude()
187187

188188
$sniffCode = 'PEAR.Files.IncludingFile';
189189
$this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered");
190-
$this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array");
190+
$this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array");
191191
$this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode");
192192
$this->assertSame(0, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode");
193193

194194
$sniffCode = 'PEAR.Files.IncludingFile.BracketsNotRequired';
195195
$this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered");
196-
$this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array");
196+
$this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array");
197197
$this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode");
198198
$this->assertSame(5, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode");
199199

200200
$sniffCode = 'PEAR.Files.IncludingFile.UseRequire';
201201
$this->assertArrayHasKey($sniffCode, $ruleset->ruleset, "Sniff $sniffCode not registered");
202-
$this->assertTrue(is_array($ruleset->ruleset[$sniffCode]), "Sniff $sniffCode is not an array");
202+
$this->assertIsArray($ruleset->ruleset[$sniffCode], "Sniff $sniffCode is not an array");
203203
$this->assertArrayHasKey($key, $ruleset->ruleset[$sniffCode], "Directive $key not registered for sniff $sniffCode");
204204
$this->assertSame(5, $ruleset->ruleset[$sniffCode][$key], "$key has unexpected value for sniff $sniffCode");
205205

tests/Core/Tokenizers/PHP/GotoLabelTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testGotoStatement($testMarker, $testContent)
3636

3737
$label = $this->getTargetToken($testMarker, T_STRING);
3838

39-
$this->assertTrue(is_int($label));
39+
$this->assertIsInt($label);
4040
$this->assertSame($testContent, $tokens[$label]['content']);
4141

4242
}//end testGotoStatement()
@@ -89,7 +89,7 @@ public function testGotoDeclaration($testMarker, $testContent)
8989

9090
$label = $this->getTargetToken($testMarker, T_GOTO_LABEL);
9191

92-
$this->assertTrue(is_int($label));
92+
$this->assertIsInt($label);
9393
$this->assertSame($testContent, $tokens[$label]['content']);
9494

9595
}//end testGotoDeclaration()

tests/Core/Tokenizers/Tokenizer/ReplaceTabsInTokenMiscTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testTabWidthNotSet()
4444
$target = $phpcsFile->findNext(T_WHITESPACE, 0);
4545

4646
// Verify initial state.
47-
$this->assertTrue(is_int($target), 'Target token was not found');
47+
$this->assertIsInt($target, 'Target token was not found');
4848
$this->assertSame(' ', $tokens[$target]['content'], 'Content after initial parsing does not contain tabs');
4949
$this->assertSame(2, $tokens[$target]['length'], 'Length after initial parsing is not as expected');
5050
$this->assertArrayNotHasKey('orig_content', $tokens[$target], "Key 'orig_content' found in the initial token array.");
@@ -82,7 +82,7 @@ public function testLengthSettingRespectsEncoding()
8282
$tokens = $phpcsFile->getTokens();
8383
$target = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, 0);
8484

85-
$this->assertTrue(is_int($target), 'Target token was not found');
85+
$this->assertIsInt($target, 'Target token was not found');
8686
$this->assertSame("'пасха пасха'", $tokens[$target]['content'], 'Content is not as expected');
8787
$this->assertSame(17, $tokens[$target]['length'], 'Length is not as expected');
8888
$this->assertArrayHasKey('orig_content', $tokens[$target], "Key 'orig_content' not found in the token array.");
@@ -114,7 +114,7 @@ public function testLengthSettingFallsBackToBytesWhenTextContainsIllegalChars()
114114
$tokens = $phpcsFile->getTokens();
115115
$target = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, 0);
116116

117-
$this->assertTrue(is_int($target), 'Target token was not found');
117+
$this->assertIsInt($target, 'Target token was not found');
118118
$this->assertSame(11, $tokens[$target]['length'], 'Length is not as expected');
119119
$this->assertArrayHasKey('orig_content', $tokens[$target], "Key 'orig_content' not found in the token array.");
120120

tests/Core/Util/Timing/TimingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testGetDurationWithStartReturnsMilliseconds()
5151
usleep(1500);
5252
$duration = Timing::getDuration();
5353

54-
$this->assertTrue(is_float($duration));
54+
$this->assertIsFloat($duration);
5555
$this->assertGreaterThan(1, $duration);
5656
$this->assertLessThan(15, $duration);
5757

0 commit comments

Comments
 (0)