-
Notifications
You must be signed in to change notification settings - Fork 12
/
EnforceClosureParamNativeTypehintRuleTest.php
64 lines (49 loc) 路 1.95 KB
/
EnforceClosureParamNativeTypehintRuleTest.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
<?php declare(strict_types = 1);
namespace ShipMonk\PHPStan\Rule;
use LogicException;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\Rule;
use ShipMonk\PHPStan\RuleTestCase;
/**
* @extends RuleTestCase<EnforceClosureParamNativeTypehintRule>
*/
class EnforceClosureParamNativeTypehintRuleTest extends RuleTestCase
{
private ?bool $allowMissingTypeWhenInferred = null;
private ?PhpVersion $phpVersion = null;
protected function getRule(): Rule
{
if ($this->allowMissingTypeWhenInferred === null || $this->phpVersion === null) {
throw new LogicException('Missing phpVersion or allowMissingTypeWhenInferred');
}
return new EnforceClosureParamNativeTypehintRule(
$this->phpVersion,
$this->allowMissingTypeWhenInferred,
);
}
public function testAllowInferring(): void
{
$this->allowMissingTypeWhenInferred = true;
$this->phpVersion = $this->createPhpVersion(80_000);
$this->analyseFile(__DIR__ . '/data/EnforceClosureParamNativeTypehintRule/allow-inferring.php');
}
public function testEnforceEverywhere(): void
{
$this->allowMissingTypeWhenInferred = false;
$this->phpVersion = $this->createPhpVersion(80_000);
$this->analyseFile(__DIR__ . '/data/EnforceClosureParamNativeTypehintRule/enforce-everywhere.php');
}
public function testNoErrorOnPhp74(): void
{
$this->allowMissingTypeWhenInferred = false;
$this->phpVersion = $this->createPhpVersion(70_400);
self::assertEmpty($this->processActualErrors($this->gatherAnalyserErrors([
__DIR__ . '/data/EnforceClosureParamNativeTypehintRule/allow-inferring.php',
__DIR__ . '/data/EnforceClosureParamNativeTypehintRule/enforce-everywhere.php',
])));
}
private function createPhpVersion(int $version): PhpVersion
{
return new PhpVersion($version); // @phpstan-ignore-line ignore bc promise
}
}