Passed
Push — master ( 1ec4ca...843f46 )
by Caen
04:01 queued 27s
created

TestView::assertSeeHtmlIgnoringFormatting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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
    protected function trimNewlinesAndIndentation(string $value): string
38
    {
39
        return str_replace(['    ', "\t", "\n", "\r"], '', $value);
40
    }
41
}
42