GeneralTest::testDecorateHiddenComponents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\PropellerAdmin\Decorator;
6
7
use AbterPhp\Framework\Constant\Html5;
8
use AbterPhp\Framework\Html\Component;
9
use PHPUnit\Framework\TestCase;
10
11
class GeneralTest extends TestCase
12
{
13
    /** @var General - System Under Test */
14
    protected $sut;
15
16
    public function setUp(): void
17
    {
18
        $this->sut = (new General())->init();
19
20
        parent::setUp();
21
    }
22
23
    public function testDecorateWithEmptyComponents()
24
    {
25
        $this->sut->decorate([]);
26
27
        $this->assertTrue(true, 'No error was found.');
28
    }
29
30
    public function testDecorateNonMatchingComponents()
31
    {
32
        $this->sut->decorate([new Component()]);
33
34
        $this->assertTrue(true, 'No error was found.');
35
    }
36
37
    public function testDecorateHiddenComponents()
38
    {
39
        $component1 = new Component('a', [Component::INTENT_HIDDEN]);
40
        $component2 = new Component('b', []);
41
        $component3 = new Component('c', [Component::INTENT_HIDDEN]);
42
43
        $this->sut->decorate([$component1, $component2, $component3]);
44
45
        $this->assertTrue($component1->hasAttribute(Html5::ATTR_CLASS));
46
        $this->assertStringContainsString(Component::CLASS_HIDDEN, $component1->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $component1->getAttribut...tant\Html5::ATTR_CLASS) can also be of type null; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $this->assertStringContainsString(Component::CLASS_HIDDEN, /** @scrutinizer ignore-type */ $component1->getAttribute(Html5::ATTR_CLASS));
Loading history...
47
        $this->assertFalse($component2->hasAttribute(Html5::ATTR_CLASS));
48
        $this->assertTrue($component3->hasAttribute(Html5::ATTR_CLASS));
49
        $this->assertStringContainsString(Component::CLASS_HIDDEN, $component3->getAttribute(Html5::ATTR_CLASS));
50
    }
51
52
    public function testDecorateButtons()
53
    {
54
        $component1 = new Component\Button('a');
55
        $component2 = new Component('b');
56
        $component3 = new Component\Button('c');
57
58
        $this->sut->decorate([$component1, $component2, $component3]);
59
60
        $this->assertTrue($component1->hasAttribute(Html5::ATTR_CLASS));
61
        $this->assertStringContainsString(General::BUTTON_CLASS, $component1->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $component1->getAttribut...tant\Html5::ATTR_CLASS) can also be of type null; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        $this->assertStringContainsString(General::BUTTON_CLASS, /** @scrutinizer ignore-type */ $component1->getAttribute(Html5::ATTR_CLASS));
Loading history...
62
        $this->assertFalse($component2->hasAttribute(Html5::ATTR_CLASS));
63
        $this->assertTrue($component3->hasAttribute(Html5::ATTR_CLASS));
64
        $this->assertStringContainsString(General::BUTTON_CLASS, $component3->getAttribute(Html5::ATTR_CLASS));
65
    }
66
67
    public function testDecorateButtonsWithDoubleInit()
68
    {
69
        $this->sut->init();
70
71
        $this->testDecorateButtons();
72
    }
73
}
74