-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeprecatedTest.php
More file actions
105 lines (87 loc) · 2.55 KB
/
DeprecatedTest.php
File metadata and controls
105 lines (87 loc) · 2.55 KB
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
<?php
declare(strict_types=1);
use PhpStaticAnalysis\Attributes\Deprecated;
use PHPUnit\Framework\TestCase;
#[Deprecated]
class DeprecatedTest extends TestCase
{
#[Deprecated]
public string $property;
public function testDeprecatedProperty(): void
{
$reflection = new ReflectionProperty($this, 'property');
$this->assertTrue(self::getDeprecatedFromReflection($reflection));
}
public function testClassDeprecated(): void
{
$reflection = new ReflectionClass($this);
$this->assertTrue(self::getDeprecatedFromReflection($reflection));
}
public function testTraitDeprecated(): void
{
$reflection = new ReflectionClass(DeprecatedTestTrait::class);
$this->assertTrue(self::getDeprecatedFromReflection($reflection));
}
public function testInterfaceDeprecated(): void
{
$reflection = new ReflectionClass(DeprecatedTestInterface::class);
$this->assertTrue(self::getDeprecatedFromReflection($reflection));
}
public function testMethodDeprecated(): void
{
$this->assertTrue($this->methodDeprecated());
}
public function testInvalidTypeMethodDeprecated(): void
{
$errorThrown = false;
try {
$this->invalidTypeMethodDeprecated();
} catch (Error $e) {
$errorThrown = true;
}
$this->assertTrue($errorThrown);
}
public function testFunctionDeprecated(): void
{
$this->assertTrue(functionDeprecated());
}
#[Deprecated]
private function methodDeprecated(): bool
{
return $this->getDeprecated(__FUNCTION__);
}
#[Deprecated]
#[Deprecated]
private function invalidTypeMethodDeprecated(): bool
{
return $this->getDeprecated(__FUNCTION__);
}
private function getDeprecated(string $methodName): bool
{
$reflection = new ReflectionMethod($this, $methodName);
return self::getDeprecatedFromReflection($reflection);
}
public static function getDeprecatedFromReflection(
ReflectionMethod | ReflectionFunction | ReflectionClass | ReflectionProperty $reflection
): bool {
return AttributeHelper::getInstances($reflection, Deprecated::class) !== [];
}
}
#[Deprecated]
trait DeprecatedTestTrait
{
}
#[Deprecated]
interface DeprecatedTestInterface
{
}
#[Deprecated]
function functionDeprecated(): bool
{
$reflection = new ReflectionFunction(__FUNCTION__);
return DeprecatedTest::getDeprecatedFromReflection($reflection);
}
class DeprecatedClass
{
use DeprecatedTestTrait;
}