Skip to content

Commit 1d86de8

Browse files
authored
More precise return type for gatherAssertTypes
1 parent 19dfc5e commit 1d86de8

File tree

6 files changed

+18
-25
lines changed

6 files changed

+18
-25
lines changed

src/Testing/TypeInferenceTestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,13 @@ public function assertFileAsserts(
220220
}
221221

222222
/**
223+
* @return array<string, (
224+
* array{0: 'type', 1: string, 2: int|float|string|bool|null, 3: string, 4: int, 5?: non-empty-list<non-falsy-string>}|
225+
* array{0: 'superType', 1: string, 2: string, 3: string, 4: bool, 5: int, 6?: non-empty-list<non-falsy-string>}|
226+
* array{0: 'variableCertainty', 1: string, 2: TrinaryLogic, 3: TrinaryLogic, 4: string, 5: int, 6?: non-empty-list<non-falsy-string>}
227+
* )>
228+
*
223229
* @api
224-
* @return array<string, mixed[]>
225230
*/
226231
public static function gatherAssertTypes(string $file): array
227232
{

tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
class LooseConstComparisonPhp7Test extends TypeInferenceTestCase
99
{
1010

11-
/**
12-
* @return iterable<array<string, mixed[]>>
13-
*/
1411
public static function dataFileAsserts(): iterable
1512
{
1613
// compares constants according to the php-version phpstan configuration,

tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
class LooseConstComparisonPhp8Test extends TypeInferenceTestCase
99
{
1010

11-
/**
12-
* @return iterable<array<string, mixed[]>>
13-
*/
1411
public static function dataFileAsserts(): iterable
1512
{
1613
// compares constants according to the php-version phpstan configuration,

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPUnit\Framework\Attributes\DataProvider;
99
use stdClass;
1010
use function array_merge;
11-
use function array_shift;
1211
use function define;
1312
use function dirname;
1413
use function implode;
@@ -270,23 +269,24 @@ public function testFile(string $file): void
270269
$failures = [];
271270

272271
foreach ($asserts as $args) {
273-
$assertType = array_shift($args);
274-
$file = array_shift($args);
272+
if ($args[0] === 'type') {
273+
$file = $args[1];
275274

276-
if ($assertType === 'type') {
277-
$expected = $args[0];
278-
$actual = $args[1];
275+
$expected = $args[2];
276+
$actual = $args[3];
279277

280278
if ($expected !== $actual) {
281-
$failures[] = sprintf("Line %d:\nExpected: %s\nActual: %s\n", $args[2], $expected, $actual);
279+
$failures[] = sprintf("Line %d:\nExpected: %s\nActual: %s\n", $args[4], $expected, $actual);
282280
}
283-
} elseif ($assertType === 'variableCertainty') {
284-
$expectedCertainty = $args[0];
285-
$actualCertainty = $args[1];
286-
$variableName = $args[2];
281+
} elseif ($args[0] === 'variableCertainty') {
282+
$file = $args[1];
283+
284+
$expectedCertainty = $args[2];
285+
$actualCertainty = $args[3];
286+
$variableName = $args[4];
287287

288288
if ($expectedCertainty->equals($actualCertainty) !== true) {
289-
$failures[] = sprintf("Certainty of %s on line %d:\nExpected: %s\nActual: %s\n", $variableName, $args[3], $expectedCertainty->describe(), $actualCertainty->describe());
289+
$failures[] = sprintf("Certainty of %s on line %d:\nExpected: %s\nActual: %s\n", $variableName, $args[5], $expectedCertainty->describe(), $actualCertainty->describe());
290290
}
291291
}
292292
}

tests/PHPStan/Analyser/SubstrPhp7Test.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
class SubstrPhp7Test extends TypeInferenceTestCase
99
{
1010

11-
/**
12-
* @return iterable<array<string, mixed[]>>
13-
*/
1411
public static function dataFileAsserts(): iterable
1512
{
1613
yield from self::gatherAssertTypes(__DIR__ . '/data/bug-13129-php7.php');

tests/PHPStan/Analyser/SubstrPhp8Test.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
class SubstrPhp8Test extends TypeInferenceTestCase
99
{
1010

11-
/**
12-
* @return iterable<array<string, mixed[]>>
13-
*/
1411
public static function dataFileAsserts(): iterable
1512
{
1613
yield from self::gatherAssertTypes(__DIR__ . '/data/bug-13129-php8.php');

0 commit comments

Comments
 (0)