Skip to content

Commit

Permalink
Tests/BackfillReadonlyTest: use named data sets
Browse files Browse the repository at this point in the history
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 making the data types in the docblocks more specific.
  • Loading branch information
jrfnl committed Jan 14, 2024
1 parent a08b80d commit 7a017f3
Showing 1 changed file with 114 additions and 114 deletions.
228 changes: 114 additions & 114 deletions tests/Core/Tokenizer/BackfillReadonlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,117 +43,117 @@ public function testReadonly($testMarker, $testContent='readonly')
*
* @see testReadonly()
*
* @return array
* @return array<string, array<string, string>>
*/
public static function dataReadonly()
{
return [
[
'/* testReadonlyProperty */',
'property declaration, no visibility' => [
'testMarker' => '/* testReadonlyProperty */',
],
[
'/* testVarReadonlyProperty */',
'property declaration, var keyword before' => [
'testMarker' => '/* testVarReadonlyProperty */',
],
[
'/* testReadonlyVarProperty */',
'property declaration, var keyword after' => [
'testMarker' => '/* testReadonlyVarProperty */',
],
[
'/* testStaticReadonlyProperty */',
'property declaration, static before' => [
'testMarker' => '/* testStaticReadonlyProperty */',
],
[
'/* testReadonlyStaticProperty */',
'property declaration, static after' => [
'testMarker' => '/* testReadonlyStaticProperty */',
],
[
'/* testConstReadonlyProperty */',
'constant declaration, with visibility' => [
'testMarker' => '/* testConstReadonlyProperty */',
],
[
'/* testReadonlyPropertyWithoutType */',
'property declaration, missing type' => [
'testMarker' => '/* testReadonlyPropertyWithoutType */',
],
[
'/* testPublicReadonlyProperty */',
'property declaration, public before' => [
'testMarker' => '/* testPublicReadonlyProperty */',
],
[
'/* testProtectedReadonlyProperty */',
'property declaration, protected before' => [
'testMarker' => '/* testProtectedReadonlyProperty */',
],
[
'/* testPrivateReadonlyProperty */',
'property declaration, private before' => [
'testMarker' => '/* testPrivateReadonlyProperty */',
],
[
'/* testPublicReadonlyPropertyWithReadonlyFirst */',
'property declaration, public after' => [
'testMarker' => '/* testPublicReadonlyPropertyWithReadonlyFirst */',
],
[
'/* testProtectedReadonlyPropertyWithReadonlyFirst */',
'property declaration, protected after' => [
'testMarker' => '/* testProtectedReadonlyPropertyWithReadonlyFirst */',
],
[
'/* testPrivateReadonlyPropertyWithReadonlyFirst */',
'property declaration, private after' => [
'testMarker' => '/* testPrivateReadonlyPropertyWithReadonlyFirst */',
],
[
'/* testReadonlyWithCommentsInDeclaration */',
'property declaration, private before, comments in declaration' => [
'testMarker' => '/* testReadonlyWithCommentsInDeclaration */',
],
[
'/* testReadonlyWithNullableProperty */',
'property declaration, private before, nullable type' => [
'testMarker' => '/* testReadonlyWithNullableProperty */',
],
[
'/* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */',
'property declaration, private before, union type, null first' => [
'testMarker' => '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */',
],
[
'/* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */',
'property declaration, private before, union type, null last' => [
'testMarker' => '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */',
],
[
'/* testReadonlyPropertyWithArrayTypeHint */',
'property declaration, private before, array type' => [
'testMarker' => '/* testReadonlyPropertyWithArrayTypeHint */',
],
[
'/* testReadonlyPropertyWithSelfTypeHint */',
'property declaration, private before, self type' => [
'testMarker' => '/* testReadonlyPropertyWithSelfTypeHint */',
],
[
'/* testReadonlyPropertyWithParentTypeHint */',
'property declaration, private before, parent type' => [
'testMarker' => '/* testReadonlyPropertyWithParentTypeHint */',
],
[
'/* testReadonlyPropertyWithFullyQualifiedTypeHint */',
'property declaration, private before, FQN type' => [
'testMarker' => '/* testReadonlyPropertyWithFullyQualifiedTypeHint */',
],
[
'/* testReadonlyIsCaseInsensitive */',
'ReAdOnLy',
'property declaration, public before, mixed case' => [
'testMarker' => '/* testReadonlyIsCaseInsensitive */',
'testContent' => 'ReAdOnLy',
],
[
'/* testReadonlyConstructorPropertyPromotion */',
'property declaration, constructor property promotion' => [
'testMarker' => '/* testReadonlyConstructorPropertyPromotion */',
],
[
'/* testReadonlyConstructorPropertyPromotionWithReference */',
'ReadOnly',
'property declaration, constructor property promotion with reference, mixed case' => [
'testMarker' => '/* testReadonlyConstructorPropertyPromotionWithReference */',
'testContent' => 'ReadOnly',
],
[
'/* testReadonlyPropertyInAnonymousClass */',
'property declaration, in anonymous class' => [
'testMarker' => '/* testReadonlyPropertyInAnonymousClass */',
],
[
'/* testReadonlyPropertyDNFTypeUnqualified */',
'property declaration, no visibility, DNF type, unqualified' => [
'testMarker' => '/* testReadonlyPropertyDNFTypeUnqualified */',
],
[
'/* testReadonlyPropertyDNFTypeFullyQualified */',
'property declaration, public before, DNF type, fully qualified' => [
'testMarker' => '/* testReadonlyPropertyDNFTypeFullyQualified */',
],
[
'/* testReadonlyPropertyDNFTypePartiallyQualified */',
'property declaration, protected before, DNF type, partially qualified' => [
'testMarker' => '/* testReadonlyPropertyDNFTypePartiallyQualified */',
],
[
'/* testReadonlyPropertyDNFTypeRelativeName */',
'property declaration, private before, DNF type, namespace relative name' => [
'testMarker' => '/* testReadonlyPropertyDNFTypeRelativeName */',
],
[
'/* testReadonlyPropertyDNFTypeMultipleSets */',
'property declaration, private before, DNF type, multiple sets' => [
'testMarker' => '/* testReadonlyPropertyDNFTypeMultipleSets */',
],
[
'/* testReadonlyPropertyDNFTypeWithArray */',
'property declaration, private before, DNF type, union with array' => [
'testMarker' => '/* testReadonlyPropertyDNFTypeWithArray */',
],
[
'/* testReadonlyPropertyDNFTypeWithSpacesAndComments */',
'property declaration, private before, DNF type, with spaces and comment' => [
'testMarker' => '/* testReadonlyPropertyDNFTypeWithSpacesAndComments */',
],
[
'/* testReadonlyConstructorPropertyPromotionWithDNF */',
'property declaration, constructor property promotion, DNF type' => [
'testMarker' => '/* testReadonlyConstructorPropertyPromotionWithDNF */',
],
[
'/* testReadonlyConstructorPropertyPromotionWithDNFAndReference */',
'property declaration, constructor property promotion, DNF type and reference' => [
'testMarker' => '/* testReadonlyConstructorPropertyPromotionWithDNFAndReference */',
],
[
'/* testParseErrorLiveCoding */',
'live coding / parse error' => [
'testMarker' => '/* testParseErrorLiveCoding */',
],
];

Expand Down Expand Up @@ -188,67 +188,67 @@ public function testNotReadonly($testMarker, $testContent='readonly')
*
* @see testNotReadonly()
*
* @return array
* @return array<string, array<string, string>>
*/
public static function dataNotReadonly()
{
return [
[
'/* testReadonlyUsedAsClassConstantName */',
'READONLY',
'name of a constant, context: declaration using "const" keyword, uppercase' => [
'testMarker' => '/* testReadonlyUsedAsClassConstantName */',
'testContent' => 'READONLY',
],
[
'/* testReadonlyUsedAsMethodName */',
'name of a method, context: declaration' => [
'testMarker' => '/* testReadonlyUsedAsMethodName */',
],
[
'/* testReadonlyUsedAsPropertyName */',
'name of a property, context: property access' => [
'testMarker' => '/* testReadonlyUsedAsPropertyName */',
],
[
'/* testReadonlyPropertyInTernaryOperator */',
'name of a property, context: property access in ternary' => [
'testMarker' => '/* testReadonlyPropertyInTernaryOperator */',
],
[
'/* testReadonlyUsedAsFunctionName */',
'name of a function, context: declaration' => [
'testMarker' => '/* testReadonlyUsedAsFunctionName */',
],
[
'/* testReadonlyUsedAsFunctionNameWithReturnByRef */',
'name of a function, context: declaration with return by ref' => [
'testMarker' => '/* testReadonlyUsedAsFunctionNameWithReturnByRef */',
],
[
'/* testReadonlyUsedAsNamespaceName */',
'Readonly',
'name of namespace, context: declaration, mixed case' => [
'testMarker' => '/* testReadonlyUsedAsNamespaceName */',
'testContent' => 'Readonly',
],
[
'/* testReadonlyUsedAsPartOfNamespaceName */',
'Readonly',
'partial name of namespace, context: declaration, mixed case' => [
'testMarker' => '/* testReadonlyUsedAsPartOfNamespaceName */',
'testContent' => 'Readonly',
],
[
'/* testReadonlyAsFunctionCall */',
'name of a function, context: call' => [
'testMarker' => '/* testReadonlyAsFunctionCall */',
],
[
'/* testReadonlyAsNamespacedFunctionCall */',
'name of a namespaced function, context: partially qualified call' => [
'testMarker' => '/* testReadonlyAsNamespacedFunctionCall */',
],
[
'/* testReadonlyAsNamespaceRelativeFunctionCall */',
'ReadOnly',
'name of a function, context: namespace relative call, mixed case' => [
'testMarker' => '/* testReadonlyAsNamespaceRelativeFunctionCall */',
'testContent' => 'ReadOnly',
],
[
'/* testReadonlyAsMethodCall */',
'name of a method, context: method call on object' => [
'testMarker' => '/* testReadonlyAsMethodCall */',
],
[
'/* testReadonlyAsNullsafeMethodCall */',
'readOnly',
'name of a method, context: nullsafe method call on object' => [
'testMarker' => '/* testReadonlyAsNullsafeMethodCall */',
'testContent' => 'readOnly',
],
[
'/* testReadonlyAsStaticMethodCallWithSpace */',
'name of a method, context: static method call with space after' => [
'testMarker' => '/* testReadonlyAsStaticMethodCallWithSpace */',
],
[
'/* testClassConstantFetchWithReadonlyAsConstantName */',
'READONLY',
'name of a constant, context: constant access - uppercase' => [
'testMarker' => '/* testClassConstantFetchWithReadonlyAsConstantName */',
'testContent' => 'READONLY',
],
[
'/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */',
'name of a function, context: call with space and comment between keyword and parens' => [
'testMarker' => '/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */',
],
[
'/* testReadonlyUsedAsMethodNameWithDNFParam */',
'name of a method, context: declaration with DNF parameter' => [
'testMarker' => '/* testReadonlyUsedAsMethodNameWithDNFParam */',
],
];

Expand Down

0 comments on commit 7a017f3

Please sign in to comment.