Completed
Pull Request — develop (#8)
by Josh
09:39
created

IsActionResponseType::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JoshGaber\NovaUnit\Constraints;
4
5
use Laravel\Nova\Actions\Action;
6
use PHPUnit\Framework\Constraint\Constraint;
7
8
class IsActionResponseType extends Constraint
9
{
10
    private $actionType;
11
12 14
    public function __construct($actionType)
13
    {
14 14
        $this->actionType = $actionType;
15 14
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 7
    public function toString(): string
21
    {
22 7
        return \sprintf('matches the "%s" Action response', $this->actionType);
23
    }
24
25 14
    public function matches($response): bool
26
    {
27 14
        $structure = \array_keys(\call_user_func([Action::class, $this->actionType], 'param 1', 'param 2'));
28 14
        $responseKeys = \array_keys($response);
29
30 14
        \sort($structure);
31 14
        \sort($responseKeys);
32
33 14
        return $structure === $responseKeys;
34
    }
35
}
36