Passed
Push — main ( 27211a...7f530d )
by Thierry
03:53
created

testNodeComponentExportBaseMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.9666
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\NodeComponent;
8
use Jaxon\Attributes\Tests\Attr\Ajax\Component\NodeBaseComponent;
9
use Jaxon\Attributes\Tests\Attr\Ajax\Component\PageComponent;
10
use Jaxon\Exception\SetupException;
11
use PHPUnit\Framework\TestCase;
12
13
use ReflectionClass;
14
use function Jaxon\Attributes\_register;
15
use function Jaxon\jaxon;
16
17
class ComponentTest extends TestCase
18
{
19
    use AttributeTrait;
20
21
    /**
22
     * @var string
23
     */
24
    private $sCacheDir;
25
26
    /**
27
     * @throws SetupException
28
     */
29
    public function setUp(): void
30
    {
31
        $this->sCacheDir = __DIR__ . '/../cache';
32
        @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

32
        /** @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...
33
34
        jaxon()->di()->getPluginManager()->registerPlugins();
35
        _register();
36
37
        jaxon()->di()->val('jaxon_attributes_cache_dir', $this->sCacheDir);
38
    }
39
40
    /**
41
     * @throws SetupException
42
     */
43
    public function tearDown(): void
44
    {
45
        jaxon()->reset();
46
        parent::tearDown();
47
    }
48
49
    /**
50
     * @throws SetupException
51
     */
52
    public function testNodeComponentExportMethods()
53
    {
54
        $xMetadata = $this->getAttributes(NodeComponent::class,
55
            ['item', 'html', 'render', 'clear', 'visible'], []);
56
        $bExcluded = $xMetadata->isExcluded();
57
        $aExcluded = $xMetadata->getExceptMethods();
58
        $aBaseMethods = $xMetadata->getExportBaseMethods();
59
        $aOnlyMethods = $xMetadata->getExportOnlyMethods();
60
61
        $this->assertFalse($bExcluded);
62
        $this->assertCount(0, $aExcluded);
63
        $this->assertCount(0, $aBaseMethods);
64
        $this->assertCount(0, $aOnlyMethods);
65
    }
66
67
    /**
68
     * @throws SetupException
69
     */
70
    public function testPageComponentExportMethods()
71
    {
72
        $xMetadata = $this->getAttributes(PageComponent::class,
73
            ['item', 'html', 'render', 'clear', 'visible'], []);
74
        $bExcluded = $xMetadata->isExcluded();
75
        $aExcluded = $xMetadata->getExceptMethods();
76
        $aBaseMethods = $xMetadata->getExportBaseMethods();
77
        $aOnlyMethods = $xMetadata->getExportOnlyMethods();
78
79
        $this->assertFalse($bExcluded);
80
        $this->assertCount(0, $aExcluded);
81
        $this->assertCount(0, $aBaseMethods);
82
        $this->assertCount(0, $aOnlyMethods);
83
    }
84
85
    /**
86
     * @throws SetupException
87
     */
88
    public function testFuncComponentExportMethods()
89
    {
90
        $xMetadata = $this->getAttributes(FuncComponent::class,
91
            ['paginator'], []);
92
        $bExcluded = $xMetadata->isExcluded();
93
        $aExcluded = $xMetadata->getExceptMethods();
94
        $aBaseMethods = $xMetadata->getExportBaseMethods();
95
        $aOnlyMethods = $xMetadata->getExportOnlyMethods();
96
97
        $this->assertFalse($bExcluded);
98
        $this->assertCount(0, $aExcluded);
99
        $this->assertCount(0, $aBaseMethods);
100
        $this->assertCount(0, $aOnlyMethods);
101
    }
102
103
    /**
104
     * @throws SetupException
105
     */
106
    public function testNodeComponentExportBaseMethods()
107
    {
108
        // The attribute exports the 'html' and 'render' methods,
109
        // but only the 'render' method shall be exported.
110
        $xClass = new ReflectionClass(NodeBaseComponent::class);
111
        $aMethods = ['item', 'html', 'render', 'clear', 'visible'];
112
        $xMetadata = $this->getAttributes($xClass, $aMethods, []);
113
        $aBaseMethods = $xMetadata->getExportBaseMethods();
114
115
        // The 'html' and 'render' methods are returned.
116
        $this->assertCount(2, $aBaseMethods);
117
118
        $xOptions = $this->getOptions($xClass);
119
        $aPublicMethods = $xOptions->getPublicMethods();
120
121
        // Only the 'render' method is returned.
122
        $this->assertCount(1, $aPublicMethods);
123
        $this->assertEquals('render', $aPublicMethods[0]);
124
    }
125
126
    // public function testContainerAttributeErrorTwoDi()
127
    // {
128
    //     $this->expectException(SetupException::class);
129
    //     $this->getAttributes(PropertyAttribute::class, [], ['errorTwoDi']);
130
    // }
131
132
    // public function testContainerAttributeErrorDiClass()
133
    // {
134
    //     $this->expectException(SetupException::class);
135
    //     $this->getAttributes(PropertyAttribute::class, ['errorDiClass']);
136
    // }
137
}
138