Passed
Push — master ( de4139...96da48 )
by Josh
06:18
created

MockFieldElement::__construct()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace JoshGaber\NovaUnit\Fields;
4
5
use Laravel\Nova\Fields\Field;
6
use PHPUnit\Framework\Assert as PHPUnit;
7
8
class MockFieldElement
9
{
10
    private $field;
11
12 29
    public function __construct(Field $field)
13
    {
14 29
        $this->field = $field;
15 29
    }
16
17
    /**
18
     * Assert that the following rule can be found on the field.
19
     *
20
     * @param string $rule The rule to match this field against
21
     * @param string $message
22
     * @return $this
23
     */
24 2
    public function assertHasRule(string $rule, string $message = ''): self
25
    {
26 2
        PHPUnit::assertContains($rule, $this->field->rules, $message);
27
28 1
        return $this;
29
    }
30
31
    /**
32
     * Assert that the following rule cannot be found on the field.
33
     *
34
     * @param string $rule The rule to match this field against
35
     * @param string $message
36
     * @return $this
37
     */
38 2
    public function assertRuleMissing(string $rule, string $message = ''): self
39
    {
40 2
        PHPUnit::assertNotContains($rule, $this->field->rules, $message);
41
42 1
        return $this;
43
    }
44
45
    /**
46
     * Assert that the field can be shown on the index view.
47
     *
48
     * @param string $message
49
     * @return $this
50
     */
51 2
    public function assertShownOnIndex(string $message = ''): self
52
    {
53 2
        $test = $this->field->showOnIndex;
54 2
        PHPUnit::assertTrue(
55 2
            is_callable($test) ? $test() : $test,
56 2
            $message
57
        );
58
59 1
        return $this;
60
    }
61
62
    /**
63
     * Assert that the field is hidden from the index view.
64
     *
65
     * @param string $message
66
     * @return $this
67
     */
68 2
    public function assertHiddenFromIndex(string $message = ''): self
69
    {
70 2
        $test = $this->field->showOnIndex;
71 2
        PHPUnit::assertFalse(
72 2
            is_callable($test) ? $test() : $test,
73 2
            $message
74
        );
75
76 1
        return $this;
77
    }
78
79
    /**
80
     * Assert that the field can be shown on the detail view.
81
     *
82
     * @param string $message
83
     * @return $this
84
     */
85 2
    public function assertShownOnDetail(string $message = ''): self
86
    {
87 2
        $test = $this->field->showOnDetail;
88 2
        PHPUnit::assertTrue(
89 2
            is_callable($test) ? $test() : $test,
90 2
            $message
91
        );
92
93 1
        return $this;
94
    }
95
96
    /**
97
     * Assert that the field is hidden from the detail view.
98
     *
99
     * @param string $message
100
     * @return $this
101
     */
102 2
    public function assertHiddenFromDetail(string $message = ''): self
103
    {
104 2
        $test = $this->field->showOnDetail;
105 2
        PHPUnit::assertFalse(
106 2
            is_callable($test) ? $test() : $test,
107 2
            $message
108
        );
109
110 1
        return $this;
111
    }
112
113
    /**
114
     * Assert that the field can be shown when creating a new record.
115
     *
116
     * @param string $message
117
     * @return $this
118
     */
119 2
    public function assertShownWhenCreating(string $message = ''): self
120
    {
121 2
        $test = $this->field->showOnCreation;
122 2
        PHPUnit::assertTrue(
123 2
            is_callable($test) ? $test() : $test,
124 2
            $message
125
        );
126
127 1
        return $this;
128
    }
129
130
    /**
131
     * Assert that the field is hidden when creating a new record.
132
     *
133
     * @param string $message
134
     * @return $this
135
     */
136 2
    public function assertHiddenWhenCreating(string $message = ''): self
137
    {
138 2
        $test = $this->field->showOnCreation;
139 2
        PHPUnit::assertFalse(
140 2
            is_callable($test) ? $test() : $test,
141 2
            $message
142
        );
143
144 1
        return $this;
145
    }
146
147
    /**
148
     * Assert that the field can be shown when updating a record.
149
     *
150
     * @param string $message
151
     * @return $this
152
     */
153 2
    public function assertShownWhenUpdating(string $message = ''): self
154
    {
155 2
        $test = $this->field->showOnUpdate;
156 2
        PHPUnit::assertTrue(
157 2
            is_callable($test) ? $test() : $test,
158 2
            $message
159
        );
160
161 1
        return $this;
162
    }
163
164
    /**
165
     * Assert that the field is hidden when updating a record.
166
     *
167
     * @param string $message
168
     * @return $this
169
     */
170 2
    public function assertHiddenWhenUpdating(string $message = ''): self
171
    {
172 2
        $test = $this->field->showOnUpdate;
173 2
        PHPUnit::assertFalse(
174 2
            is_callable($test) ? $test() : $test,
175 2
            $message
176
        );
177
178 1
        return $this;
179
    }
180
181
    /**
182
     * Assert that the field should be set to null if the value is empty.
183
     *
184
     * @param string $message
185
     * @return $this
186
     */
187 2
    public function assertNullable(string $message = ''): self
188
    {
189 2
        PHPUnit::assertTrue($this->field->nullable, $message);
190
191 1
        return $this;
192
    }
193
194
    /**
195
     * Assert that the field should not be set to null if the value is empty.
196
     *
197
     * @param string $message
198
     * @return $this
199
     */
200 2
    public function assertNotNullable(string $message = ''): self
201
    {
202 2
        PHPUnit::assertFalse($this->field->nullable, $message);
203
204 1
        return $this;
205
    }
206
207
    /**
208
     * Assert that records can be sorted by this field.
209
     *
210
     * @param string $message
211
     * @return $this
212
     */
213 2
    public function assertSortable(string $message = ''): self
214
    {
215 2
        PHPUnit::assertTrue($this->field->sortable, $message);
216
217 1
        return $this;
218
    }
219
220
    /**
221
     * Assert that records cannot be sorted by this field.
222
     *
223
     * @param string $message
224
     * @return $this
225
     */
226 2
    public function assertNotSortable(string $message = ''): self
227
    {
228 2
        PHPUnit::assertFalse($this->field->sortable, $message);
229
230 1
        return $this;
231
    }
232
}
233