Skip to content

Commit dec8b03

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 fa32635 commit dec8b03

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
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: 44 additions & 25 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,14 +165,6 @@ public static function dataTypeHandling()
175165
'propertyName' => 'expectsArrayWithKeysAndValues',
176166
'expected' => $expectedArrayKeysAndValues,
177167
],
178-
'Array with only values extended (new style)' => [
179-
'propertyName' => 'expectsArrayWithExtendedValues',
180-
'expected' => $expectedArrayOnlyValuesExtended,
181-
],
182-
'Array with keys and values extended (new style)' => [
183-
'propertyName' => 'expectsArrayWithExtendedKeysAndValues',
184-
'expected' => $expectedArrayKeysAndValuesExtended,
185-
],
186168
'Empty array (new style)' => [
187169
'propertyName' => 'expectsEmptyArray',
188170
'expected' => [],
@@ -195,6 +177,47 @@ public static function dataTypeHandling()
195177
'propertyName' => 'expectsOldSchoolArrayWithKeysAndValues',
196178
'expected' => $expectedArrayKeysAndValues,
197179
],
180+
'Empty array (old style)' => [
181+
'propertyName' => 'expectsOldSchoolEmptyArray',
182+
'expected' => [],
183+
],
184+
];
185+
186+
}//end dataTypeHandling()
187+
188+
189+
/**
190+
* Data provider.
191+
*
192+
* Array property extending is a feature which is only supported from a ruleset, not for inline property setting.
193+
*
194+
* @see self::testTypeHandlingWhenSetViaRuleset()
195+
*
196+
* @return array<string, array<string, mixed>>
197+
*/
198+
public static function dataArrayPropertyExtending()
199+
{
200+
$expectedArrayOnlyValuesExtended = [
201+
'string',
202+
'15',
203+
'another string',
204+
];
205+
$expectedArrayKeysAndValuesExtended = [
206+
10 => '10',
207+
'string' => 'string',
208+
15 => '15',
209+
'another string' => 'another string',
210+
];
211+
212+
return [
213+
'Array with only values extended (new style)' => [
214+
'propertyName' => 'expectsArrayWithExtendedValues',
215+
'expected' => $expectedArrayOnlyValuesExtended,
216+
],
217+
'Array with keys and values extended (new style)' => [
218+
'propertyName' => 'expectsArrayWithExtendedKeysAndValues',
219+
'expected' => $expectedArrayKeysAndValuesExtended,
220+
],
198221
'Array with only values extended (old style)' => [
199222
'propertyName' => 'expectsOldSchoolArrayWithExtendedValues',
200223
'expected' => $expectedArrayOnlyValuesExtended,
@@ -203,13 +226,9 @@ public static function dataTypeHandling()
203226
'propertyName' => 'expectsOldSchoolArrayWithExtendedKeysAndValues',
204227
'expected' => $expectedArrayKeysAndValuesExtended,
205228
],
206-
'Empty array (old style)' => [
207-
'propertyName' => 'expectsOldSchoolEmptyArray',
208-
'expected' => [],
209-
],
210229
];
211230

212-
}//end dataTypeHandling()
231+
}//end dataArrayPropertyExtending()
213232

214233

215234
/**

0 commit comments

Comments
 (0)