MockAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 17
ccs 5
cts 5
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 2
1
<?php
2
3
namespace JoshGaber\NovaUnit\Actions;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Collection;
8
use JoshGaber\NovaUnit\MockComponent;
9
use JoshGaber\NovaUnit\Traits\FieldAssertions;
10
use Laravel\Nova\Fields\ActionFields;
11
12
class MockAction extends MockComponent
13
{
14
    use FieldAssertions;
15
16
    /**
17
     * Dispatches the Action, and returns a test handler for the Action response.
18
     *
19
     * @param array $fields A set of action fields send to the Action, as a key-value array
20
     * @param Model|Model[]|Collection $models A set of models sent to the Action
21
     * @return MockActionResponse A mock class for testing Nova Action responses
22
     */
23 1
    public function handle(array $fields, $models): MockActionResponse
24
    {
25 1
        return new MockActionResponse(
26 1
            $this->component->handle(
27 1
                new ActionFields(collect($fields), collect()),
28 1
                $models instanceof Collection ? $models : collect(Arr::wrap($models))
29
            )
30
        );
31
    }
32
}
33