Passed
Push — master ( 5153a0...c7b3db )
by Josh
03:56
created

NovaResourceTest::novaResource()   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 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JoshGaber\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