Passed
Push — main ( 87fed9...27211a )
by Thierry
04:04
created

ComponentTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testFuncComponentExportMethods() 0 11 1
A tearDown() 0 4 1
A testPageComponentExportMethods() 0 11 1
A testNodeComponentExportMethods() 0 11 1
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\PageComponent;
9
use Jaxon\Exception\SetupException;
10
use PHPUnit\Framework\TestCase;
11
12
use function Jaxon\Attributes\_register;
13
use function Jaxon\jaxon;
14
15
class ComponentTest extends TestCase
16
{
17
    use AttributeTrait;
18
19
    /**
20
     * @var string
21
     */
22
    private $sCacheDir;
23
24
    /**
25
     * @throws SetupException
26
     */
27
    public function setUp(): void
28
    {
29
        $this->sCacheDir = __DIR__ . '/../cache';
30
        @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

30
        /** @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...
31
32
        jaxon()->di()->getPluginManager()->registerPlugins();
33
        _register();
34
35
        jaxon()->di()->val('jaxon_attributes_cache_dir', $this->sCacheDir);
36
    }
37
38
    /**
39
     * @throws SetupException
40
     */
41
    public function tearDown(): void
42
    {
43
        jaxon()->reset();
44
        parent::tearDown();
45
    }
46
47
    /**
48
     * @throws SetupException
49
     */
50
    public function testNodeComponentExportMethods()
51
    {
52
        $xMetadata = $this->getAttributes(NodeComponent::class,
53
            [], ['item', 'html', 'render', 'clear', 'visible']);
54
        $bExcluded = $xMetadata->isExcluded();
55
        $aProperties = $xMetadata->getProperties();
56
        $aProtected = $xMetadata->getProtectedMethods();
57
58
        $this->assertFalse($bExcluded);
59
        $this->assertCount(0, $aProperties);
60
        $this->assertCount(0, $aProtected);
61
    }
62
63
    /**
64
     * @throws SetupException
65
     */
66
    public function testPageComponentExportMethods()
67
    {
68
        $xMetadata = $this->getAttributes(PageComponent::class,
69
            [], ['item', 'html', 'render', 'clear', 'visible']);
70
        $bExcluded = $xMetadata->isExcluded();
71
        $aProperties = $xMetadata->getProperties();
72
        $aProtected = $xMetadata->getProtectedMethods();
73
74
        $this->assertFalse($bExcluded);
75
        $this->assertCount(0, $aProperties);
76
        $this->assertCount(0, $aProtected);
77
    }
78
79
    /**
80
     * @throws SetupException
81
     */
82
    public function testFuncComponentExportMethods()
83
    {
84
        $xMetadata = $this->getAttributes(FuncComponent::class,
85
            [], ['paginator']);
86
        $bExcluded = $xMetadata->isExcluded();
87
        $aProperties = $xMetadata->getProperties();
88
        $aProtected = $xMetadata->getProtectedMethods();
89
90
        $this->assertFalse($bExcluded);
91
        $this->assertCount(0, $aProperties);
92
        $this->assertCount(0, $aProtected);
93
    }
94
95
    // public function testContainerAttributeErrorTwoDi()
96
    // {
97
    //     $this->expectException(SetupException::class);
98
    //     $this->getAttributes(PropertyAttribute::class, [], ['errorTwoDi']);
99
    // }
100
101
    // public function testContainerAttributeErrorDiClass()
102
    // {
103
    //     $this->expectException(SetupException::class);
104
    //     $this->getAttributes(PropertyAttribute::class, ['errorDiClass']);
105
    // }
106
}
107