Skip to content

Commit 7bab9bb

Browse files
committed
PropertyTypeHandlingTest: split data provider
The `PropertyTypeHandlingTest` class tests the setting of property values from the ruleset as well as via inline `// phpcs:set ...` annotations. As both ways of setting the property value should be supported in the same manner, the tests used one data provider for both tests and the fixtures (`PropertyTypeHandlingTest.xml` ruleset and the `Fixtures/PropertyTypeHandlingInline.inc` file containing the inline annotations) mirrored the exact same test cases. There is one feature, however, which is only supported when setting properties via the ruleset, not when setting them via inline annotations: array property extending. Until now, the tests for that were also mirrored in the inline annotation tests, even though the feature isn't supported for inline annotations. This commit now splits the data provider in two: * One data provider for the tests which apply for both (= most tests). * One specifically for extending array properties. That second data provider will now only be used by the `testTypeHandlingWhenSetViaRuleset()` test method. This should make it more straight-forward to add additional tests for property extending in the future. --- In case anyone is wondering: As `phpcs:set` is only supposed to be used in tests, I don't think adding support for the `extend` option to inline properties is necessary.
1 parent 0ee3759 commit 7bab9bb

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,10 @@
2222

2323
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithOnlyValues[] string, 10, 1.5, null, true, false
2424
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false
25-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithExtendedValues[] string, 15, another string
26-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithExtendedKeysAndValues[] 10=>10,string=>string,15=>15,another string=>another string
2725
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsEmptyArray[]
2826

2927
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithOnlyValues[] string, 10, 1.5, null, true, false
3028
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false
31-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithExtendedValues[] string, 15, another string
32-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithExtendedKeysAndValues[] 10=>10,string=>string,15=>15,another string=>another string
3329
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolEmptyArray[]
3430

3531
echo 'hello!';

tests/Core/Ruleset/PropertyTypeHandlingTest.php

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class PropertyTypeHandlingTest extends TestCase
4545
* @param mixed $expected Expected property value.
4646
*
4747
* @dataProvider dataTypeHandling
48+
* @dataProvider dataArrayPropertyExtending
4849
*
4950
* @return void
5051
*/
@@ -80,6 +81,7 @@ public function testTypeHandlingWhenSetInline($propertyName, $expected)
8081
* Data provider.
8182
*
8283
* @see self::testTypeHandlingWhenSetViaRuleset()
84+
* @see self::testTypeHandlingWhenSetInline()
8385
*
8486
* @return array<string, array<string, mixed>>
8587
*/
@@ -102,18 +104,6 @@ public static function dataTypeHandling()
102104
'false' => 'false',
103105
];
104106

105-
$expectedArrayOnlyValuesExtended = [
106-
'string',
107-
'15',
108-
'another string',
109-
];
110-
$expectedArrayKeysAndValuesExtended = [
111-
10 => '10',
112-
'string' => 'string',
113-
15 => '15',
114-
'another string' => 'another string',
115-
];
116-
117107
return [
118108
'String value (default)' => [
119109
'propertyName' => 'expectsString',
@@ -175,21 +165,50 @@ public static function dataTypeHandling()
175165
'propertyName' => 'expectsArrayWithKeysAndValues',
176166
'expected' => $expectedArrayKeysAndValues,
177167
],
178-
'Array with only values extended' => [
168+
'Empty array' => [
169+
'propertyName' => 'expectsEmptyArray',
170+
'expected' => [],
171+
],
172+
];
173+
174+
}//end dataTypeHandling()
175+
176+
177+
/**
178+
* Data provider.
179+
*
180+
* Array property extending is a feature which is only supported from a ruleset, not for inline property setting.
181+
*
182+
* @see self::testTypeHandlingWhenSetViaRuleset()
183+
*
184+
* @return array<string, array<string, mixed>>
185+
*/
186+
public static function dataArrayPropertyExtending()
187+
{
188+
$expectedArrayOnlyValuesExtended = [
189+
'string',
190+
'15',
191+
'another string',
192+
];
193+
$expectedArrayKeysAndValuesExtended = [
194+
10 => '10',
195+
'string' => 'string',
196+
15 => '15',
197+
'another string' => 'another string',
198+
];
199+
200+
return [
201+
'Array with only values extended' => [
179202
'propertyName' => 'expectsArrayWithExtendedValues',
180203
'expected' => $expectedArrayOnlyValuesExtended,
181204
],
182-
'Array with keys and values extended' => [
205+
'Array with keys and values extended' => [
183206
'propertyName' => 'expectsArrayWithExtendedKeysAndValues',
184207
'expected' => $expectedArrayKeysAndValuesExtended,
185208
],
186-
'Empty array' => [
187-
'propertyName' => 'expectsEmptyArray',
188-
'expected' => [],
189-
],
190209
];
191210

192-
}//end dataTypeHandling()
211+
}//end dataArrayPropertyExtending()
193212

194213

195214
/**

0 commit comments

Comments
 (0)