Passed
Push — main ( 124c22...ff6848 )
by Thierry
07:11
created

MetadataCacheTest::testNodeComponentExport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 10
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\Component\NodeBaseComponent;
11
use Jaxon\Attributes\Tests\Attr\Ajax\DiAttributeError;
12
use Jaxon\Exception\SetupException;
13
use PHPUnit\Framework\TestCase;
14
15
use function Jaxon\Attributes\_register;
16
use function Jaxon\jaxon;
17
use function realpath;
18
19
class MetadataCacheTest extends TestCase
20
{
21
    use AttributeTrait;
22
23
    /**
24
     * @var string
25
     */
26
    private $sCacheDir;
27
28
    /**
29
     * @throws SetupException
30
     */
31
    public function setUp(): void
32
    {
33
        $this->sCacheDir = realpath(__DIR__ . '/../cache');
34
        @mkdir($this->sCacheDir);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mkdir(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

34
        /** @scrutinizer ignore-unhandled */ @mkdir($this->sCacheDir);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

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