Passed
Push — master ( eaf66d...5fa21f )
by Caen
13:40 queued 12s
created

TestsBladeViews::html()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Testing;
6
7
use Illuminate\View\View;
8
use Hyde\Testing\Support\TestView;
9
use Hyde\Testing\Support\HtmlTesting\TestableHtmlDocument;
10
11
/**
12
 * Provides a more fluent way to test Blade views.
13
 */
14
trait TestsBladeViews
15
{
16
    /**
17
     * Test a Blade view.
18
     */
19
    protected function test(string|View $view, $data = []): TestView
20
    {
21
        $data = array_merge($this->testViewData(), $data);
22
23
        if ($view instanceof View) {
24
            return new TestView($view->with($data));
25
        }
26
27
        return new TestView(view($view, $data));
28
    }
29
30
    /**
31
     * Create a testable HTML document instance.
32
     */
33
    protected function html(string $html): TestableHtmlDocument
34
    {
35
        return new TestableHtmlDocument($html);
36
    }
37
38
    /**
39
     * Define any view data to pass to all views in the test.
40
     */
41
    protected function testViewData(): array
42
    {
43
        return [];
44
    }
45
}
46