forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeInferenceTestCaseTest.php
104 lines (93 loc) · 3.56 KB
/
TypeInferenceTestCaseTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php declare(strict_types = 1);
namespace PHPStan\Testing;
use PHPStan\File\FileHelper;
use PHPUnit\Framework\AssertionFailedError;
use function array_values;
use function sprintf;
final class TypeInferenceTestCaseTest extends TypeInferenceTestCase
{
public static function dataFileAssertionFailedErrors(): iterable
{
/** @var FileHelper $fileHelper */
$fileHelper = self::getContainer()->getByType(FileHelper::class);
yield [
__DIR__ . '/data/assert-certainty-missing-namespace.php',
sprintf(
'Missing use statement for assertVariableCertainty() in %s on line 8.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-certainty-missing-namespace.php'),
),
];
yield [
__DIR__ . '/data/assert-native-type-missing-namespace.php',
sprintf(
'Missing use statement for assertNativeType() in %s on line 6.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-native-type-missing-namespace.php'),
),
];
yield [
__DIR__ . '/data/assert-type-missing-namespace.php',
sprintf(
'Missing use statement for assertType() in %s on line 6.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-type-missing-namespace.php'),
),
];
yield [
__DIR__ . '/data/assert-certainty-wrong-namespace.php',
sprintf(
'Function PHPStan\Testing\assertVariableCertainty imported with wrong namespace SomeWrong\Namespace\assertVariableCertainty called in %s on line 9.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-certainty-wrong-namespace.php'),
),
];
yield [
__DIR__ . '/data/assert-native-type-wrong-namespace.php',
sprintf(
'Function PHPStan\Testing\assertNativeType imported with wrong namespace SomeWrong\Namespace\assertNativeType called in %s on line 8.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-native-type-wrong-namespace.php'),
),
];
yield [
__DIR__ . '/data/assert-type-wrong-namespace.php',
sprintf(
'Function PHPStan\Testing\assertType imported with wrong namespace SomeWrong\Namespace\assertType called in %s on line 8.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-type-wrong-namespace.php'),
),
];
yield [
__DIR__ . '/data/assert-certainty-case-insensitive.php',
sprintf(
'Missing use statement for assertvariablecertainty() in %s on line 8.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-certainty-case-insensitive.php'),
),
];
yield [
__DIR__ . '/data/assert-native-type-case-insensitive.php',
sprintf(
'Missing use statement for assertNATIVEType() in %s on line 6.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-native-type-case-insensitive.php'),
),
];
yield [
__DIR__ . '/data/assert-type-case-insensitive.php',
sprintf(
'Missing use statement for assertTYPe() in %s on line 6.',
$fileHelper->normalizePath('tests/PHPStan/Testing/data/assert-type-case-insensitive.php'),
),
];
}
/**
* @dataProvider dataFileAssertionFailedErrors
*/
public function testFileAssertionFailedErrors(string $filePath, string $errorMessage): void
{
$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage($errorMessage);
$this->gatherAssertTypes($filePath);
}
public function testVariableOrOffsetDescription(): void
{
$filePath = __DIR__ . '/data/assert-certainty-variable-or-offset.php';
[$variableAssert, $offsetAssert] = array_values($this->gatherAssertTypes($filePath));
$this->assertSame('variable $context', $variableAssert[4]);
$this->assertSame("offset 'email'", $offsetAssert[4]);
}
}