Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 20, 2022
1 parent 7aa7269 commit 20a6b38
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php
Expand Up @@ -192,4 +192,12 @@ public function testBug7176(): void
$this->analyse([__DIR__ . '/data/bug-7176.php'], []);
}

public function testBug6064(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}
$this->analyse([__DIR__ . '/data/bug-6064.php'], []);
}

}
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-6064.php
@@ -0,0 +1,11 @@
<?php // lint >= 8.1

namespace Bug6064;

function (): void {
$result = match( rand() <=> rand() ) {
-1 => 'down',
0 => 'same',
1 => 'up'
};
};
17 changes: 16 additions & 1 deletion tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Expand Up @@ -13,14 +13,17 @@
class ReturnTypeRuleTest extends RuleTestCase
{

private bool $checkExplicitMixed;

protected function getRule(): Rule
{
return new ReturnTypeRule(new FunctionReturnTypeCheck(new RuleLevelHelper($this->createReflectionProvider(), true, false, true, false)));
return new ReturnTypeRule(new FunctionReturnTypeCheck(new RuleLevelHelper($this->createReflectionProvider(), true, false, true, $this->checkExplicitMixed)));
}

public function testReturnTypeRule(): void
{
require_once __DIR__ . '/data/returnTypes.php';
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/returnTypes.php'], [
[
'Function ReturnTypes\returnInteger() should return int but returns string.',
Expand Down Expand Up @@ -67,6 +70,7 @@ public function testReturnTypeRule(): void

public function testReturnTypeRulePhp70(): void
{
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/returnTypes-7.0.php'], [
[
'Function ReturnTypes\Php70\returnInteger() should return int but empty return statement found.',
Expand All @@ -77,18 +81,21 @@ public function testReturnTypeRulePhp70(): void

public function testIsGenerator(): void
{
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/is-generator.php'], []);
}

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

public function testBug2723(): void
{
require_once __DIR__ . '/data/bug-2723.php';
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/bug-2723.php'], [
[
'Function Bug2723\baz() should return Bug2723\Bar<Bug2723\Foo<T4>> but returns Bug2723\BarOfFoo<string>.',
Expand All @@ -99,12 +106,20 @@ public function testBug2723(): void

public function testBug5706(): void
{
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/bug-5706.php'], []);
}

public function testBug5844(): void
{
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/bug-5844.php'], []);
}

public function testBug7218(): void
{
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-7218.php'], []);
}

}
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-7218.php
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace Bug7218;

/** @template T */
class Foo {}

/** @return Foo<string> */
function getFoo(): Foo
{
/** @var Foo<string> */
return new Foo();
}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Variables/IssetRuleTest.php
Expand Up @@ -397,4 +397,12 @@ public function testBug7318(): void
]);
}

public function testBug6163(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->strictUnnecessaryNullsafePropertyFetch = true;

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

}
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-6163.php
@@ -0,0 +1,12 @@
<?php

namespace Bug6163;

function (): void {
$products = [];
foreach (['123', 'abc'] as $id) {
$products[$id] = true;
}

var_dump(isset($products['123']));
};

0 comments on commit 20a6b38

Please sign in to comment.