Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 2, 2023
1 parent a849f06 commit a4e2bfe
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ public function dataFileAsserts(): iterable

if (PHP_VERSION_ID >= 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10071.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9394.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/allowed-subtypes-datetime.php');
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/data/bug-9394.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Bug9394;

use function PHPStan\Testing\assertType;

class Order
{
public bool $is_pre_order;
}

function (?Order $order): void {
if ($order?->is_pre_order === false) {
return;
}

assertType(Order::class . '|null', $order);
};
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Methods/NullsafeMethodCallRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ public function testBug9293(): void
$this->analyse([__DIR__ . '/../../Analyser/data/bug-9293.php'], []);
}

public function testBug6922b(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

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

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

namespace Bug6922b;

final class Configuration
{
public function isFirstOptionActive(): bool
{
return true;
}

public function isSecondOptionActive(): bool
{
return true;
}
}

function run(?Configuration $configuration): void
{
if (
$configuration?->isFirstOptionActive() === false ||
$configuration?->isSecondOptionActive() === false)
{
// ....
}
}
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,10 @@ public function testBug7384(): void
$this->analyse([__DIR__ . '/data/bug-7384.php'], []);
}

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

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

namespace Bug9309;

function a(): int {
declare(ticks=1) {
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@ public function testBug9105(): void
$this->analyse([__DIR__ . '/../../Analyser/data/bug-9105.php'], []);
}

public function testBug6922(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

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

}
25 changes: 25 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-6922.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php // lint >= 8.0

namespace Bug6922;

class Person {

public function __construct(
public readonly string $name,
public readonly bool $isDeveloper,
public readonly bool $isAdmin
) {

}
}

class Proof
{
public function test(?Person $person): void
{
if ($person?->isDeveloper === FALSE ||
$person?->isAdmin === FALSE) {
echo "Bug";
}
}
}
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,4 +1015,13 @@ public function testIsStringNarrowsCertainty(): void
]);
}

public function testBug5266(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = true;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-5266.php'], []);
}

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

namespace Bug5266;

class TestEnums
{
const SORT_ASC = 'sort_asc';
const SORT_DESC = 'sort_desc';

/**
* @param self::SORT_ASC|self::SORT_DESC $sortType
*/
public function sort(string $sortType): void
{
if ($sortType === self::SORT_ASC) {
$message = 'Sorting ASC';
} elseif ($sortType === self::SORT_DESC) {
$message = 'Sorting DESC';
}

echo $message . '\n';
}
}

0 comments on commit a4e2bfe

Please sign in to comment.