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

TestsBladeViews   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 7
c 7
b 0
f 0
dl 0
loc 30
rs 10
wmc 4
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