Skip to content

Commit

Permalink
Add regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen committed May 27, 2022
1 parent c65f834 commit 5d33443
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Expand Up @@ -835,6 +835,18 @@ public function testBug7248(): void
$this->assertNoErrors($errors);
}

public function testBug6653(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6653.php');
$this->assertNoErrors($errors);
}

public function testBug5592(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5592.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Analyser/data/bug-5592.php
@@ -0,0 +1,12 @@
<?php declare(strict_types = 1);

namespace Bug5592;

/**
* @param \Ds\Map<\Ds\Hashable, numeric-string> $map
* @return numeric-string
*/
function mapGet(\Ds\Map $map, \Ds\Hashable $key): string
{
return $map->get($key, '0');
}
38 changes: 38 additions & 0 deletions tests/PHPStan/Analyser/data/bug-6653.php
@@ -0,0 +1,38 @@
<?php declare(strict_types = 1);

namespace Bug6653;

class HelloWorld
{
/**
* @return array<string, int>|false
*/
public function sayHello()
{
$test = $this->getTest();
return $this->filterEvent('sayHello', $test);
}

/**
* @template TValue of mixed
* @param TValue $value
* @return TValue
*/
private function filterEvent(string $eventName, $value)
{
// do event
return $value;
}

/**
* @return array<string, int>|false
*/
private function getTest()
{
$failure = random_int(0, PHP_INT_MAX) % 2 ? true : false;
if ($failure === true) {
return false;
}
return ['foo' => 123];
}
}

0 comments on commit 5d33443

Please sign in to comment.