|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jaxon\Attributes\Tests\TestAttributes; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Attributes\Tests\AttributeTrait; |
|
6
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\ClassExtendsAttribute; |
|
7
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\ClassExtendsExcluded; |
|
8
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\ClassExtendsTraitExcluded; |
|
9
|
|
|
use Jaxon\Exception\SetupException; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
use function Jaxon\Attributes\_register; |
|
13
|
|
|
use function Jaxon\jaxon; |
|
14
|
|
|
|
|
15
|
|
|
class ClassExtendsTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
use AttributeTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $sCacheDir; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @throws SetupException |
|
26
|
|
|
*/ |
|
27
|
|
|
public function setUp(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->sCacheDir = __DIR__ . '/../cache'; |
|
30
|
|
|
@mkdir($this->sCacheDir); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
jaxon()->di()->getPluginManager()->registerPlugins(); |
|
33
|
|
|
_register(); |
|
34
|
|
|
|
|
35
|
|
|
jaxon()->di()->val('jaxon_attributes_cache_dir', $this->sCacheDir); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @throws SetupException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function tearDown(): void |
|
42
|
|
|
{ |
|
43
|
|
|
jaxon()->reset(); |
|
44
|
|
|
parent::tearDown(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @throws SetupException |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testInheritedAttributes() |
|
51
|
|
|
{ |
|
52
|
|
|
$xMetadata = $this->getAttributes(ClassExtendsExcluded::class, |
|
53
|
|
|
['doNot', 'withBags', 'cbSingle']); |
|
54
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
55
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
56
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertFalse($bExcluded); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertCount(1, $aProtected); |
|
61
|
|
|
$this->assertEquals('doNot', $aProtected[0]); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertCount(2, $aProperties); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertArrayHasKey('withBags', $aProperties); |
|
66
|
|
|
$this->assertCount(1, $aProperties['withBags']); |
|
67
|
|
|
$this->assertCount(2, $aProperties['withBags']['bags']); |
|
68
|
|
|
$this->assertEquals('user.name', $aProperties['withBags']['bags'][0]); |
|
69
|
|
|
$this->assertEquals('page.number', $aProperties['withBags']['bags'][1]); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertArrayHasKey('cbSingle', $aProperties); |
|
72
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__before']); |
|
73
|
|
|
$this->assertArrayHasKey('funcBefore', $aProperties['cbSingle']['__before']); |
|
74
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__before']['funcBefore']); |
|
75
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__after']); |
|
76
|
|
|
$this->assertArrayHasKey('funcAfter', $aProperties['cbSingle']['__after']); |
|
77
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__after']['funcAfter']); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @throws SetupException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testInheritedTraitAttributes() |
|
84
|
|
|
{ |
|
85
|
|
|
$xMetadata = $this->getAttributes(ClassExtendsTraitExcluded::class, |
|
86
|
|
|
['doNot', 'withBags', 'cbSingle', 'cbMultiple', 'withCallbacks']); |
|
87
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
88
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
89
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertFalse($bExcluded); |
|
92
|
|
|
$this->assertEmpty($aProtected); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertCount(4, $aProperties); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertArrayHasKey('withBags', $aProperties); |
|
97
|
|
|
$this->assertCount(1, $aProperties['withBags']); |
|
98
|
|
|
$this->assertCount(2, $aProperties['withBags']['bags']); |
|
99
|
|
|
$this->assertEquals('user.name', $aProperties['withBags']['bags'][0]); |
|
100
|
|
|
$this->assertEquals('page.number', $aProperties['withBags']['bags'][1]); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertArrayHasKey('cbSingle', $aProperties); |
|
103
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__before']); |
|
104
|
|
|
$this->assertArrayHasKey('funcBefore', $aProperties['cbSingle']['__before']); |
|
105
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__before']['funcBefore']); |
|
106
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__after']); |
|
107
|
|
|
$this->assertArrayHasKey('funcAfter', $aProperties['cbSingle']['__after']); |
|
108
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__after']['funcAfter']); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertArrayHasKey('cbMultiple', $aProperties); |
|
111
|
|
|
$this->assertCount(2, $aProperties['cbMultiple']['__before']); |
|
112
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['cbMultiple']['__before']); |
|
113
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['cbMultiple']['__before']); |
|
114
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore1']); |
|
115
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore2']); |
|
116
|
|
|
$this->assertCount(3, $aProperties['cbMultiple']['__after']); |
|
117
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['cbMultiple']['__after']); |
|
118
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['cbMultiple']['__after']); |
|
119
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['cbMultiple']['__after']); |
|
120
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter1']); |
|
121
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter2']); |
|
122
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter3']); |
|
123
|
|
|
|
|
124
|
|
|
$this->assertArrayHasKey('withCallbacks', $aProperties); |
|
125
|
|
|
$this->assertCount(1, $aProperties['withCallbacks']); |
|
126
|
|
|
$this->assertCount(2, $aProperties['withCallbacks']['callback']); |
|
127
|
|
|
$this->assertEquals('jaxon.callback.first', $aProperties['withCallbacks']['callback'][0]); |
|
128
|
|
|
$this->assertEquals('jaxon.callback.second', $aProperties['withCallbacks']['callback'][1]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @throws SetupException |
|
133
|
|
|
*/ |
|
134
|
|
|
public function testClassExtendsAttribute() |
|
135
|
|
|
{ |
|
136
|
|
|
$xMetadata = $this->getAttributes(ClassExtendsAttribute::class, []); |
|
137
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
138
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
139
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertFalse($bExcluded); |
|
142
|
|
|
$this->assertEmpty($aProtected); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertCount(1, $aProperties); |
|
145
|
|
|
$this->assertArrayHasKey('*', $aProperties); |
|
146
|
|
|
$this->assertCount(5, $aProperties['*']); |
|
147
|
|
|
$this->assertArrayHasKey('bags', $aProperties['*']); |
|
148
|
|
|
$this->assertArrayHasKey('callback', $aProperties['*']); |
|
149
|
|
|
$this->assertArrayHasKey('__before', $aProperties['*']); |
|
150
|
|
|
$this->assertArrayHasKey('__after', $aProperties['*']); |
|
151
|
|
|
$this->assertArrayHasKey('__di', $aProperties['*']); |
|
152
|
|
|
|
|
153
|
|
|
$this->assertCount(2, $aProperties['*']['bags']); |
|
154
|
|
|
$this->assertEquals('user.name', $aProperties['*']['bags'][0]); |
|
155
|
|
|
$this->assertEquals('page.number', $aProperties['*']['bags'][1]); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertCount(2, $aProperties['*']['__before']); |
|
158
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['*']['__before']); |
|
159
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['*']['__before']); |
|
160
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore1']); |
|
161
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore2']); |
|
162
|
|
|
|
|
163
|
|
|
$this->assertCount(3, $aProperties['*']['__after']); |
|
164
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['*']['__after']); |
|
165
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['*']['__after']); |
|
166
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['*']['__after']); |
|
167
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter1']); |
|
168
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter2']); |
|
169
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter3']); |
|
170
|
|
|
|
|
171
|
|
|
$this->assertCount(3, $aProperties['*']['__di']); |
|
172
|
|
|
$this->assertArrayHasKey('colorService', $aProperties['*']['__di']); |
|
173
|
|
|
$this->assertArrayHasKey('textService', $aProperties['*']['__di']); |
|
174
|
|
|
$this->assertArrayHasKey('fontService', $aProperties['*']['__di']); |
|
175
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['*']['__di']['colorService']); |
|
176
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['*']['__di']['textService']); |
|
177
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService']); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: