Skip to content

Commit

Permalink
added type inference test
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Mar 5, 2024
1 parent 8b011d5 commit 84de378
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/PHPStan/Analyser/Bug10483InferenceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Testing\TypeInferenceTestCase;

class Bug10483InferenceTest extends TypeInferenceTestCase
{

public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug10483.php');
}

/**
* @dataProvider dataFileAsserts
* @param mixed ...$args
*/
public function testFileAsserts(
string $assertType,
string $file,
...$args,
): void
{
$this->assertFileAsserts($assertType, $file, ...$args);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/data/bug10483.neon',
];
}

}
5 changes: 5 additions & 0 deletions tests/PHPStan/Analyser/data/bug10483-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

// constant that's used in the Filter extension that was introduced in a later version of PHP.
// on earlier php version introduce the same constant via a bootstrap file but with a wrong type
if(!defined("FILTER_SANITIZE_ADD_SLASHES"))define("FILTER_SANITIZE_ADD_SLASHES",false);
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/data/bug10483.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 9
paths:
- src

bootstrapFiles:
- bug10483-bootstrap.php
9 changes: 9 additions & 0 deletions tests/PHPStan/Analyser/data/bug10483.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Bug10483;

use function PHPStan\Testing\assertType;

function doFoo(): void {
assertType('non-falsy-string|false', filter_var("no", FILTER_VALIDATE_REGEXP));
}

0 comments on commit 84de378

Please sign in to comment.