NavbarTest::testDecorateWithDoubleInit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\PropellerAdmin\Decorator\Navigation;
6
7
use AbterPhp\Framework\Constant\Html5;
8
use AbterPhp\Framework\Html\Component;
9
use AbterPhp\Framework\Navigation\Navigation;
10
use Opulence\Routing\Urls\UrlGenerator;
11
use PHPUnit\Framework\MockObject\MockObject;
12
use PHPUnit\Framework\TestCase;
13
14
class NavbarTest extends TestCase
15
{
16
    /** @var Navbar - System Under Test */
17
    protected $sut;
18
19
    /** @var UrlGenerator|MockObject */
20
    protected $urlGeneratorMock;
21
22
    public function setUp(): void
23
    {
24
        $this->urlGeneratorMock = $this->getMockBuilder(UrlGenerator::class)
25
            ->disableOriginalConstructor()
26
            ->onlyMethods(['createFromName'])
27
            ->getMock();
28
29
        $this->sut = (new Navbar($this->urlGeneratorMock))->init();
30
31
        parent::setUp();
32
    }
33
34
    public function testDecorateWithEmptyComponents()
35
    {
36
        $this->sut->decorate([]);
37
38
        $this->assertTrue(true, 'No error was found.');
39
    }
40
41
    public function testDecorateNonMatchingComponents()
42
    {
43
        $this->sut->decorate([new Component()]);
44
45
        $this->assertTrue(true, 'No error was found.');
46
    }
47
48
    public function testDecorateWithDoubleInit()
49
    {
50
        $this->sut->init();
51
        $this->sut->decorate([new Component()]);
52
53
        $this->testDecorateNonMatchingComponents();
54
    }
55
56
    public function testDecorateNavbar()
57
    {
58
        $navbar = new Navigation([Navigation::INTENT_NAVBAR]);
59
60
        $this->sut->decorate([$navbar]);
61
62
        $this->assertStringContainsString(Navbar::NAVBAR_CLASS, $navbar->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $navbar->getAttribute(Ab...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

62
        $this->assertStringContainsString(Navbar::NAVBAR_CLASS, /** @scrutinizer ignore-type */ $navbar->getAttribute(Html5::ATTR_CLASS));
Loading history...
63
        $this->assertCount(1, $navbar->getNodes());
64
    }
65
}
66