Passed
Push — master ( 48a45a...d91d3c )
by Caen
04:02
created

TestsBladeViews   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 6
c 6
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testViewData() 0 3 1
A test() 0 9 2
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
10
/**
11
 * Provides a more fluent way to test Blade views.
12
 */
13
trait TestsBladeViews
14
{
15
    /**
16
     * Test a Blade view.
17
     */
18
    protected function test(string|View $view, $data = []): TestView
19
    {
20
        $data = array_merge($this->testViewData(), $data);
21
22
        if ($view instanceof View) {
23
            return new TestView($view->with($data));
24
        }
25
26
        return new TestView(view($view, $data));
27
    }
28
29
    /**
30
     * Define any view data to pass to all views in the test.
31
     */
32
    protected function testViewData(): array
33
    {
34
        return [];
35
    }
36
}
37