Skip to content

Commit 66e178b

Browse files
committed
Ruleset/PropertyTypeHandlingTest: add tests with extended arrays
Add some extra tests to verify that extending a (new style) array property declaration works as expected. While this is also tested via the `ProcessRuleShouldProcessElementTest`, some extra tests seemed warranted.
1 parent 1bb5741 commit 66e178b

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919

2020
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithOnlyValues[] string, 10, 1.5, null, true, false
2121
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false
22+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithExtendedValues[] string, 15, another string
23+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithExtendedKeysAndValues[] 10=>10,string=>string,15=>15,another string=>another string
2224

2325
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithOnlyValues[] string, 10, 1.5, null, true, false
2426
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false
27+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithExtendedValues[] string, 15, another string
28+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithExtendedKeysAndValues[] 10=>10,string=>string,15=>15,another string=>another string
2529

2630
echo 'hello!';

tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/SetProperty/PropertyTypeHandlingSniff.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ final class PropertyTypeHandlingSniff implements Sniff
9999
*/
100100
public $expectsArrayWithKeysAndValues;
101101

102+
/**
103+
* Used to verify that array properties can get extended.
104+
*
105+
* @var array<mixed>
106+
*/
107+
public $expectsArrayWithExtendedValues;
108+
109+
/**
110+
* Used to verify that array properties can get extended.
111+
*
112+
* @var array<mixed>
113+
*/
114+
public $expectsArrayWithExtendedKeysAndValues;
115+
102116
/**
103117
* Used to verify that array properties passed as a string get parsed to a proper array.
104118
*
@@ -113,6 +127,20 @@ final class PropertyTypeHandlingSniff implements Sniff
113127
*/
114128
public $expectsOldSchoolArrayWithKeysAndValues;
115129

130+
/**
131+
* Used to verify that array properties passed as a string can get extended.
132+
*
133+
* @var array<string, mixed>
134+
*/
135+
public $expectsOldSchoolArrayWithExtendedValues;
136+
137+
/**
138+
* Used to verify that array properties passed as a string can get extended.
139+
*
140+
* @var array<string, mixed>
141+
*/
142+
public $expectsOldSchoolArrayWithExtendedKeysAndValues;
143+
116144
public function register()
117145
{
118146
return [T_ECHO];

tests/Core/Ruleset/PropertyTypeHandlingTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ public static function dataTypeHandling()
102102
'false' => 'false',
103103
];
104104

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+
105117
return [
106118
'String value (default)' => [
107119
'propertyName' => 'expectsString',
@@ -151,6 +163,15 @@ public static function dataTypeHandling()
151163
'propertyName' => 'expectsArrayWithKeysAndValues',
152164
'expected' => $expectedArrayKeysAndValues,
153165
],
166+
'Array with only values extended' => [
167+
'propertyName' => 'expectsArrayWithExtendedValues',
168+
'expected' => $expectedArrayOnlyValuesExtended,
169+
],
170+
'Array with keys and values extended' => [
171+
'propertyName' => 'expectsArrayWithExtendedKeysAndValues',
172+
'expected' => $expectedArrayKeysAndValuesExtended,
173+
],
174+
154175
];
155176

156177
}//end dataTypeHandling()

tests/Core/Ruleset/PropertyTypeHandlingTest.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@
3434
<element key="true" value="true"/>
3535
<element key="false" value="false"/>
3636
</property>
37+
38+
<property name="expectsArrayWithExtendedValues" type="array">
39+
<element value="string"/>
40+
</property>
41+
42+
<property name="expectsArrayWithExtendedValues" type="array" extend="true">
43+
<element value="15"/>
44+
<element value="another string"/>
45+
</property>
46+
47+
<property name="expectsArrayWithExtendedKeysAndValues" type="array">
48+
<element key="10" value="10"/>
49+
<element key="string" value="string"/>
50+
</property>
51+
52+
<property name="expectsArrayWithExtendedKeysAndValues" type="array" extend="true">
53+
<element key="15" value="15"/>
54+
<element key="another string" value="another string"/>
55+
</property>
3756
</properties>
3857
</rule>
3958

0 commit comments

Comments
 (0)