Skip to content

Commit 6b8e591

Browse files
committed
Tests/ScopeSettingWithNamespaceOperatorTest: use named data sets
With non-named data sets, when a test fails, PHPUnit will display the number of the test which failed. With tests which have a _lot_ of data sets, this makes it _interesting_ (and time-consuming) to debug those, as one now has to figure out which of the data sets in the data provider corresponds to that number. Using named data sets makes debugging failing tests more straight forward as PHPUnit will display the data set name instead of the number. Using named data sets also documents what exactly each data set is testing. Aside from adding the data set name, this commit also adds the parameter name for each item in the data set, this time in an effort to make it more straight forward to update and add tests as it will be more obvious what each key in the data set signifies. Include making the data type in the docblock more specific. Includes fixing the test description in the file docblock.
1 parent b223027 commit 6b8e591

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

tests/Core/Tokenizer/ScopeSettingWithNamespaceOperatorTest.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Tests the adding of the "bracket_opener/closer" keys to use group tokens.
3+
* Tests the scope opener/closers are set correctly when the namespace keyword is used as an operator.
44
*
55
* @author Juliette Reinders Folmer <[email protected]>
66
* @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600)
@@ -18,10 +18,10 @@ final class ScopeSettingWithNamespaceOperatorTest extends AbstractMethodUnitTest
1818
/**
1919
* Test that the scope opener/closers are set correctly when the namespace keyword is encountered as an operator.
2020
*
21-
* @param string $testMarker The comment which prefaces the target tokens in the test file.
22-
* @param int|string[] $tokenTypes The token type to search for.
23-
* @param int|string[] $open Optional. The token type for the scope opener.
24-
* @param int|string[] $close Optional. The token type for the scope closer.
21+
* @param string $testMarker The comment which prefaces the target tokens in the test file.
22+
* @param array<int|string> $tokenTypes The token type to search for.
23+
* @param array<int|string> $open Optional. The token type for the scope opener.
24+
* @param array<int|string> $close Optional. The token type for the scope closer.
2525
*
2626
* @dataProvider dataScopeSetting
2727
* @covers PHP_CodeSniffer\Tokenizers\Tokenizer::recurseScopeMap
@@ -59,36 +59,36 @@ public function testScopeSetting($testMarker, $tokenTypes, $open=T_OPEN_CURLY_BR
5959
*
6060
* @see testScopeSetting()
6161
*
62-
* @return array
62+
* @return array<string, array<string, string|array<int|string>>>
6363
*/
6464
public static function dataScopeSetting()
6565
{
6666
return [
67-
[
68-
'/* testClassExtends */',
69-
[T_CLASS],
67+
'class which extends namespace relative name' => [
68+
'testMarker' => '/* testClassExtends */',
69+
'tokenTypes' => [T_CLASS],
7070
],
71-
[
72-
'/* testClassImplements */',
73-
[T_ANON_CLASS],
71+
'class which implements namespace relative name' => [
72+
'testMarker' => '/* testClassImplements */',
73+
'tokenTypes' => [T_ANON_CLASS],
7474
],
75-
[
76-
'/* testInterfaceExtends */',
77-
[T_INTERFACE],
75+
'interface which extend namespace relative name' => [
76+
'testMarker' => '/* testInterfaceExtends */',
77+
'tokenTypes' => [T_INTERFACE],
7878
],
79-
[
80-
'/* testFunctionReturnType */',
81-
[T_FUNCTION],
79+
'namespace relative name in function return type' => [
80+
'testMarker' => '/* testFunctionReturnType */',
81+
'tokenTypes' => [T_FUNCTION],
8282
],
83-
[
84-
'/* testClosureReturnType */',
85-
[T_CLOSURE],
83+
'namespace relative name in closure return type' => [
84+
'testMarker' => '/* testClosureReturnType */',
85+
'tokenTypes' => [T_CLOSURE],
8686
],
87-
[
88-
'/* testArrowFunctionReturnType */',
89-
[T_FN],
90-
[T_FN_ARROW],
91-
[T_SEMICOLON],
87+
'namespace relative name in arrow function return type' => [
88+
'testMarker' => '/* testArrowFunctionReturnType */',
89+
'tokenTypes' => [T_FN],
90+
'open' => [T_FN_ARROW],
91+
'close' => [T_SEMICOLON],
9292
],
9393
];
9494

0 commit comments

Comments
 (0)