Skip to content

Commit 5ba6c44

Browse files
Explicitly set nullable validation rule (#581)
1 parent 54c47a7 commit 5ba6c44

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/Translators/Rules.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public static function fromColumn(string $context, Column $column)
2929
{
3030
$rules = [];
3131

32-
if (!in_array('nullable', $column->modifiers())) {
33-
array_push($rules, 'required');
34-
}
32+
array_push($rules, in_array('nullable', $column->modifiers()) ? 'nullable' : 'required');
3533

3634
// hack for tests...
3735
if (in_array($column->dataType(), ['string', 'char', 'text', 'longText', 'fullText'])) {

tests/Feature/Translators/RulesTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public function forColumn_returns_required_rule_by_default()
2121
$this->assertEquals(['required'], Rules::fromColumn('context', $column));
2222
}
2323

24+
/**
25+
* @test
26+
*/
27+
public function forColumn_returns_nullable_rule()
28+
{
29+
$column = new Column('test', 'string', ['nullable']);
30+
31+
$this->assertEquals(['nullable', 'string'], Rules::fromColumn('context', $column));
32+
}
33+
2434
/**
2535
* @test
2636
* @dataProvider stringDataTypesProvider
@@ -201,7 +211,7 @@ public function forColumn_does_not_return_between_rule_for_decimal_without_preci
201211
/**
202212
* @test
203213
*/
204-
public function forColumn_does_not_return_between_rule_for_unsigned_decimal_without_precion_and_scale()
214+
public function forColumn_does_not_return_between_rule_for_unsigned_decimal_without_precision_and_scale()
205215
{
206216
$unsignedBeforeDecimalColumn = new Column('column', 'unsigned decimal');
207217

@@ -216,7 +226,7 @@ public function forColumn_does_not_return_between_rule_for_unsigned_decimal_with
216226
* @test
217227
* @dataProvider noBetweenRuleDataProvider
218228
*/
219-
public function forColumn_does_not_return_between_rule_for_double_without_precion_and_scale($column)
229+
public function forColumn_does_not_return_between_rule_for_double_without_precision_and_scale($column)
220230
{
221231
$this->assertNotContains('between', Rules::fromColumn('context', $column));
222232
}

tests/fixtures/form-requests/certificate-store.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function rules()
2929
'reference' => ['required', 'string'],
3030
'document' => ['required', 'string'],
3131
'expiry_date' => ['required', 'date'],
32-
'remarks' => ['string'],
32+
'remarks' => ['nullable', 'string'],
3333
];
3434
}
3535
}

tests/fixtures/form-requests/certificate-update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function rules()
2929
'reference' => ['required', 'string'],
3030
'document' => ['required', 'string'],
3131
'expiry_date' => ['required', 'date'],
32-
'remarks' => ['string'],
32+
'remarks' => ['nullable', 'string'],
3333
];
3434
}
3535
}

0 commit comments

Comments
 (0)