/
AccessPropertiesInAssignRuleTest.php
83 lines (74 loc) · 2.02 KB
/
AccessPropertiesInAssignRuleTest.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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Properties;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<AccessPropertiesInAssignRule>
*/
class AccessPropertiesInAssignRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$reflectionProvider = $this->createReflectionProvider();
return new AccessPropertiesInAssignRule(
new AccessPropertiesRule($reflectionProvider, new RuleLevelHelper($reflectionProvider, true, false, true, false), true, true),
);
}
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/access-properties-assign.php'], [
[
'Access to an undefined property TestAccessPropertiesAssign\AccessPropertyWithDimFetch::$foo.',
10,
],
[
'Access to an undefined property TestAccessPropertiesAssign\AccessPropertyWithDimFetch::$foo.',
15,
],
]);
}
public function testRuleAssignOp(): void
{
if (PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}
$this->analyse([__DIR__ . '/data/access-properties-assign-op.php'], [
[
'Access to an undefined property TestAccessProperties\AssignOpNonexistentProperty::$flags.',
15,
],
]);
}
public function testRuleExpressionNames(): void
{
$this->analyse([__DIR__ . '/data/properties-from-variable-into-object.php'], [
[
'Access to an undefined property PropertiesFromVariableIntoObject\Foo::$noop.',
26,
],
]);
}
public function testRuleExpressionNames2(): void
{
$this->analyse([__DIR__ . '/data/properties-from-array-into-object.php'], [
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
42,
],
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
54,
],
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
69,
],
[
'Access to an undefined property PropertiesFromArrayIntoObject\Foo::$noop.',
110,
],
]);
}
}