jaxon-php /
jaxon-mono
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Jaxon\Annotations\Tests\TestAnnotation; |
||||
| 4 | |||||
| 5 | use Jaxon\Annotations\Tests\AnnotationTrait; |
||||
| 6 | use Jaxon\Annotations\Tests\Attr\Ajax\AttrAnnotated; |
||||
| 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 AttrAnnotationTest 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); |
||||
|
0 ignored issues
–
show
|
|||||
| 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); |
||||
|
0 ignored issues
–
show
It seems like you do not handle an error condition for
unlink(). 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
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...
|
|||||
| 51 | } |
||||
| 52 | } |
||||
| 53 | @rmdir($this->sCacheDir); |
||||
|
0 ignored issues
–
show
It seems like you do not handle an error condition for
rmdir(). 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
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...
|
|||||
| 54 | } |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * @throws SetupException |
||||
| 58 | */ |
||||
| 59 | public function testContainerAnnotation() |
||||
| 60 | { |
||||
| 61 | $xMetadata = $this->getAttributes(AttrAnnotated::class, |
||||
| 62 | ['attrVar'], ['colorService', 'fontService', 'textService']); |
||||
| 63 | $bExcluded = $xMetadata->isExcluded(); |
||||
| 64 | $aProperties = $xMetadata->getProperties(); |
||||
| 65 | |||||
| 66 | $this->assertFalse($bExcluded); |
||||
| 67 | |||||
| 68 | $this->assertCount(1, $aProperties); |
||||
| 69 | $this->assertArrayHasKey('attrVar', $aProperties); |
||||
| 70 | $this->assertCount(3, $aProperties['attrVar']['__di']); |
||||
| 71 | $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['attrVar']['__di']['colorService']); |
||||
| 72 | $this->assertEquals('Jaxon\Annotations\Tests\Attr\Ajax\FontService', $aProperties['attrVar']['__di']['fontService']); |
||||
| 73 | $this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['attrVar']['__di']['textService']); |
||||
| 74 | } |
||||
| 75 | |||||
| 76 | /** |
||||
| 77 | * @throws SetupException |
||||
| 78 | */ |
||||
| 79 | public function testContainerDocBlockAnnotation() |
||||
| 80 | { |
||||
| 81 | $xMetadata = $this->getAttributes(AttrAnnotated::class, |
||||
| 82 | ['attrDbVar'], ['colorService', 'fontService', 'textService']); |
||||
| 83 | $bExcluded = $xMetadata->isExcluded(); |
||||
| 84 | $aProperties = $xMetadata->getProperties(); |
||||
| 85 | |||||
| 86 | $this->assertFalse($bExcluded); |
||||
| 87 | |||||
| 88 | $this->assertCount(1, $aProperties); |
||||
| 89 | $this->assertArrayHasKey('attrDbVar', $aProperties); |
||||
| 90 | $this->assertCount(3, $aProperties['attrDbVar']['__di']); |
||||
| 91 | $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['attrDbVar']['__di']['colorService']); |
||||
| 92 | $this->assertEquals('Jaxon\Annotations\Tests\Attr\Ajax\FontService', $aProperties['attrDbVar']['__di']['fontService']); |
||||
| 93 | $this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['attrDbVar']['__di']['textService']); |
||||
| 94 | } |
||||
| 95 | |||||
| 96 | /** |
||||
| 97 | * @throws SetupException |
||||
| 98 | */ |
||||
| 99 | public function testContainerDiAnnotation() |
||||
| 100 | { |
||||
| 101 | $xMetadata = $this->getAttributes(AttrAnnotated::class, |
||||
| 102 | ['attrDi'], ['colorService1', 'fontService1', 'textService1']); |
||||
| 103 | $bExcluded = $xMetadata->isExcluded(); |
||||
| 104 | $aProperties = $xMetadata->getProperties(); |
||||
| 105 | |||||
| 106 | $this->assertFalse($bExcluded); |
||||
| 107 | |||||
| 108 | $this->assertCount(1, $aProperties); |
||||
| 109 | $this->assertArrayHasKey('*', $aProperties); |
||||
| 110 | $this->assertCount(3, $aProperties['*']['__di']); |
||||
| 111 | $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['*']['__di']['colorService1']); |
||||
| 112 | $this->assertEquals('Jaxon\Annotations\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService1']); |
||||
| 113 | $this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['*']['__di']['textService1']); |
||||
| 114 | } |
||||
| 115 | |||||
| 116 | /** |
||||
| 117 | * @throws SetupException |
||||
| 118 | */ |
||||
| 119 | public function testContainerDiAndVarAnnotation() |
||||
| 120 | { |
||||
| 121 | $xMetadata = $this->getAttributes(AttrAnnotated::class, |
||||
| 122 | ['attrDi'], ['colorService2', 'fontService2', 'textService2']); |
||||
| 123 | $bExcluded = $xMetadata->isExcluded(); |
||||
| 124 | $aProperties = $xMetadata->getProperties(); |
||||
| 125 | |||||
| 126 | $this->assertFalse($bExcluded); |
||||
| 127 | |||||
| 128 | $this->assertCount(1, $aProperties); |
||||
| 129 | $this->assertArrayHasKey('*', $aProperties); |
||||
| 130 | $this->assertCount(3, $aProperties['*']['__di']); |
||||
| 131 | $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['*']['__di']['colorService2']); |
||||
| 132 | $this->assertEquals('Jaxon\Annotations\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService2']); |
||||
| 133 | $this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['*']['__di']['textService2']); |
||||
| 134 | } |
||||
| 135 | |||||
| 136 | /** |
||||
| 137 | * @throws SetupException |
||||
| 138 | */ |
||||
| 139 | public function testContainerPropAnnotation() |
||||
| 140 | { |
||||
| 141 | $xMetadata = $this->getAttributes(AttrAnnotated::class, |
||||
| 142 | ['attrDi'], ['colorService3', 'fontService3', 'textService3']); |
||||
| 143 | $bExcluded = $xMetadata->isExcluded(); |
||||
| 144 | $aProperties = $xMetadata->getProperties(); |
||||
| 145 | |||||
| 146 | $this->assertFalse($bExcluded); |
||||
| 147 | |||||
| 148 | $this->assertCount(1, $aProperties); |
||||
| 149 | $this->assertArrayHasKey('*', $aProperties); |
||||
| 150 | $this->assertCount(3, $aProperties['*']['__di']); |
||||
| 151 | $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['*']['__di']['colorService3']); |
||||
| 152 | $this->assertEquals('Jaxon\Annotations\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService3']); |
||||
| 153 | $this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['*']['__di']['textService3']); |
||||
| 154 | } |
||||
| 155 | |||||
| 156 | public function testContainerAnnotationErrorTwoParams() |
||||
| 157 | { |
||||
| 158 | $this->expectException(SetupException::class); |
||||
| 159 | $this->getAttributes(AttrAnnotated::class, [], ['errorTwoParams']); |
||||
| 160 | } |
||||
| 161 | |||||
| 162 | public function testContainerAnnotationErrorDiAttr() |
||||
| 163 | { |
||||
| 164 | $this->expectException(SetupException::class); |
||||
| 165 | $this->getAttributes(AttrAnnotated::class, [], ['errorDiAttr']); |
||||
| 166 | } |
||||
| 167 | |||||
| 168 | public function testContainerAnnotationErrorDiDbAttr() |
||||
| 169 | { |
||||
| 170 | $this->expectException(SetupException::class); |
||||
| 171 | $this->getAttributes(AttrAnnotated::class, [], ['errorDiDbAttr']); |
||||
| 172 | } |
||||
| 173 | |||||
| 174 | public function testContainerAnnotationErrorTwoDi() |
||||
| 175 | { |
||||
| 176 | $this->expectException(SetupException::class); |
||||
| 177 | $this->getAttributes(AttrAnnotated::class, [], ['errorTwoDi']); |
||||
| 178 | } |
||||
| 179 | |||||
| 180 | public function testContainerAnnotationErrorDiClass() |
||||
| 181 | { |
||||
| 182 | $this->expectException(SetupException::class); |
||||
| 183 | $this->getAttributes(AttrAnnotated::class, ['errorDiClass']); |
||||
| 184 | } |
||||
| 185 | |||||
| 186 | public function testContainerAnnotationErrorNoVar() |
||||
| 187 | { |
||||
| 188 | $this->expectException(SetupException::class); |
||||
| 189 | $this->getAttributes(AttrAnnotated::class, ['errorDiNoVar']); |
||||
| 190 | } |
||||
| 191 | |||||
| 192 | public function testContainerAnnotationErrorTwoVars() |
||||
| 193 | { |
||||
| 194 | $this->expectException(SetupException::class); |
||||
| 195 | $this->getAttributes(AttrAnnotated::class, ['errorDiTwoVars']); |
||||
| 196 | } |
||||
| 197 | } |
||||
| 198 |
If you suppress an error, we recommend checking for the error condition explicitly: