Skip to content

Commit 2bdb734

Browse files
committed
File/Get*Tests: work round removal of assertArraySubset()
The `assertArraySubset()` method was deprecated in PHPUnit 8.x and removed in PHPUnit 9.0.0 without replacement. The `assertArraySubset()` assertion was being used as not all token array indexes are being tested - to be specific: any index which is a token offset is not tested -. As the `assertArraySubset()` has been removed, I'm electing to unset the token offset array indexes and replacing the assertion with a strict type `assertSame()` comparison.
1 parent 69f66cc commit 2bdb734

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

tests/Core/File/GetMemberPropertiesTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public function testGetMemberProperties($identifier, $expected)
3030
$variable = $this->getTargetToken($identifier, T_VARIABLE);
3131
$result = self::$phpcsFile->getMemberProperties($variable);
3232

33-
$this->assertArraySubset($expected, $result, true);
33+
// Unset those indexes which are not being tested.
34+
unset($result['type_token'], $result['type_end_token']);
35+
36+
$this->assertSame($expected, $result);
3437

3538
}//end testGetMemberProperties()
3639

tests/Core/File/GetMethodParametersTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,23 @@ private function getMethodParametersTestHelper($commentString, $expected)
11791179
$function = $this->getTargetToken($commentString, [T_FUNCTION, T_CLOSURE, T_FN]);
11801180
$found = self::$phpcsFile->getMethodParameters($function);
11811181

1182-
$this->assertArraySubset($expected, $found, true);
1182+
// Unset those indexes which are not being tested.
1183+
foreach ($found as $i => $param) {
1184+
unset(
1185+
$found[$i]['token'],
1186+
$found[$i]['reference_token'],
1187+
$found[$i]['variadic_token'],
1188+
$found[$i]['type_hint_token'],
1189+
$found[$i]['type_hint_end_token'],
1190+
$found[$i]['comma_token'],
1191+
$found[$i]['default_token'],
1192+
$found[$i]['default_equal_token'],
1193+
$found[$i]['visibility_token'],
1194+
$found[$i]['readonly_token']
1195+
);
1196+
}
1197+
1198+
$this->assertSame($expected, $found);
11831199

11841200
}//end getMethodParametersTestHelper()
11851201

tests/Core/File/GetMethodPropertiesTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,10 @@ private function getMethodPropertiesTestHelper($commentString, $expected)
902902
$function = $this->getTargetToken($commentString, [T_FUNCTION, T_CLOSURE, T_FN]);
903903
$found = self::$phpcsFile->getMethodProperties($function);
904904

905-
$this->assertArraySubset($expected, $found, true);
905+
// Unset those indexes which are not being tested.
906+
unset($found['return_type_token'], $found['return_type_end_token']);
907+
908+
$this->assertSame($expected, $found);
906909

907910
}//end getMethodPropertiesTestHelper()
908911

0 commit comments

Comments
 (0)