Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 19, 2021
1 parent fe4c770 commit 3c43c54
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ public function testRule(): void
]);
}

public function testBug3261(): void
{
if (!self::$useStaticReflectionProvider && PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->analyse([__DIR__ . '/data/bug-3261.php'], []);
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,14 @@ public function testBug2846(): void
$this->analyse([__DIR__ . '/data/bug-2846.php'], []);
}

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

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

}
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ public function testIsGenerator(): void
$this->analyse([__DIR__ . '/data/is-generator.php'], []);
}

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

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

namespace Bug2568;

/**
* @template T
*
* @param array<T, mixed> $arr
* @return array<int, T>
*/
function my_array_keys($arr) {
return array_keys($arr);
}
20 changes: 20 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-3261.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php // lint >= 7.4

namespace Bug3261;

class A
{
}

class B extends A {}

function (): void {
/** @var A[] $a */
$a = [];

array_filter(
$a,
fn (A $a) => $a instanceof B
);

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

namespace Bug3608;

interface IHost
{
/** @return IHost[] * */
public static function getArray();
}

class MyHost implements IHost
{
public static function getArray()
{
return [new self()];
}
}

class HelloWorld
{
/**
* @param class-string<IHost> $name
**/
public function getConfig(string $name): void
{
call_user_func([$name, 'getArray']);

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

namespace Bug3920;

class HelloWorld
{
/**
* @return class-string<Two>
*/
public function sayHello(string $a)
{

$arr = [
'a' => Two::class,
'c' => Two::class,
];
return $arr[$a];
}

public function sayType(): void
{
call_user_func([One::class, 'isType']);
call_user_func([Two::class, 'isType']);
$class = $this->sayHello('a');
$type = $class::isType();
$callable = [$class, 'isType'];
call_user_func($callable);
if (is_callable($callable)) {
call_user_func($callable);
}
}
}

class One {
public static function isType(): bool
{
return true;
}
}
class Two extends One {

}
class Three {}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,12 @@ public function testMissingMixedReturnInEmptyBody(): void
]);
}

public function testBug3669(): void
{
$this->checkExplicitMixedMissingReturn = true;

require_once __DIR__ . '/data/bug-3669.php';
$this->analyse([__DIR__ . '/data/bug-3669.php'], []);
}

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

namespace Bug3669;

function foo(): \Generator
{
while ($bar = yield 'foo') {
}
}

function bar($m): \Generator
{
while ($bar = yield $m) {
}
}
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Variables/UnsetRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ public function testBug2752(): void
$this->analyse([__DIR__ . '/data/bug-2752.php'], []);
}

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

}
28 changes: 28 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-4289.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types = 1);

namespace Bug4289;

class BaseClass
{
protected array $fields = [];

function populateFields(): void
{
$this->fields = [
'foo' => 'bar',
'some' => 'what',
];
}
}

class ChildClass extends BaseClass
{
public function populateFields(): void
{
if (empty($this->fields)) {
parent::populateFields();

unset($this->fields['foo']);
}
}
}

0 comments on commit 3c43c54

Please sign in to comment.