Passed
Pull Request — main (#53)
by
unknown
12:45
created

MockAction::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
use Laravel\Nova\Http\Requests\NovaRequest;
12
13
class MockAction extends MockComponent
14
{
15
    use FieldAssertions;
16
17
    /**
18
     * Dispatches the Action, and returns a test handler for the Action response.
19
     *
20
     * @param  array  $fields  A set of action fields send to the Action, as a key-value array
21
     * @param  Model|Model[]|Collection  $models  A set of models sent to the Action
22
     * @return MockActionResponse A mock class for testing Nova Action responses
23
     */
24 1
    public function handle(array $fields, $models): MockActionResponse
25
    {
26 1
        return new MockActionResponse(
27 1
            $this->component->handle(
28 1
                new ActionFields(collect($fields), collect()),
29 1
                $models instanceof Collection ? $models : collect(Arr::wrap($models))
30 1
            )
31 1
        );
32
    }
33
34 1
    public function getFields(): array
35
    {
36 1
        return $this->component->fields(NovaRequest::createFromGlobals());
37
    }
38
}
39