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

ActionAssertions::assertHasAction()   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 2
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\Traits;
4
5
use Illuminate\Http\Request;
6
use JoshGaber\NovaUnit\Constraints\ArrayHasInstanceOf;
7
use JoshGaber\NovaUnit\Constraints\HasValidFields;
8
use PHPUnit\Framework\Assert as PHPUnit;
9
10
trait ActionAssertions
11
{
12
    /**
13
     * Asserts that this component has the specified field.
14
     *
15
     * @param string $action The class path of the Action
16
     * @param string $message
17
     * @return $this
18
     */
19 2
    public function assertHasAction(string $action, string $message = ''): self
20
    {
21 2
        PHPUnit::assertThat(
22 2
            $this->component->actions(Request::createFromGlobals()),
23 2
            new ArrayHasInstanceOf($action),
24 2
            $message
25
        );
26
27 1
        return $this;
28
    }
29
30
    /**
31
     * Asserts that this component does not have the specified field.
32
     *
33
     * @param string $action The class path of the Action
34
     * @param string $message
35
     * @return $this
36
     */
37 2
    public function assertActionMissing(string $action, string $message = ''): self
38
    {
39 2
        PHPUnit::assertThat(
40 2
            $this->component->actions(Request::createFromGlobals()),
41 2
            PHPUnit::logicalNot(new ArrayHasInstanceOf($action)),
42 2
            $message
43
        );
44
45 1
        return $this;
46
    }
47
48
    /**
49
     * Asserts that this component has no Actions specified.
50
     *
51
     * @param string $message
52
     * @return $this
53
     */
54 2
    public function assertHasNoActions(string $message = ''): self
55
    {
56 2
        PHPUnit::assertCount(0, $this->component->fields(Request::createFromGlobals()), $message);
57
58 1
        return $this;
59
    }
60
61
    /**
62
     * Asserts that all actions on this component are valid Actions.
63
     *
64
     * @param string $message
65
     * @return $this
66
     */
67 3
    public function assertHasValidActions(string $message = ''): self
68
    {
69 3
        PHPUnit::assertThat(
70 3
            $this->component->fields(Request::createFromGlobals()),
71 3
            new HasValidFields(),
72 3
            $message
73
        );
74
75 1
        return $this;
76
    }
77
}
78