Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 18, 2021
1 parent cb04a6e commit 402b34a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,14 @@ public function testBug1664(): void
$this->analyse([__DIR__ . '/data/bug-1664.php'], []);
}

public function testBug2689(): void
{
$this->analyse([__DIR__ . '/data/bug-2689.php'], [
[
'Cannot access an offset on callable.',
14,
],
]);
}

}
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/bug-2689.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Bug2689;

class HelloWorld
{
/**
* @var callable[]
*/
private $listeners;

public function addListener(string $name, callable $callback): void
{
$this->listeners[$name][] = $callback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,11 @@ public function testBug1613(): void
$this->analyse([__DIR__ . '/data/bug-1613.php'], []);
}

public function testBug2714(): void
{
$this->checkAlwaysTrueCheckTypeFunctionCall = true;
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-2714.php'], []);
}

}
25 changes: 25 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-2714.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Bug2714;

function (): void
{
$list = [];

// creation of unpredictable values at 'type' key
for ($i = 0; $i < 3; $i++) {
$list[] = [
'type' => str_repeat('a', rand(1, 10)),
];
}

$list[] = [
'type' => 'x',
];

foreach ($list as $item) {
if (in_array($item['type'], ['aaa', 'aaaa'], TRUE)) {
echo 'OK';
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,9 @@ public function testBug2434(): void
$this->analyse([__DIR__ . '/data/bug-2434.php'], []);
}

public function testBug2846(): void
{
$this->analyse([__DIR__ . '/data/bug-2846.php'], []);
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-2846.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Bug2846;

class Test {
public static function staticFunc(): void {}
public static function callStatic(): void {
call_user_func([static::class, 'staticFunc']);
}
}

0 comments on commit 402b34a

Please sign in to comment.