jaxon-php /
jaxon-mono
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Jaxon\Attributes\Tests\TestAttributes; |
||
| 4 | |||
| 5 | use Jaxon\Attributes\Tests\AttributeTrait; |
||
| 6 | use Jaxon\Attributes\Tests\Attr\Ajax\PropertyAttribute; |
||
| 7 | use Jaxon\Exception\SetupException; |
||
| 8 | use PHPUnit\Framework\TestCase; |
||
| 9 | |||
| 10 | use function Jaxon\Attributes\_register; |
||
| 11 | use function Jaxon\jaxon; |
||
| 12 | |||
| 13 | class PropertyAttributeTest extends TestCase |
||
| 14 | { |
||
| 15 | use AttributeTrait; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $sCacheDir; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @throws SetupException |
||
| 24 | */ |
||
| 25 | public function setUp(): void |
||
| 26 | { |
||
| 27 | $this->sCacheDir = __DIR__ . '/../cache'; |
||
| 28 | @mkdir($this->sCacheDir); |
||
|
0 ignored issues
–
show
|
|||
| 29 | |||
| 30 | jaxon()->di()->getPluginManager()->registerPlugins(); |
||
| 31 | _register(); |
||
| 32 | |||
| 33 | jaxon()->di()->val('jaxon_attributes_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 | |||
| 45 | /** |
||
| 46 | * @throws SetupException |
||
| 47 | */ |
||
| 48 | public function testContainerAttribute() |
||
| 49 | { |
||
| 50 | $xMetadata = $this->getAttributes(PropertyAttribute::class, |
||
| 51 | ['attrVar'], ['colorService', 'fontService', 'textService']); |
||
| 52 | $bExcluded = $xMetadata->isExcluded(); |
||
| 53 | $aProperties = $xMetadata->getProperties(); |
||
| 54 | $aExcluded = $xMetadata->getExceptMethods(); |
||
|
0 ignored issues
–
show
|
|||
| 55 | |||
| 56 | $this->assertFalse($bExcluded); |
||
| 57 | |||
| 58 | $this->assertCount(1, $aProperties); |
||
| 59 | $this->assertArrayHasKey('attrVar', $aProperties); |
||
| 60 | $this->assertCount(3, $aProperties['attrVar']['__di']); |
||
| 61 | $this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['attrVar']['__di']['colorService']); |
||
| 62 | $this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['attrVar']['__di']['fontService']); |
||
| 63 | $this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['attrVar']['__di']['textService']); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @throws SetupException |
||
| 68 | */ |
||
| 69 | public function testContainerDocBlockAttribute() |
||
| 70 | { |
||
| 71 | $xMetadata = $this->getAttributes(PropertyAttribute::class, |
||
| 72 | ['attrDbVar'], ['colorService', 'fontService', 'textService']); |
||
| 73 | $bExcluded = $xMetadata->isExcluded(); |
||
| 74 | $aProperties = $xMetadata->getProperties(); |
||
| 75 | $aExcluded = $xMetadata->getExceptMethods(); |
||
|
0 ignored issues
–
show
|
|||
| 76 | |||
| 77 | $this->assertFalse($bExcluded); |
||
| 78 | |||
| 79 | $this->assertCount(1, $aProperties); |
||
| 80 | $this->assertArrayHasKey('attrDbVar', $aProperties); |
||
| 81 | $this->assertCount(3, $aProperties['attrDbVar']['__di']); |
||
| 82 | $this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['attrDbVar']['__di']['colorService']); |
||
| 83 | $this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['attrDbVar']['__di']['fontService']); |
||
| 84 | $this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['attrDbVar']['__di']['textService']); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @throws SetupException |
||
| 89 | */ |
||
| 90 | public function testContainerDiAttribute() |
||
| 91 | { |
||
| 92 | $xMetadata = $this->getAttributes(PropertyAttribute::class, |
||
| 93 | ['attrDi'], ['colorService1', 'fontService1', 'textService1']); |
||
| 94 | $bExcluded = $xMetadata->isExcluded(); |
||
| 95 | $aProperties = $xMetadata->getProperties(); |
||
| 96 | $aExcluded = $xMetadata->getExceptMethods(); |
||
|
0 ignored issues
–
show
|
|||
| 97 | |||
| 98 | $this->assertFalse($bExcluded); |
||
| 99 | |||
| 100 | $this->assertCount(1, $aProperties); |
||
| 101 | $this->assertArrayHasKey('*', $aProperties); |
||
| 102 | $this->assertCount(3, $aProperties['*']['__di']); |
||
| 103 | $this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['*']['__di']['colorService1']); |
||
| 104 | $this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService1']); |
||
| 105 | $this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['*']['__di']['textService1']); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @throws SetupException |
||
| 110 | */ |
||
| 111 | public function testContainerDiAndVarAttribute() |
||
| 112 | { |
||
| 113 | $xMetadata = $this->getAttributes(PropertyAttribute::class, |
||
| 114 | ['attrDi'], ['colorService2', 'fontService2', 'textService2']); |
||
| 115 | $bExcluded = $xMetadata->isExcluded(); |
||
| 116 | $aProperties = $xMetadata->getProperties(); |
||
| 117 | $aExcluded = $xMetadata->getExceptMethods(); |
||
|
0 ignored issues
–
show
|
|||
| 118 | |||
| 119 | $this->assertFalse($bExcluded); |
||
| 120 | |||
| 121 | $this->assertCount(1, $aProperties); |
||
| 122 | $this->assertArrayHasKey('*', $aProperties); |
||
| 123 | $this->assertCount(3, $aProperties['*']['__di']); |
||
| 124 | $this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['*']['__di']['colorService2']); |
||
| 125 | $this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService2']); |
||
| 126 | $this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['*']['__di']['textService2']); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @throws SetupException |
||
| 131 | */ |
||
| 132 | public function testContainerPropAttribute() |
||
| 133 | { |
||
| 134 | $xMetadata = $this->getAttributes(PropertyAttribute::class, |
||
| 135 | ['attrDi'], ['colorService3', 'fontService3', 'textService3']); |
||
| 136 | $bExcluded = $xMetadata->isExcluded(); |
||
| 137 | $aProperties = $xMetadata->getProperties(); |
||
| 138 | $aExcluded = $xMetadata->getExceptMethods(); |
||
|
0 ignored issues
–
show
|
|||
| 139 | |||
| 140 | $this->assertFalse($bExcluded); |
||
| 141 | |||
| 142 | $this->assertCount(1, $aProperties); |
||
| 143 | $this->assertArrayHasKey('*', $aProperties); |
||
| 144 | $this->assertCount(3, $aProperties['*']['__di']); |
||
| 145 | $this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['*']['__di']['colorService3']); |
||
| 146 | $this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService3']); |
||
| 147 | $this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['*']['__di']['textService3']); |
||
| 148 | } |
||
| 149 | |||
| 150 | public function testContainerAttributeErrorDiAttr() |
||
| 151 | { |
||
| 152 | $this->expectException(SetupException::class); |
||
| 153 | $this->getAttributes(PropertyAttribute::class, [], ['errorDiAttr']); |
||
| 154 | } |
||
| 155 | |||
| 156 | public function testContainerAttributeErrorTwoDi() |
||
| 157 | { |
||
| 158 | $this->expectException(SetupException::class); |
||
| 159 | $this->getAttributes(PropertyAttribute::class, [], ['errorTwoDi']); |
||
| 160 | } |
||
| 161 | |||
| 162 | public function testContainerAttributeErrorDiClass() |
||
| 163 | { |
||
| 164 | $this->expectException(SetupException::class); |
||
| 165 | $this->getAttributes(PropertyAttribute::class, ['errorDiClass']); |
||
| 166 | } |
||
| 167 | } |
||
| 168 |
If you suppress an error, we recommend checking for the error condition explicitly: