Passed
Push — main ( 4567d4...1bb836 )
by Sammy
07:03
created

ElementTest::testCanBeUsedAsString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
use PHPUnit\Framework\TestCase;
6
use HexMakina\Marker\Element;
7
8
final class ElementTest extends TestCase
9
{
10
    public function testCanBeCreatedFromValidTagName(): void
11
    {
12
        $this->assertInstanceOf(
13
            Element::class,
14
            new Element('div')
15
        );
16
    }
17
18
    public function testCanBeUsedAsString(): void
19
    {
20
        $this->assertEquals(
21
            '<div>test</div>',
22
            Element::div('test')->__toString()
0 ignored issues
show
Bug introduced by
The method div() does not exist on HexMakina\Marker\Element. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

22
            Element::/** @scrutinizer ignore-call */ 
23
                     div('test')->__toString()
Loading history...
23
        );
24
    }
25
26
    public function testVoidElement(): void
27
    {
28
        $this->assertEquals(
29
            '<hr/>',
30
            Element::hr()->__toString()
0 ignored issues
show
Bug introduced by
The method hr() does not exist on HexMakina\Marker\Element. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

30
            Element::/** @scrutinizer ignore-call */ 
31
                     hr()->__toString()
Loading history...
31
        );
32
    }
33
34
    public function testVoidElementWithAttribute(): void
35
    {
36
        $this->assertEquals(
37
            '<img src="test.jpg"/>',
38
            Element::img(null, ['src' => 'test.jpg'])->__toString()
0 ignored issues
show
Bug introduced by
The method img() does not exist on HexMakina\Marker\Element. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

38
            Element::/** @scrutinizer ignore-call */ 
39
                     img(null, ['src' => 'test.jpg'])->__toString()
Loading history...
39
        );
40
41
        $this->assertEquals(
42
            '<img src="test.jpg"/>',
43
            (new Element('img', null, ['src' => 'test.jpg']))->__toString()
44
        );
45
    }
46
47
    public function testCanHaveStringClassAttribute(): void
48
    {
49
        $element = new Element('div', 'with class', ['class' => 'test']);
50
51
        $this->assertEquals(
52
            '<div class="test">with class</div>',
53
            $element->__toString()
54
        );
55
    }
56
57
    public function testCanHaveArrayClassAttribute(): void
58
    {
59
        $element = new Element('div', 'Hello, World!', ['class' => ['foo', 'bar']]);
60
61
        $this->assertEquals(
62
            '<div class="foo bar">Hello, World!</div>',
63
            $element->__toString()
64
        );
65
    }
66
}
67