Skip to content

Commit b47ca9f

Browse files
committed
Regression tests
1 parent f5b78d5 commit b47ca9f

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,13 @@ public function testBug8068(): void
544544
]);
545545
}
546546

547+
public function testBug6243(): void
548+
{
549+
if (PHP_VERSION_ID < 704000) {
550+
$this->markTestSkipped('Test requires PHP 7.4.');
551+
}
552+
553+
$this->analyse([__DIR__ . '/data/bug-6243.php'], []);
554+
}
555+
547556
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php // lint >= 7.4
2+
3+
namespace Bug6243;
4+
5+
class Foo
6+
{
7+
/** @var list<string>|(\ArrayAccess<int, string>&iterable<int, string>) */
8+
private iterable $values;
9+
10+
/**
11+
* @param list<string> $values
12+
*/
13+
public function update(array $values): void {
14+
foreach ($this->values as $key => $_) {
15+
unset($this->values[$key]);
16+
}
17+
18+
foreach ($values as $value) {
19+
$this->values[] = $value;
20+
}
21+
}
22+
}

tests/PHPStan/Rules/Classes/InstantiationRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,18 @@ public function testBug7594(): void
431431
$this->analyse([__DIR__ . '/data/bug-7594.php'], []);
432432
}
433433

434+
public function testBug3311a(): void
435+
{
436+
if (PHP_VERSION_ID < 70400) {
437+
$this->markTestSkipped('Test requires PHP 7.4.');
438+
}
439+
440+
$this->analyse([__DIR__ . '/data/bug-3311a.php'], [
441+
[
442+
'Parameter #1 $bar of class Bug3311a\Foo constructor expects list<string>, array{1: \'baz\'} given.',
443+
24,
444+
],
445+
]);
446+
}
447+
434448
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types = 1); // lint >= 7.4
2+
3+
namespace Bug3311a;
4+
5+
final class Foo
6+
{
7+
/**
8+
* @var array<int, string>
9+
* @psalm-var list<string>
10+
*/
11+
public array $bar = [];
12+
13+
/**
14+
* @param array<int, string> $bar
15+
* @psalm-param list<string> $bar
16+
*/
17+
public function __construct(array $bar)
18+
{
19+
$this->bar = $bar;
20+
}
21+
}
22+
23+
function () {
24+
$instance = new Foo([1 => 'baz']);
25+
};

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,19 @@ public function testIntegerRangesAndConstants(): void
503503
]);
504504
}
505505

506+
public function testBug3311b(): void
507+
{
508+
if (PHP_VERSION_ID < 70400) {
509+
$this->markTestSkipped('Test requires PHP 7.4.');
510+
}
511+
512+
$this->checkExplicitMixed = true;
513+
$this->analyse([__DIR__ . '/data/bug-3311b.php'], [
514+
[
515+
'Property Bug3311b\Foo::$bar (list<string>) does not accept non-empty-array<int<0, max>, string>.',
516+
16,
517+
],
518+
]);
519+
}
520+
506521
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1); // lint >= 7.4
2+
3+
namespace Bug3311b;
4+
5+
final class Foo
6+
{
7+
/**
8+
* @var array<int, string>
9+
* @psalm-var list<string>
10+
*/
11+
public array $bar = [];
12+
}
13+
14+
function () {
15+
$instance = new Foo;
16+
$instance->bar[1] = 'baz';
17+
};

0 commit comments

Comments
 (0)