|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Parser\Tests\Reflections\ReflectionClass; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface; |
|
6
|
|
|
use ApiGen\Parser\Tests\Reflection\ReflectionClass\AbstractReflectionClassTestCase; |
|
7
|
|
|
|
|
8
|
|
|
final class TraitsTest extends AbstractReflectionClassTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testIsTrait(): void |
|
11
|
|
|
{ |
|
12
|
|
|
$this->assertFalse($this->reflectionClass->isTrait()); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function testGetTraits(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$traits = $this->reflectionClass->getTraits(); |
|
18
|
|
|
$this->assertCount(2, $traits); |
|
19
|
|
|
$this->assertInstanceOf(ClassReflectionInterface::class, $traits['Project\SomeTrait']); |
|
20
|
|
|
$this->assertSame('Project\SomeTraitNotPresentHere', $traits['Project\SomeTraitNotPresentHere']); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testGetOwnTraits(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$traits = $this->reflectionClass->getOwnTraits(); |
|
26
|
|
|
$this->assertCount(2, $traits); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetTraitNames(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->assertSame( |
|
32
|
|
|
['Project\SomeTrait', 'Project\SomeTraitNotPresentHere'], |
|
33
|
|
|
$this->reflectionClass->getTraitNames() |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetOwnTraitName(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertSame( |
|
40
|
|
|
['Project\SomeTrait', 'Project\SomeTraitNotPresentHere'], |
|
41
|
|
|
$this->reflectionClass->getOwnTraitNames() |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testGetTraitAliases(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->assertCount(0, $this->reflectionClass->getTraitAliases()); |
|
48
|
|
|
}// |
|
49
|
|
|
|
|
50
|
|
|
public function testGetTraitProperties(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertCount(1, $this->reflectionClass->getTraitProperties()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testGetTraitMethods(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->assertCount(1, $this->reflectionClass->getTraitMethods()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testUsesTrait(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->assertTrue($this->reflectionClass->usesTrait('Project\SomeTrait')); |
|
63
|
|
|
$this->assertFalse($this->reflectionClass->usesTrait('Project\NotActiveTrait')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @expectedException \TokenReflection\Exception\RuntimeException |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testUsesTraitNotExisting(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->reflectionClass->usesTrait('Project\SomeTraitNotPresentHere'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testGetDirectUsers(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertCount(1, $this->reflectionClassOfTrait->getDirectUsers()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testGetIndirectUsers(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$this->assertCount(0, $this->reflectionClassOfTrait->getIndirectUsers()); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|