|
13 | 13 | class InvalidKeyInArrayDimFetchRuleTest extends RuleTestCase
|
14 | 14 | {
|
15 | 15 |
|
| 16 | + private bool $reportCastedArrayKey = false; |
| 17 | + |
16 | 18 | protected function getRule(): Rule
|
17 | 19 | {
|
18 | 20 | $ruleLevelHelper = new RuleLevelHelper($this->createReflectionProvider(), true, false, true, false, false, false, true);
|
19 |
| - return new InvalidKeyInArrayDimFetchRule($ruleLevelHelper, true); |
| 21 | + return new InvalidKeyInArrayDimFetchRule($ruleLevelHelper, true, $this->reportCastedArrayKey); |
20 | 22 | }
|
21 | 23 |
|
22 | 24 | public function testInvalidKey(): void
|
@@ -61,6 +63,69 @@ public function testInvalidKey(): void
|
61 | 63 | ]);
|
62 | 64 | }
|
63 | 65 |
|
| 66 | + public function testInvalidKeyReportingCastedArrayKey(): void |
| 67 | + { |
| 68 | + $this->reportCastedArrayKey = true; |
| 69 | + $this->analyse([__DIR__ . '/data/invalid-key-array-dim-fetch.php'], [ |
| 70 | + [ |
| 71 | + 'Invalid array key type null.', |
| 72 | + 6, |
| 73 | + ], |
| 74 | + [ |
| 75 | + 'Invalid array key type DateTimeImmutable.', |
| 76 | + 7, |
| 77 | + ], |
| 78 | + [ |
| 79 | + 'Invalid array key type array.', |
| 80 | + 8, |
| 81 | + ], |
| 82 | + [ |
| 83 | + 'Invalid array key type float.', |
| 84 | + 10, |
| 85 | + ], |
| 86 | + [ |
| 87 | + 'Invalid array key type true.', |
| 88 | + 12, |
| 89 | + ], |
| 90 | + [ |
| 91 | + 'Invalid array key type false.', |
| 92 | + 13, |
| 93 | + ], |
| 94 | + [ |
| 95 | + 'Possibly invalid array key type string|null.', |
| 96 | + 17, |
| 97 | + ], |
| 98 | + [ |
| 99 | + 'Possibly invalid array key type stdClass|string.', |
| 100 | + 24, |
| 101 | + ], |
| 102 | + [ |
| 103 | + 'Invalid array key type DateTimeImmutable.', |
| 104 | + 31, |
| 105 | + ], |
| 106 | + [ |
| 107 | + 'Invalid array key type DateTimeImmutable.', |
| 108 | + 45, |
| 109 | + ], |
| 110 | + [ |
| 111 | + 'Invalid array key type DateTimeImmutable.', |
| 112 | + 46, |
| 113 | + ], |
| 114 | + [ |
| 115 | + 'Invalid array key type DateTimeImmutable.', |
| 116 | + 47, |
| 117 | + ], |
| 118 | + [ |
| 119 | + 'Invalid array key type stdClass.', |
| 120 | + 47, |
| 121 | + ], |
| 122 | + [ |
| 123 | + 'Invalid array key type DateTimeImmutable.', |
| 124 | + 48, |
| 125 | + ], |
| 126 | + ]); |
| 127 | + } |
| 128 | + |
64 | 129 | public function testBug6315(): void
|
65 | 130 | {
|
66 | 131 | if (PHP_VERSION_ID < 80100) {
|
@@ -95,4 +160,20 @@ public function testBug6315(): void
|
95 | 160 | ]);
|
96 | 161 | }
|
97 | 162 |
|
| 163 | + public function testUnsetFalseKey(): void |
| 164 | + { |
| 165 | + $this->reportCastedArrayKey = true; |
| 166 | + |
| 167 | + $this->analyse([__DIR__ . '/data/unset-false-key.php'], [ |
| 168 | + [ |
| 169 | + 'Invalid array key type false.', |
| 170 | + 6, |
| 171 | + ], |
| 172 | + [ |
| 173 | + 'Invalid array key type false.', |
| 174 | + 13, |
| 175 | + ], |
| 176 | + ]); |
| 177 | + } |
| 178 | + |
98 | 179 | }
|
0 commit comments