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\Component\FuncComponent; |
||
| 7 | use Jaxon\Attributes\Tests\Attr\Ajax\Component\ExportErrorComponent; |
||
| 8 | use Jaxon\Attributes\Tests\Attr\Ajax\Component\NodeComponent; |
||
| 9 | use Jaxon\Attributes\Tests\Attr\Ajax\Component\NodeBaseComponent; |
||
| 10 | use Jaxon\Attributes\Tests\Attr\Ajax\Component\PageComponent; |
||
| 11 | use Jaxon\Exception\SetupException; |
||
| 12 | use PHPUnit\Framework\TestCase; |
||
| 13 | |||
| 14 | use ReflectionClass; |
||
| 15 | use function Jaxon\Attributes\_register; |
||
| 16 | use function Jaxon\jaxon; |
||
| 17 | |||
| 18 | class ComponentTest 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 = __DIR__ . '/../cache'; |
||
| 33 | @mkdir($this->sCacheDir); |
||
|
0 ignored issues
–
show
|
|||
| 34 | |||
| 35 | jaxon()->di()->getPluginManager()->registerPlugins(); |
||
| 36 | _register(); |
||
| 37 | |||
| 38 | jaxon()->di()->val('jaxon_attributes_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 | |||
| 50 | /** |
||
| 51 | * @throws SetupException |
||
| 52 | */ |
||
| 53 | public function testNodeComponentExportMethods() |
||
| 54 | { |
||
| 55 | $xMetadata = $this->getAttributes(NodeComponent::class, |
||
| 56 | ['item', 'html', 'render', 'clear', 'visible'], []); |
||
| 57 | $bExcluded = $xMetadata->isExcluded(); |
||
| 58 | $aExcluded = $xMetadata->getExceptMethods(); |
||
| 59 | $aBaseMethods = $xMetadata->getExportBaseMethods(); |
||
| 60 | $aOnlyMethods = $xMetadata->getExportOnlyMethods(); |
||
| 61 | |||
| 62 | $this->assertFalse($bExcluded); |
||
| 63 | $this->assertCount(0, $aExcluded); |
||
| 64 | $this->assertCount(0, $aBaseMethods); |
||
| 65 | $this->assertCount(0, $aOnlyMethods); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @throws SetupException |
||
| 70 | */ |
||
| 71 | public function testPageComponentExportMethods() |
||
| 72 | { |
||
| 73 | $xMetadata = $this->getAttributes(PageComponent::class, |
||
| 74 | ['item', 'html', 'render', 'clear', 'visible'], []); |
||
| 75 | $bExcluded = $xMetadata->isExcluded(); |
||
| 76 | $aExcluded = $xMetadata->getExceptMethods(); |
||
| 77 | $aBaseMethods = $xMetadata->getExportBaseMethods(); |
||
| 78 | $aOnlyMethods = $xMetadata->getExportOnlyMethods(); |
||
| 79 | |||
| 80 | $this->assertFalse($bExcluded); |
||
| 81 | $this->assertCount(0, $aExcluded); |
||
| 82 | $this->assertCount(0, $aBaseMethods); |
||
| 83 | $this->assertCount(0, $aOnlyMethods); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @throws SetupException |
||
| 88 | */ |
||
| 89 | public function testFuncComponentExportMethods() |
||
| 90 | { |
||
| 91 | $xMetadata = $this->getAttributes(FuncComponent::class, |
||
| 92 | ['paginator'], []); |
||
| 93 | $bExcluded = $xMetadata->isExcluded(); |
||
| 94 | $aExcluded = $xMetadata->getExceptMethods(); |
||
| 95 | $aBaseMethods = $xMetadata->getExportBaseMethods(); |
||
| 96 | $aOnlyMethods = $xMetadata->getExportOnlyMethods(); |
||
| 97 | |||
| 98 | $this->assertFalse($bExcluded); |
||
| 99 | $this->assertCount(0, $aExcluded); |
||
| 100 | $this->assertCount(0, $aBaseMethods); |
||
| 101 | $this->assertCount(0, $aOnlyMethods); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @throws SetupException |
||
| 106 | */ |
||
| 107 | public function testNodeComponentExportBaseMethods() |
||
| 108 | { |
||
| 109 | // The attribute exports the 'html' and 'render' methods, |
||
| 110 | // but only the 'render' method shall be exported. |
||
| 111 | $xClass = new ReflectionClass(NodeBaseComponent::class); |
||
| 112 | $aMethods = ['item', 'html', 'render', 'clear', 'visible']; |
||
| 113 | $xMetadata = $this->getAttributes($xClass, $aMethods, []); |
||
| 114 | $aBaseMethods = $xMetadata->getExportBaseMethods(); |
||
| 115 | |||
| 116 | // The 'html' and 'render' methods are returned. |
||
| 117 | $this->assertCount(2, $aBaseMethods); |
||
| 118 | |||
| 119 | $xOptions = $this->getOptions($xClass); |
||
| 120 | $aPublicMethods = $xOptions->getPublicMethods(); |
||
| 121 | |||
| 122 | // Only the 'render' method is returned. |
||
| 123 | $this->assertCount(1, $aPublicMethods); |
||
| 124 | $this->assertEquals('render', $aPublicMethods[0]); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function testAttributeExportError() |
||
| 128 | { |
||
| 129 | $this->expectException(SetupException::class); |
||
| 130 | $xClass = new ReflectionClass(ExportErrorComponent::class); |
||
| 131 | $this->getOptions($xClass); |
||
| 132 | } |
||
| 133 | |||
| 134 | // public function testContainerAttributeErrorDiClass() |
||
| 135 | // { |
||
| 136 | // $this->expectException(SetupException::class); |
||
| 137 | // $this->getAttributes(PropertyAttribute::class, ['errorDiClass']); |
||
| 138 | // } |
||
| 139 | } |
||
| 140 |
If you suppress an error, we recommend checking for the error condition explicitly: