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

FieldAssertions::assertHasValidFields()   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\Traits;
4
5
use Illuminate\Http\Request;
6
use JoshGaber\NovaUnit\Constraints\HasField;
7
use JoshGaber\NovaUnit\Constraints\HasValidFields;
8
use PHPUnit\Framework\Assert as PHPUnit;
9
10
trait FieldAssertions
11
{
12
    /**
13
     * Checks that this Nova component has a field with the same name or attribute.
14
     *
15
     * @param string $field The name or attribute of the field
16
     * @param string $message
17
     * @return $this
18
     */
19 4
    public function assertHasField(string $field, string $message = ''): self
20
    {
21 4
        PHPUnit::assertThat(
22 4
            $this->component->fields(Request::createFromGlobals()),
23 4
            new HasField($field),
24 4
            $message
25
        );
26
27 2
        return $this;
28
    }
29
30
    /**
31
     * Checks that no field on this Nova component has a name or attribute matching
32
     * the given parameter.
33
     *
34
     * @param string $field
35
     * @param string $message
36
     * @return $this
37
     */
38 4
    public function assertFieldMissing(string $field, string $message = ''): self
39
    {
40 4
        PHPUnit::assertThat(
41 4
            $this->component->fields(Request::createFromGlobals()),
42 4
            PHPUnit::logicalNot(new HasField($field)),
43 4
            $message
44
        );
45
46 2
        return $this;
47
    }
48
49
    /**
50
     * Asserts that this Nova Action has no fields defined.
51
     * @param string $message
52
     * @return $this
53
     */
54 2
    public function assertHasNoFields(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 fields defined on this Nova Action are valid fields.
63
     *
64
     * @param string $message
65
     * @return $this
66
     */
67 3
    public function assertHasValidFields(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