Skip to content

Commit 9fa10d3

Browse files
Add tests
1 parent c86721e commit 9fa10d3

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,16 @@ public function testBug13799(): void
12021202
public function testBug13023(): void
12031203
{
12041204
$this->treatPhpDocTypesAsCertain = true;
1205-
$this->analyse([__DIR__ . '/data/bug-13023.php'], []);
1205+
$this->analyse([__DIR__ . '/data/bug-13023.php'], [
1206+
[
1207+
'Call to function is_int() with 0 will always evaluate to true.',
1208+
198,
1209+
],
1210+
[
1211+
'Call to function is_int() with int<1, max> will always evaluate to true.',
1212+
198,
1213+
],
1214+
]);
12061215
}
12071216

12081217
#[RequiresPhp('>= 8.1')]

tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public function testBug13874(): void
288288
$this->analyse([__DIR__ . '/data/bug-13874.php'], []);
289289
}
290290

291+
public function testBug13023(): void
292+
{
293+
$this->analyse([__DIR__ . '/data/bug-13023.php'], []);
294+
}
295+
291296
public function testBug12163(): void
292297
{
293298
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12163.php'], [

tests/PHPStan/Rules/Comparison/data/bug-13023.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,39 @@ public function getRandom(): int
170170
class SomeClass11
171171
{
172172
use MyTrait6;
173+
174+
/** @return non-empty-array */
175+
public function getBar(): array
176+
{
177+
return ['foo'];
178+
}
173179
}
174180

175-
trait MyTrait6
181+
class SomeClass12
176182
{
183+
use MyTrait6;
184+
185+
/** @return array{} */
177186
public function getBar(): array
178187
{
179188
return [];
180189
}
190+
}
191+
192+
trait MyTrait6
193+
{
194+
abstract public function getBar(): array;
181195

182196
public function getRandom(): int
183197
{
184198
if (!\is_int(count($this->getBar()))) {
185199
return 1;
186200
}
187201

202+
if (count($this->getBar()) > 0) {
203+
return 1;
204+
}
205+
188206
return 0;
189207
}
190208
}

0 commit comments

Comments
 (0)