-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathNetteObjectClassReflectionExtensionTest.php
111 lines (101 loc) · 2.32 KB
/
NetteObjectClassReflectionExtensionTest.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
105
106
107
108
109
110
111
<?php declare(strict_types = 1);
namespace PHPStan\Reflection\Nette;
class NetteObjectClassReflectionExtensionTest extends \PHPStan\Testing\TestCase
{
/** @var \PHPStan\Broker\Broker */
private $broker;
/** @var \PHPStan\Reflection\Nette\NetteObjectClassReflectionExtension */
private $extension;
protected function setUp()
{
$this->broker = $this->createBroker();
$this->extension = new NetteObjectClassReflectionExtension();
}
/**
* @return mixed[]
*/
public function dataHasMethod(): array
{
$data = [];
$data[] = [
\PHPStan\Tests\SmartObjectChild::class,
'onPublicEvent',
true,
];
$data[] = [
\PHPStan\Tests\SmartObjectChild::class,
'onProtectedEvent',
false,
];
if (PHP_VERSION_ID < 70200) { // PHP 7.2 is incompatible with Nette\Object.
$data[] = [
'PHPStan\Tests\NetteObjectChild',
'onPublicEvent',
true,
];
$data[] = [
'PHPStan\Tests\NetteObjectChild',
'onProtectedEvent',
false,
];
}
return $data;
}
/**
* @dataProvider dataHasMethod
* @param string $className
* @param string $method
* @param bool $result
*/
public function testHasMethod(string $className, string $method, bool $result)
{
$classReflection = $this->broker->getClass($className);
$this->assertSame($result, $this->extension->hasMethod($classReflection, $method));
}
/**
* @return mixed[]
*/
public function dataHasProperty(): array
{
$data = [];
$data[] = [
\PHPStan\Tests\SmartObjectChild::class,
'foo',
false,
];
if (PHP_VERSION_ID < 70200) { // PHP 7.2 is incompatible with Nette\Object.
$data[] = [
'PHPStan\Tests\NetteObjectChild',
'staticProperty',
false,
];
$data[] = [
'PHPStan\Tests\NetteObjectChild',
'publicProperty',
true,
];
$data[] = [
'PHPStan\Tests\NetteObjectChild',
'protectedProperty',
false,
];
$data[] = [
'PHPStan\Tests\NetteObjectChild',
'methodAsClosureGetter',
true,
];
}
return $data;
}
/**
* @dataProvider dataHasProperty
* @param string $className
* @param string $property
* @param bool $result
*/
public function testHasProperty(string $className, string $property, bool $result)
{
$classReflection = $this->broker->getClass($className);
$this->assertSame($result, $this->extension->hasProperty($classReflection, $property));
}
}