|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jaxon\Annotations\Tests\TestAnnotation; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Annotations\Tests\AnnotationTrait; |
|
6
|
|
|
use Jaxon\Annotations\Tests\Attr\Ajax\TraitAnnotated; |
|
7
|
|
|
use Jaxon\Exception\SetupException; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
use function Jaxon\jaxon; |
|
11
|
|
|
use function Jaxon\Annotations\_register; |
|
12
|
|
|
|
|
13
|
|
|
class TraitAnnotationTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
use AnnotationTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $sCacheDir; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @throws SetupException |
|
24
|
|
|
*/ |
|
25
|
|
|
public function setUp(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->sCacheDir = __DIR__ . '/../tmp'; |
|
28
|
|
|
@mkdir($this->sCacheDir); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
jaxon()->di()->getPluginManager()->registerPlugins(); |
|
31
|
|
|
_register(); |
|
32
|
|
|
|
|
33
|
|
|
jaxon()->di()->val('jaxon_annotations_cache_dir', $this->sCacheDir); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws SetupException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function tearDown(): void |
|
40
|
|
|
{ |
|
41
|
|
|
jaxon()->reset(); |
|
42
|
|
|
parent::tearDown(); |
|
43
|
|
|
|
|
44
|
|
|
// Delete the temp dir and all its content |
|
45
|
|
|
$aFiles = scandir($this->sCacheDir); |
|
46
|
|
|
foreach ($aFiles as $sFile) |
|
47
|
|
|
{ |
|
48
|
|
|
if($sFile !== '.' && $sFile !== '..') |
|
49
|
|
|
{ |
|
50
|
|
|
@unlink($this->sCacheDir . DIRECTORY_SEPARATOR . $sFile); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
@rmdir($this->sCacheDir); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @throws SetupException |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testTraitAnnotation() |
|
60
|
|
|
{ |
|
61
|
|
|
$xMetadata = $this->getAttributes(TraitAnnotated::class, []); |
|
62
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
63
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertFalse($bExcluded); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertCount(1, $aProperties); |
|
68
|
|
|
$this->assertArrayHasKey('*', $aProperties); |
|
69
|
|
|
$this->assertCount(4, $aProperties['*']); |
|
70
|
|
|
$this->assertArrayHasKey('bags', $aProperties['*']); |
|
71
|
|
|
$this->assertArrayHasKey('__before', $aProperties['*']); |
|
72
|
|
|
$this->assertArrayHasKey('__after', $aProperties['*']); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertCount(2, $aProperties['*']['bags']); |
|
75
|
|
|
$this->assertEquals('user.name', $aProperties['*']['bags'][0]); |
|
76
|
|
|
$this->assertEquals('page.number', $aProperties['*']['bags'][1]); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertCount(2, $aProperties['*']['__before']); |
|
79
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['*']['__before']); |
|
80
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['*']['__before']); |
|
81
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore1']); |
|
82
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore2']); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertCount(3, $aProperties['*']['__after']); |
|
85
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['*']['__after']); |
|
86
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['*']['__after']); |
|
87
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['*']['__after']); |
|
88
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter1']); |
|
89
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter2']); |
|
90
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter3']); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertCount(3, $aProperties['*']['__di']); |
|
93
|
|
|
$this->assertArrayHasKey('colorService', $aProperties['*']['__di']); |
|
94
|
|
|
$this->assertArrayHasKey('textService', $aProperties['*']['__di']); |
|
95
|
|
|
$this->assertArrayHasKey('fontService', $aProperties['*']['__di']); |
|
96
|
|
|
$this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['*']['__di']['colorService']); |
|
97
|
|
|
$this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['*']['__di']['textService']); |
|
98
|
|
|
$this->assertEquals('Jaxon\Annotations\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService']); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: