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

IsActionResponseType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A toString() 0 3 1
A matches() 0 9 1
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