Passed
Push — master ( 5fa21f...f08728 )
by Caen
03:34 queued 15s
created

HtmlTestingAssertions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 7
c 4
b 0
f 0
dl 0
loc 32
rs 10
wmc 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Testing\Support\HtmlTesting;
6
7
use Illuminate\Testing\Assert as PHPUnit;
8
9
trait HtmlTestingAssertions
10
{
11
    public function complete(): void
12
    {
13
        // Just an empty helper so we get easier Git diffs when adding new assertions.
14
    }
15
16
    public function assertSee(string $value): static
17
    {
18
        return $this->doAssert(fn () => PHPUnit::assertStringContainsString($value, $this->html, "The string '$value' was not found in the HTML."));
19
    }
20
21
    public function assertDontSee(string $value): static
22
    {
23
        return $this->doAssert(fn () => PHPUnit::assertStringNotContainsString($value, $this->html, "The string '$value' was found in the HTML."));
24
    }
25
26
    public function assertSeeEscaped(string $value): static
27
    {
28
        return $this->doAssert(fn () => PHPUnit::assertStringContainsString(e($value), $this->html, "The escaped string '$value' was not found in the HTML."));
29
    }
30
31
    public function assertDontSeeEscaped(string $value): static
32
    {
33
        return $this->doAssert(fn () => PHPUnit::assertStringNotContainsString(e($value), $this->html, "The escaped string '$value' was found in the HTML."));
34
    }
35
36
    protected function doAssert(callable $assertion): static
37
    {
38
        $assertion();
39
40
        return $this;
41
    }
42
}
43