Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Translators/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
14 changes: 12 additions & 2 deletions tests/Feature/Translators/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');

Expand All @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/form-requests/certificate-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function rules()
'reference' => ['required', 'string'],
'document' => ['required', 'string'],
'expiry_date' => ['required', 'date'],
'remarks' => ['string'],
'remarks' => ['nullable', 'string'],
];
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/form-requests/certificate-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function rules()
'reference' => ['required', 'string'],
'document' => ['required', 'string'],
'expiry_date' => ['required', 'date'],
'remarks' => ['string'],
'remarks' => ['nullable', 'string'],
];
}
}