Passed
Push — master ( 9a2ed4...0d5fd3 )
by Caen
03:42 queued 18s
created

TestView   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 11
c 4
b 0
f 0
dl 0
loc 55
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A assertSeeHtmlIgnoringFormatting() 0 5 1
A assertSeeHtml() 0 7 2
A assertTextIs() 0 5 1
A trimNewlinesAndIndentation() 0 3 1
A assertAttributeIs() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Testing\Support;
6
7
use Illuminate\Testing\Assert as PHPUnit;
8
9
class TestView extends \Illuminate\Testing\TestView
10
{
11
    /**
12
     * Assert that the given HTML is contained within the view.
13
     *
14
     * @return $this
15
     */
16
    public function assertSeeHtml(string $value, bool $ignoreFormatting = false): static
17
    {
18
        if ($ignoreFormatting) {
19
            return $this->assertSeeHtmlIgnoringFormatting($value);
20
        }
21
22
        return $this->assertSee($value, false);
23
    }
24
25
    /**
26
     * Assert that the given HTML is contained within the view text, ignoring whitespace and newlines.
27
     *
28
     * @return $this
29
     */
30
    public function assertSeeHtmlIgnoringFormatting(string $value): static
31
    {
32
        PHPUnit::assertStringContainsString($this->trimNewlinesAndIndentation($value), $this->trimNewlinesAndIndentation($this->rendered));
33
34
        return $this;
35
    }
36
37
    /**
38
     * Assert that the HTML attribute value is contained within the view.
39
     *
40
     * @return $this
41
     */
42
    public function assertAttributeIs(string $attributeName, string $expectedValue): static
43
    {
44
        PHPUnit::assertStringContainsString($attributeName.'="'.$expectedValue.'"', $this->rendered);
45
46
        return $this;
47
    }
48
49
    /**
50
     * Assert that the given text is equals the view's text content.
51
     *
52
     * @return $this
53
     */
54
    public function assertTextIs(string $value): static
55
    {
56
        PHPUnit::assertSame($value, strip_tags($this->rendered));
57
58
        return $this;
59
    }
60
61
    protected function trimNewlinesAndIndentation(string $value): string
62
    {
63
        return str_replace(['    ', "\t", "\n", "\r"], '', $value);
64
    }
65
}
66