|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Jaxon\Attributes\Tests\TestAttributes; |
|
5
|
|
|
|
|
6
|
|
|
use Jaxon\Attributes\Tests\AttributeTrait; |
|
7
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\Attribute; |
|
8
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\ClassAttribute; |
|
9
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\ClassExcluded; |
|
10
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\DiAttributeError; |
|
11
|
|
|
use Jaxon\Exception\SetupException; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
use function Jaxon\Attributes\_register; |
|
15
|
|
|
use function Jaxon\jaxon; |
|
16
|
|
|
use function realpath; |
|
17
|
|
|
|
|
18
|
|
|
class MetadataCacheTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
use AttributeTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $sCacheDir; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @throws SetupException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function setUp(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->sCacheDir = realpath(__DIR__ . '/../cache'); |
|
33
|
|
|
@mkdir($this->sCacheDir); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
jaxon()->di()->getPluginManager()->registerPlugins(); |
|
36
|
|
|
_register(); |
|
37
|
|
|
|
|
38
|
|
|
jaxon()->di()->val('jaxon_metadata_cache_dir', $this->sCacheDir); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @throws SetupException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function tearDown(): void |
|
45
|
|
|
{ |
|
46
|
|
|
jaxon()->reset(); |
|
47
|
|
|
parent::tearDown(); |
|
48
|
|
|
|
|
49
|
|
|
// Delete the temp dir and all its content |
|
50
|
|
|
// $aFiles = scandir($this->sCacheDir); |
|
51
|
|
|
// foreach ($aFiles as $sFile) |
|
52
|
|
|
// { |
|
53
|
|
|
// if($sFile !== '.' && $sFile !== '..') |
|
54
|
|
|
// { |
|
55
|
|
|
// @unlink($this->sCacheDir . DIRECTORY_SEPARATOR . $sFile); |
|
56
|
|
|
// } |
|
57
|
|
|
// } |
|
58
|
|
|
// @rmdir($this->sCacheDir); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @throws SetupException |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testUploadAndExcludeWriteCache() |
|
65
|
|
|
{ |
|
66
|
|
|
$xMetadata = $this->getAttributes(Attribute::class, ['saveFiles', 'doNot']); |
|
67
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
68
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
69
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
70
|
|
|
|
|
71
|
|
|
// Save the class metadata in the cache. |
|
72
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
73
|
|
|
$xMetadataCache->save(Attribute::class, $xMetadata); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$this->assertFalse($bExcluded); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertCount(1, $aProtected); |
|
78
|
|
|
$this->assertEquals('doNot', $aProtected[0]); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertCount(1, $aProperties); |
|
81
|
|
|
$this->assertArrayHasKey('saveFiles', $aProperties); |
|
82
|
|
|
$this->assertCount(1, $aProperties['saveFiles']); |
|
83
|
|
|
$this->assertEquals("'user-files'", $aProperties['saveFiles']['upload']); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @throws SetupException |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testUploadAndExcludeReadCache() |
|
90
|
|
|
{ |
|
91
|
|
|
// Read the class metadata from the cache, and run the same tests. |
|
92
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
93
|
|
|
$xMetadata = $xMetadataCache->read(Attribute::class); |
|
94
|
|
|
|
|
95
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
96
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
97
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertFalse($bExcluded); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertCount(1, $aProtected); |
|
102
|
|
|
$this->assertEquals('doNot', $aProtected[0]); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertCount(1, $aProperties); |
|
105
|
|
|
$this->assertArrayHasKey('saveFiles', $aProperties); |
|
106
|
|
|
$this->assertCount(1, $aProperties['saveFiles']); |
|
107
|
|
|
$this->assertEquals("'user-files'", $aProperties['saveFiles']['upload']); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @throws SetupException |
|
112
|
|
|
*/ |
|
113
|
|
|
public function testDatabagWriteCache() |
|
114
|
|
|
{ |
|
115
|
|
|
$xMetadata = $this->getAttributes(Attribute::class, ['withBags']); |
|
116
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
117
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
118
|
|
|
|
|
119
|
|
|
// Save the class metadata in the cache. |
|
120
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
121
|
|
|
$xMetadataCache->save(Attribute::class, $xMetadata); |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
$this->assertFalse($bExcluded); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertCount(1, $aProperties); |
|
126
|
|
|
$this->assertArrayHasKey('withBags', $aProperties); |
|
127
|
|
|
$this->assertCount(1, $aProperties['withBags']); |
|
128
|
|
|
$this->assertCount(2, $aProperties['withBags']['bags']); |
|
129
|
|
|
$this->assertEquals('user.name', $aProperties['withBags']['bags'][0]); |
|
130
|
|
|
$this->assertEquals('page.number', $aProperties['withBags']['bags'][1]); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @throws SetupException |
|
135
|
|
|
*/ |
|
136
|
|
|
public function testDatabagReadCache() |
|
137
|
|
|
{ |
|
138
|
|
|
// Read the class metadata from the cache, and run the same tests. |
|
139
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
140
|
|
|
$xMetadata = $xMetadataCache->read(Attribute::class); |
|
141
|
|
|
|
|
142
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
143
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
144
|
|
|
|
|
145
|
|
|
$this->assertFalse($bExcluded); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertCount(1, $aProperties); |
|
148
|
|
|
$this->assertArrayHasKey('withBags', $aProperties); |
|
149
|
|
|
$this->assertCount(1, $aProperties['withBags']); |
|
150
|
|
|
$this->assertCount(2, $aProperties['withBags']['bags']); |
|
151
|
|
|
$this->assertEquals('user.name', $aProperties['withBags']['bags'][0]); |
|
152
|
|
|
$this->assertEquals('page.number', $aProperties['withBags']['bags'][1]); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @throws SetupException |
|
157
|
|
|
*/ |
|
158
|
|
|
public function testCallbackWriteCache() |
|
159
|
|
|
{ |
|
160
|
|
|
$xMetadata = $this->getAttributes(Attribute::class, ['withCallbacks']); |
|
161
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
162
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
163
|
|
|
|
|
164
|
|
|
// Save the class metadata in the cache. |
|
165
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
166
|
|
|
$xMetadataCache->save(Attribute::class, $xMetadata); |
|
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
$this->assertFalse($bExcluded); |
|
169
|
|
|
|
|
170
|
|
|
$this->assertCount(1, $aProperties); |
|
171
|
|
|
$this->assertArrayHasKey('withCallbacks', $aProperties); |
|
172
|
|
|
$this->assertCount(1, $aProperties['withCallbacks']); |
|
173
|
|
|
$this->assertCount(2, $aProperties['withCallbacks']['callback']); |
|
174
|
|
|
$this->assertEquals('jaxon.callback.first', $aProperties['withCallbacks']['callback'][0]); |
|
175
|
|
|
$this->assertEquals('jaxon.callback.second', $aProperties['withCallbacks']['callback'][1]); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @throws SetupException |
|
180
|
|
|
*/ |
|
181
|
|
|
public function testCallbackReadCache() |
|
182
|
|
|
{ |
|
183
|
|
|
// Read the class metadata from the cache, and run the same tests. |
|
184
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
185
|
|
|
$xMetadata = $xMetadataCache->read(Attribute::class); |
|
186
|
|
|
|
|
187
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
188
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
189
|
|
|
|
|
190
|
|
|
$this->assertFalse($bExcluded); |
|
191
|
|
|
|
|
192
|
|
|
$this->assertCount(1, $aProperties); |
|
193
|
|
|
$this->assertArrayHasKey('withCallbacks', $aProperties); |
|
194
|
|
|
$this->assertCount(1, $aProperties['withCallbacks']); |
|
195
|
|
|
$this->assertCount(2, $aProperties['withCallbacks']['callback']); |
|
196
|
|
|
$this->assertEquals('jaxon.callback.first', $aProperties['withCallbacks']['callback'][0]); |
|
197
|
|
|
$this->assertEquals('jaxon.callback.second', $aProperties['withCallbacks']['callback'][1]); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @throws SetupException |
|
202
|
|
|
*/ |
|
203
|
|
|
public function testCallbacksWriteCache() |
|
204
|
|
|
{ |
|
205
|
|
|
$xMetadata = $this->getAttributes(Attribute::class, ['cbSingle', 'cbMultiple', 'cbParams']); |
|
206
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
207
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
208
|
|
|
|
|
209
|
|
|
// Save the class metadata in the cache. |
|
210
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
211
|
|
|
$xMetadataCache->save(Attribute::class, $xMetadata); |
|
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
$this->assertFalse($bExcluded); |
|
214
|
|
|
|
|
215
|
|
|
$this->assertCount(3, $aProperties); |
|
216
|
|
|
$this->assertArrayHasKey('cbSingle', $aProperties); |
|
217
|
|
|
$this->assertArrayHasKey('cbMultiple', $aProperties); |
|
218
|
|
|
$this->assertArrayHasKey('cbParams', $aProperties); |
|
219
|
|
|
|
|
220
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__before']); |
|
221
|
|
|
$this->assertCount(2, $aProperties['cbMultiple']['__before']); |
|
222
|
|
|
$this->assertCount(2, $aProperties['cbParams']['__before']); |
|
223
|
|
|
$this->assertArrayHasKey('funcBefore', $aProperties['cbSingle']['__before']); |
|
224
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['cbMultiple']['__before']); |
|
225
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['cbMultiple']['__before']); |
|
226
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['cbParams']['__before']); |
|
227
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['cbParams']['__before']); |
|
228
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__before']['funcBefore']); |
|
229
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore1']); |
|
230
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore2']); |
|
231
|
|
|
$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore1']); |
|
232
|
|
|
$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore2']); |
|
233
|
|
|
|
|
234
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__after']); |
|
235
|
|
|
$this->assertCount(3, $aProperties['cbMultiple']['__after']); |
|
236
|
|
|
$this->assertCount(1, $aProperties['cbParams']['__after']); |
|
237
|
|
|
$this->assertArrayHasKey('funcAfter', $aProperties['cbSingle']['__after']); |
|
238
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['cbMultiple']['__after']); |
|
239
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['cbMultiple']['__after']); |
|
240
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['cbMultiple']['__after']); |
|
241
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['cbParams']['__after']); |
|
242
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__after']['funcAfter']); |
|
243
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter1']); |
|
244
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter2']); |
|
245
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter3']); |
|
246
|
|
|
$this->assertIsArray($aProperties['cbParams']['__after']['funcAfter1']); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @throws SetupException |
|
251
|
|
|
*/ |
|
252
|
|
|
public function testCallbacksReadCache() |
|
253
|
|
|
{ |
|
254
|
|
|
// Read the class metadata from the cache, and run the same tests. |
|
255
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
256
|
|
|
$xMetadata = $xMetadataCache->read(Attribute::class); |
|
257
|
|
|
|
|
258
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
259
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
260
|
|
|
|
|
261
|
|
|
$this->assertFalse($bExcluded); |
|
262
|
|
|
|
|
263
|
|
|
$this->assertCount(3, $aProperties); |
|
264
|
|
|
$this->assertArrayHasKey('cbSingle', $aProperties); |
|
265
|
|
|
$this->assertArrayHasKey('cbMultiple', $aProperties); |
|
266
|
|
|
$this->assertArrayHasKey('cbParams', $aProperties); |
|
267
|
|
|
|
|
268
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__before']); |
|
269
|
|
|
$this->assertCount(2, $aProperties['cbMultiple']['__before']); |
|
270
|
|
|
$this->assertCount(2, $aProperties['cbParams']['__before']); |
|
271
|
|
|
$this->assertArrayHasKey('funcBefore', $aProperties['cbSingle']['__before']); |
|
272
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['cbMultiple']['__before']); |
|
273
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['cbMultiple']['__before']); |
|
274
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['cbParams']['__before']); |
|
275
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['cbParams']['__before']); |
|
276
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__before']['funcBefore']); |
|
277
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore1']); |
|
278
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore2']); |
|
279
|
|
|
$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore1']); |
|
280
|
|
|
$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore2']); |
|
281
|
|
|
|
|
282
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__after']); |
|
283
|
|
|
$this->assertCount(3, $aProperties['cbMultiple']['__after']); |
|
284
|
|
|
$this->assertCount(1, $aProperties['cbParams']['__after']); |
|
285
|
|
|
$this->assertArrayHasKey('funcAfter', $aProperties['cbSingle']['__after']); |
|
286
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['cbMultiple']['__after']); |
|
287
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['cbMultiple']['__after']); |
|
288
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['cbMultiple']['__after']); |
|
289
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['cbParams']['__after']); |
|
290
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__after']['funcAfter']); |
|
291
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter1']); |
|
292
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter2']); |
|
293
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter3']); |
|
294
|
|
|
$this->assertIsArray($aProperties['cbParams']['__after']['funcAfter1']); |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* @throws SetupException |
|
299
|
|
|
*/ |
|
300
|
|
|
public function testContainerWriteCache() |
|
301
|
|
|
{ |
|
302
|
|
|
$xMetadata = $this->getAttributes(Attribute::class, ['di1', 'di2']); |
|
303
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
304
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
305
|
|
|
|
|
306
|
|
|
// Save the class metadata in the cache. |
|
307
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
308
|
|
|
$xMetadataCache->save(Attribute::class, $xMetadata); |
|
|
|
|
|
|
309
|
|
|
|
|
310
|
|
|
$this->assertFalse($bExcluded); |
|
311
|
|
|
|
|
312
|
|
|
$this->assertCount(2, $aProperties); |
|
313
|
|
|
$this->assertArrayHasKey('di1', $aProperties); |
|
314
|
|
|
$this->assertArrayHasKey('di2', $aProperties); |
|
315
|
|
|
$this->assertCount(2, $aProperties['di1']['__di']); |
|
316
|
|
|
$this->assertCount(2, $aProperties['di2']['__di']); |
|
317
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['di1']['__di']['colorService']); |
|
318
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['di1']['__di']['fontService']); |
|
319
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['di2']['__di']['colorService']); |
|
320
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['di2']['__di']['textService']); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @throws SetupException |
|
325
|
|
|
*/ |
|
326
|
|
|
public function testContainerReadCache() |
|
327
|
|
|
{ |
|
328
|
|
|
// Read the class metadata from the cache, and run the same tests. |
|
329
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
330
|
|
|
$xMetadata = $xMetadataCache->read(Attribute::class); |
|
331
|
|
|
|
|
332
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
333
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
334
|
|
|
|
|
335
|
|
|
$this->assertFalse($bExcluded); |
|
336
|
|
|
|
|
337
|
|
|
$this->assertCount(2, $aProperties); |
|
338
|
|
|
$this->assertArrayHasKey('di1', $aProperties); |
|
339
|
|
|
$this->assertArrayHasKey('di2', $aProperties); |
|
340
|
|
|
$this->assertCount(2, $aProperties['di1']['__di']); |
|
341
|
|
|
$this->assertCount(2, $aProperties['di2']['__di']); |
|
342
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['di1']['__di']['colorService']); |
|
343
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['di1']['__di']['fontService']); |
|
344
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['di2']['__di']['colorService']); |
|
345
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['di2']['__di']['textService']); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* @throws SetupException |
|
350
|
|
|
*/ |
|
351
|
|
|
public function testClassWriteCache() |
|
352
|
|
|
{ |
|
353
|
|
|
$xMetadata = $this->getAttributes(ClassAttribute::class, []); |
|
354
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
355
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
356
|
|
|
|
|
357
|
|
|
// Save the class metadata in the cache. |
|
358
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
359
|
|
|
$xMetadataCache->save(ClassAttribute::class, $xMetadata); |
|
|
|
|
|
|
360
|
|
|
|
|
361
|
|
|
$this->assertFalse($bExcluded); |
|
362
|
|
|
|
|
363
|
|
|
$this->assertCount(1, $aProperties); |
|
364
|
|
|
$this->assertArrayHasKey('*', $aProperties); |
|
365
|
|
|
$this->assertCount(5, $aProperties['*']); |
|
366
|
|
|
$this->assertArrayHasKey('bags', $aProperties['*']); |
|
367
|
|
|
$this->assertArrayHasKey('callback', $aProperties['*']); |
|
368
|
|
|
$this->assertArrayHasKey('__before', $aProperties['*']); |
|
369
|
|
|
$this->assertArrayHasKey('__after', $aProperties['*']); |
|
370
|
|
|
$this->assertArrayHasKey('__di', $aProperties['*']); |
|
371
|
|
|
|
|
372
|
|
|
$this->assertCount(2, $aProperties['*']['bags']); |
|
373
|
|
|
$this->assertEquals('user.name', $aProperties['*']['bags'][0]); |
|
374
|
|
|
$this->assertEquals('page.number', $aProperties['*']['bags'][1]); |
|
375
|
|
|
|
|
376
|
|
|
$this->assertCount(2, $aProperties['*']['__before']); |
|
377
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['*']['__before']); |
|
378
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['*']['__before']); |
|
379
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore1']); |
|
380
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore2']); |
|
381
|
|
|
|
|
382
|
|
|
$this->assertCount(3, $aProperties['*']['__after']); |
|
383
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['*']['__after']); |
|
384
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['*']['__after']); |
|
385
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['*']['__after']); |
|
386
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter1']); |
|
387
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter2']); |
|
388
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter3']); |
|
389
|
|
|
|
|
390
|
|
|
$this->assertCount(3, $aProperties['*']['__di']); |
|
391
|
|
|
$this->assertArrayHasKey('colorService', $aProperties['*']['__di']); |
|
392
|
|
|
$this->assertArrayHasKey('textService', $aProperties['*']['__di']); |
|
393
|
|
|
$this->assertArrayHasKey('fontService', $aProperties['*']['__di']); |
|
394
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['*']['__di']['colorService']); |
|
395
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['*']['__di']['textService']); |
|
396
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService']); |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* @throws SetupException |
|
401
|
|
|
*/ |
|
402
|
|
|
public function testClassReadCache() |
|
403
|
|
|
{ |
|
404
|
|
|
// Read the class metadata from the cache, and run the same tests. |
|
405
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
406
|
|
|
$xMetadata = $xMetadataCache->read(ClassAttribute::class); |
|
407
|
|
|
|
|
408
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
409
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
410
|
|
|
|
|
411
|
|
|
$this->assertFalse($bExcluded); |
|
412
|
|
|
|
|
413
|
|
|
$this->assertCount(1, $aProperties); |
|
414
|
|
|
$this->assertArrayHasKey('*', $aProperties); |
|
415
|
|
|
$this->assertCount(5, $aProperties['*']); |
|
416
|
|
|
$this->assertArrayHasKey('bags', $aProperties['*']); |
|
417
|
|
|
$this->assertArrayHasKey('callback', $aProperties['*']); |
|
418
|
|
|
$this->assertArrayHasKey('__before', $aProperties['*']); |
|
419
|
|
|
$this->assertArrayHasKey('__after', $aProperties['*']); |
|
420
|
|
|
$this->assertArrayHasKey('__di', $aProperties['*']); |
|
421
|
|
|
|
|
422
|
|
|
$this->assertCount(2, $aProperties['*']['bags']); |
|
423
|
|
|
$this->assertEquals('user.name', $aProperties['*']['bags'][0]); |
|
424
|
|
|
$this->assertEquals('page.number', $aProperties['*']['bags'][1]); |
|
425
|
|
|
|
|
426
|
|
|
$this->assertCount(2, $aProperties['*']['__before']); |
|
427
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['*']['__before']); |
|
428
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['*']['__before']); |
|
429
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore1']); |
|
430
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore2']); |
|
431
|
|
|
|
|
432
|
|
|
$this->assertCount(3, $aProperties['*']['__after']); |
|
433
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['*']['__after']); |
|
434
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['*']['__after']); |
|
435
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['*']['__after']); |
|
436
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter1']); |
|
437
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter2']); |
|
438
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter3']); |
|
439
|
|
|
|
|
440
|
|
|
$this->assertCount(3, $aProperties['*']['__di']); |
|
441
|
|
|
$this->assertArrayHasKey('colorService', $aProperties['*']['__di']); |
|
442
|
|
|
$this->assertArrayHasKey('textService', $aProperties['*']['__di']); |
|
443
|
|
|
$this->assertArrayHasKey('fontService', $aProperties['*']['__di']); |
|
444
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['*']['__di']['colorService']); |
|
445
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['*']['__di']['textService']); |
|
446
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService']); |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* @throws SetupException |
|
451
|
|
|
*/ |
|
452
|
|
|
public function testClassExcludeWriteCache() |
|
453
|
|
|
{ |
|
454
|
|
|
$xMetadata = $this->getAttributes(ClassExcluded::class, |
|
455
|
|
|
['doNot', 'withBags', 'withCallbacks', 'cbSingle']); |
|
456
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
457
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
458
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
459
|
|
|
|
|
460
|
|
|
// Save the class metadata in the cache. |
|
461
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
462
|
|
|
$xMetadataCache->save(ClassExcluded::class, $xMetadata); |
|
|
|
|
|
|
463
|
|
|
|
|
464
|
|
|
$this->assertTrue($bExcluded); |
|
465
|
|
|
$this->assertEmpty($aProperties); |
|
466
|
|
|
$this->assertEmpty($aProtected); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* @throws SetupException |
|
471
|
|
|
*/ |
|
472
|
|
|
public function testClassExcludeReadCache() |
|
473
|
|
|
{ |
|
474
|
|
|
// Read the class metadata from the cache, and run the same tests. |
|
475
|
|
|
$xMetadataCache = jaxon()->di()->getMetadataCache(); |
|
476
|
|
|
$xMetadata = $xMetadataCache->read(ClassExcluded::class); |
|
477
|
|
|
|
|
478
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
479
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
480
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
481
|
|
|
|
|
482
|
|
|
$this->assertTrue($bExcluded); |
|
483
|
|
|
$this->assertEmpty($aProperties); |
|
484
|
|
|
$this->assertEmpty($aProtected); |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
public function testContainerAttributeWrongClassType() |
|
488
|
|
|
{ |
|
489
|
|
|
$this->expectException(SetupException::class); |
|
490
|
|
|
$this->getAttributes(DiAttributeError::class, ['diWrongClassType']); |
|
491
|
|
|
} |
|
492
|
|
|
} |
|
493
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: