Skip to content

Commit c5f32cd

Browse files
committed
Tests/BackfillFnTokenTest: 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. Includes minor data set array normalization. Includes making the data types in the docblocks more specific.
1 parent 29290f9 commit c5f32cd

File tree

1 file changed

+67
-51
lines changed

1 file changed

+67
-51
lines changed

tests/Core/Tokenizer/BackfillFnTokenTest.php

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -579,38 +579,38 @@ public function testInMatchValue($testMarker, $openerOffset, $closerOffset, $exp
579579
*
580580
* @see testInMatchValue()
581581
*
582-
* @return array
582+
* @return array<string, array<string, string|int>>
583583
*/
584584
public static function dataInMatchValue()
585585
{
586586
return [
587587
'not_last_value' => [
588-
'/* testInMatchNotLastValue */',
589-
5,
590-
11,
591-
'T_COMMA',
592-
'comma',
588+
'testMarker' => '/* testInMatchNotLastValue */',
589+
'openerOffset' => 5,
590+
'closerOffset' => 11,
591+
'expectedCloserType' => 'T_COMMA',
592+
'expectedCloserFriendlyName' => 'comma',
593593
],
594594
'last_value_with_trailing_comma' => [
595-
'/* testInMatchLastValueWithTrailingComma */',
596-
5,
597-
11,
598-
'T_COMMA',
599-
'comma',
595+
'testMarker' => '/* testInMatchLastValueWithTrailingComma */',
596+
'openerOffset' => 5,
597+
'closerOffset' => 11,
598+
'expectedCloserType' => 'T_COMMA',
599+
'expectedCloserFriendlyName' => 'comma',
600600
],
601601
'last_value_without_trailing_comma_1' => [
602-
'/* testInMatchLastValueNoTrailingComma1 */',
603-
5,
604-
10,
605-
'T_CLOSE_PARENTHESIS',
606-
'close parenthesis',
602+
'testMarker' => '/* testInMatchLastValueNoTrailingComma1 */',
603+
'openerOffset' => 5,
604+
'closerOffset' => 10,
605+
'expectedCloserType' => 'T_CLOSE_PARENTHESIS',
606+
'expectedCloserFriendlyName' => 'close parenthesis',
607607
],
608608
'last_value_without_trailing_comma_2' => [
609-
'/* testInMatchLastValueNoTrailingComma2 */',
610-
5,
611-
11,
612-
'T_VARIABLE',
613-
'$y variable',
609+
'testMarker' => '/* testInMatchLastValueNoTrailingComma2 */',
610+
'openerOffset' => 5,
611+
'closerOffset' => 11,
612+
'expectedCloserType' => 'T_VARIABLE',
613+
'expectedCloserFriendlyName' => '$y variable',
614614
],
615615
];
616616

@@ -669,47 +669,63 @@ public function testNotAnArrowFunction($testMarker, $testContent='fn')
669669
*
670670
* @see testNotAnArrowFunction()
671671
*
672-
* @return array
672+
* @return array<string, array<string, string>>
673673
*/
674674
public static function dataNotAnArrowFunction()
675675
{
676676
return [
677-
['/* testFunctionName */'],
678-
[
679-
'/* testConstantDeclaration */',
680-
'FN',
677+
'name of a function, context: declaration' => [
678+
'testMarker' => '/* testFunctionName */',
681679
],
682-
[
683-
'/* testConstantDeclarationLower */',
684-
'fn',
680+
'name of a constant, context: declaration using "const" keyword - uppercase' => [
681+
'testMarker' => '/* testConstantDeclaration */',
682+
'testContent' => 'FN',
685683
],
686-
['/* testStaticMethodName */'],
687-
['/* testPropertyAssignment */'],
688-
[
689-
'/* testAnonClassMethodName */',
690-
'fN',
684+
'name of a constant, context: declaration using "const" keyword - lowercase' => [
685+
'testMarker' => '/* testConstantDeclarationLower */',
686+
'testContent' => 'fn',
691687
],
692-
['/* testNonArrowStaticMethodCall */'],
693-
[
694-
'/* testNonArrowConstantAccess */',
695-
'FN',
688+
'name of a (static) method, context: declaration' => [
689+
'testMarker' => '/* testStaticMethodName */',
696690
],
697-
[
698-
'/* testNonArrowConstantAccessMixed */',
699-
'Fn',
691+
'name of a property, context: property access' => [
692+
'testMarker' => '/* testPropertyAssignment */',
700693
],
701-
['/* testNonArrowObjectMethodCall */'],
702-
[
703-
'/* testNonArrowObjectMethodCallUpper */',
704-
'FN',
694+
'name of a method, context: declaration in an anon class - mixed case' => [
695+
'testMarker' => '/* testAnonClassMethodName */',
696+
'testContent' => 'fN',
705697
],
706-
[
707-
'/* testNonArrowNamespacedFunctionCall */',
708-
'Fn',
698+
'name of a method, context: static method call' => [
699+
'testMarker' => '/* testNonArrowStaticMethodCall */',
700+
],
701+
'name of a constant, context: constant access - uppercase' => [
702+
'testMarker' => '/* testNonArrowConstantAccess */',
703+
'testContent' => 'FN',
704+
],
705+
'name of a constant, context: constant access - mixed case' => [
706+
'testMarker' => '/* testNonArrowConstantAccessMixed */',
707+
'testContent' => 'Fn',
708+
],
709+
'name of a method, context: method call on object - lowercase' => [
710+
'testMarker' => '/* testNonArrowObjectMethodCall */',
711+
],
712+
'name of a method, context: method call on object - uppercase' => [
713+
'testMarker' => '/* testNonArrowObjectMethodCallUpper */',
714+
'testContent' => 'FN',
715+
],
716+
'name of a (namespaced) function, context: partially qualified function call' => [
717+
'testMarker' => '/* testNonArrowNamespacedFunctionCall */',
718+
'testContent' => 'Fn',
719+
],
720+
'name of a (namespaced) function, context: namespace relative function call' => [
721+
'testMarker' => '/* testNonArrowNamespaceOperatorFunctionCall */',
722+
],
723+
'name of a function, context: declaration with union types for param and return' => [
724+
'testMarker' => '/* testNonArrowFunctionNameWithUnionTypes */',
725+
],
726+
'unknown - live coding/parse error' => [
727+
'testMarker' => '/* testLiveCoding */',
709728
],
710-
['/* testNonArrowNamespaceOperatorFunctionCall */'],
711-
['/* testNonArrowFunctionNameWithUnionTypes */'],
712-
['/* testLiveCoding */'],
713729
];
714730

715731
}//end dataNotAnArrowFunction()

0 commit comments

Comments
 (0)