Skip to content

Commit 68c060e

Browse files
committed
Tests/RuleInclusionTest: use named data within data sets
This commit adds the parameter name for each item in the data set 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 type in the docblock more specific.
1 parent 90e70f4 commit 68c060e

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

tests/Core/Ruleset/RuleInclusionTest.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function testRegisteredSniffCodes($key, $value)
129129
*
130130
* @see self::testRegisteredSniffCodes()
131131
*
132-
* @return array
132+
* @return array<array<string>>
133133
*/
134134
public static function dataRegisteredSniffCodes()
135135
{
@@ -335,9 +335,9 @@ public static function dataRegisteredSniffCodes()
335335
* Test that setting properties for standards, categories, sniffs works for all supported rule
336336
* inclusion methods.
337337
*
338-
* @param string $sniffClass The name of the sniff class.
339-
* @param string $propertyName The name of the changed property.
340-
* @param mixed $expectedValue The value expected for the property.
338+
* @param string $sniffClass The name of the sniff class.
339+
* @param string $propertyName The name of the changed property.
340+
* @param string|int|bool $expectedValue The value expected for the property.
341341
*
342342
* @dataProvider dataSettingProperties
343343
*
@@ -362,62 +362,62 @@ public function testSettingProperties($sniffClass, $propertyName, $expectedValue
362362
*
363363
* @see self::testSettingProperties()
364364
*
365-
* @return array
365+
* @return array<string, array<string, string|int|bool>>
366366
*/
367367
public static function dataSettingProperties()
368368
{
369369
return [
370370
'Set property for complete standard: PSR2 ClassDeclaration' => [
371-
'PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff',
372-
'indent',
373-
'20',
371+
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff',
372+
'propertyName' => 'indent',
373+
'expectedValue' => '20',
374374
],
375375
'Set property for complete standard: PSR2 SwitchDeclaration' => [
376-
'PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\SwitchDeclarationSniff',
377-
'indent',
378-
'20',
376+
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\SwitchDeclarationSniff',
377+
'propertyName' => 'indent',
378+
'expectedValue' => '20',
379379
],
380380
'Set property for complete standard: PSR2 FunctionCallSignature' => [
381-
'PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff',
382-
'indent',
383-
'20',
381+
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff',
382+
'propertyName' => 'indent',
383+
'expectedValue' => '20',
384384
],
385385
'Set property for complete category: PSR12 OperatorSpacing' => [
386-
'PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff',
387-
'ignoreSpacingBeforeAssignments',
388-
false,
386+
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff',
387+
'propertyName' => 'ignoreSpacingBeforeAssignments',
388+
'expectedValue' => false,
389389
],
390390
'Set property for individual sniff: Generic ArrayIndent' => [
391-
'PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\ArrayIndentSniff',
392-
'indent',
393-
'2',
391+
'sniffClass' => 'PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\ArrayIndentSniff',
392+
'propertyName' => 'indent',
393+
'expectedValue' => '2',
394394
],
395395
'Set property for individual sniff using sniff file inclusion: Generic LineLength' => [
396-
'PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff',
397-
'lineLimit',
398-
'10',
396+
'sniffClass' => 'PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff',
397+
'propertyName' => 'lineLimit',
398+
'expectedValue' => '10',
399399
],
400400
'Set property for individual sniff using sniff file inclusion: CamelCapsFunctionName' => [
401-
'PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff',
402-
'strict',
403-
false,
401+
'sniffClass' => 'PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff',
402+
'propertyName' => 'strict',
403+
'expectedValue' => false,
404404
],
405405
'Set property for individual sniff via included ruleset: NestingLevel - nestingLevel' => [
406-
'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff',
407-
'nestingLevel',
408-
'2',
406+
'sniffClass' => 'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff',
407+
'propertyName' => 'nestingLevel',
408+
'expectedValue' => '2',
409409
],
410410
'Set property for all sniffs in an included ruleset: NestingLevel - absoluteNestingLevel' => [
411-
'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff',
412-
'absoluteNestingLevel',
413-
true,
411+
'sniffClass' => 'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff',
412+
'propertyName' => 'absoluteNestingLevel',
413+
'expectedValue' => true,
414414
],
415415

416416
// Testing that setting a property at error code level does *not* work.
417417
'Set property for error code will not change the sniff property value: CyclomaticComplexity' => [
418-
'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff',
419-
'complexity',
420-
10,
418+
'sniffClass' => 'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff',
419+
'propertyName' => 'complexity',
420+
'expectedValue' => 10,
421421
],
422422
];
423423

@@ -453,22 +453,22 @@ public function testSettingInvalidPropertiesOnStandardsAndCategoriesSilentlyFail
453453
*
454454
* @see self::testSettingInvalidPropertiesOnStandardsAndCategoriesSilentlyFails()
455455
*
456-
* @return array
456+
* @return array<string, array>string, string>>
457457
*/
458458
public static function dataSettingInvalidPropertiesOnStandardsAndCategoriesSilentlyFails()
459459
{
460460
return [
461461
'Set property for complete standard: PSR2 ClassDeclaration' => [
462-
'PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff',
463-
'setforallsniffs',
462+
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff',
463+
'propertyName' => 'setforallsniffs',
464464
],
465465
'Set property for complete standard: PSR2 FunctionCallSignature' => [
466-
'PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff',
467-
'setforallsniffs',
466+
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff',
467+
'propertyName' => 'setforallsniffs',
468468
],
469469
'Set property for complete category: PSR12 OperatorSpacing' => [
470-
'PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff',
471-
'setforallincategory',
470+
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff',
471+
'propertyName' => 'setforallincategory',
472472
],
473473
];
474474

0 commit comments

Comments
 (0)