Passed
Push — master ( 691bb3...d5f7c6 )
by Josh
04:18
created

NovaResourceTest::testNovaResource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace NovaUnit\Resources;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Laravel\Nova\Resource;
7
8
trait NovaResourceTest
9
{
10
    /**
11
     * Initialize the Nova Resource mock.
12
     *
13
     * @param string $class The class path of the Resource
14
     * @param Model $model The object to apply to this Resource
15
     * @return MockResource The Resource mock instance
16
     * @throws InvalidNovaResourceException If the supplied action class is not a Nova Resource
17
     */
18 2
    public static function novaResource(string $class, Model $model): MockResource
19
    {
20 2
        if (! \is_subclass_of($class, Resource::class)) {
21 1
            throw new InvalidNovaResourceException();
22
        }
23
24 1
        return new MockResource(new $class($model));
25
    }
26
}
27