diff --git a/src/Translators/Rules.php b/src/Translators/Rules.php index 973e73a2..d38888c4 100644 --- a/src/Translators/Rules.php +++ b/src/Translators/Rules.php @@ -29,9 +29,7 @@ public static function fromColumn(string $context, Column $column) { $rules = []; - if (!in_array('nullable', $column->modifiers())) { - array_push($rules, 'required'); - } + array_push($rules, in_array('nullable', $column->modifiers()) ? 'nullable' : 'required'); // hack for tests... if (in_array($column->dataType(), ['string', 'char', 'text', 'longText', 'fullText'])) { diff --git a/tests/Feature/Translators/RulesTest.php b/tests/Feature/Translators/RulesTest.php index 28b3a4b3..585d2831 100644 --- a/tests/Feature/Translators/RulesTest.php +++ b/tests/Feature/Translators/RulesTest.php @@ -21,6 +21,16 @@ public function forColumn_returns_required_rule_by_default() $this->assertEquals(['required'], Rules::fromColumn('context', $column)); } + /** + * @test + */ + public function forColumn_returns_nullable_rule() + { + $column = new Column('test', 'string', ['nullable']); + + $this->assertEquals(['nullable', 'string'], Rules::fromColumn('context', $column)); + } + /** * @test * @dataProvider stringDataTypesProvider @@ -201,7 +211,7 @@ public function forColumn_does_not_return_between_rule_for_decimal_without_preci /** * @test */ - public function forColumn_does_not_return_between_rule_for_unsigned_decimal_without_precion_and_scale() + public function forColumn_does_not_return_between_rule_for_unsigned_decimal_without_precision_and_scale() { $unsignedBeforeDecimalColumn = new Column('column', 'unsigned decimal'); @@ -216,7 +226,7 @@ public function forColumn_does_not_return_between_rule_for_unsigned_decimal_with * @test * @dataProvider noBetweenRuleDataProvider */ - public function forColumn_does_not_return_between_rule_for_double_without_precion_and_scale($column) + public function forColumn_does_not_return_between_rule_for_double_without_precision_and_scale($column) { $this->assertNotContains('between', Rules::fromColumn('context', $column)); } diff --git a/tests/fixtures/form-requests/certificate-store.php b/tests/fixtures/form-requests/certificate-store.php index dec79684..5b3d7191 100644 --- a/tests/fixtures/form-requests/certificate-store.php +++ b/tests/fixtures/form-requests/certificate-store.php @@ -29,7 +29,7 @@ public function rules() 'reference' => ['required', 'string'], 'document' => ['required', 'string'], 'expiry_date' => ['required', 'date'], - 'remarks' => ['string'], + 'remarks' => ['nullable', 'string'], ]; } } diff --git a/tests/fixtures/form-requests/certificate-update.php b/tests/fixtures/form-requests/certificate-update.php index 34ec8d6d..ea7364f1 100644 --- a/tests/fixtures/form-requests/certificate-update.php +++ b/tests/fixtures/form-requests/certificate-update.php @@ -29,7 +29,7 @@ public function rules() 'reference' => ['required', 'string'], 'document' => ['required', 'string'], 'expiry_date' => ['required', 'date'], - 'remarks' => ['string'], + 'remarks' => ['nullable', 'string'], ]; } }