From 00a411b18f4fce59cd34d14a9736bd1790c46b78 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Sun, 19 Apr 2020 15:42:31 +0200 Subject: [PATCH] add json rule to json columns --- src/Translators/Rules.php | 8 ++++++-- tests/Feature/Translators/RulesTest.php | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Translators/Rules.php b/src/Translators/Rules.php index 0e2dca87..350385d7 100644 --- a/src/Translators/Rules.php +++ b/src/Translators/Rules.php @@ -2,8 +2,8 @@ namespace Blueprint\Translators; -use Blueprint\Models\Column; use Illuminate\Support\Str; +use Blueprint\Models\Column; class Rules { @@ -36,7 +36,7 @@ public static function fromColumn(string $context, Column $column) 'unsignedInteger', 'unsignedMediumInteger', 'unsignedSmallInteger', - 'unsignedTinyInteger' + 'unsignedTinyInteger', ])) { array_push($rules, 'integer'); @@ -45,6 +45,10 @@ public static function fromColumn(string $context, Column $column) } } + if (in_array($column->dataType(), ['json'])) { + array_push($rules, 'json'); + } + if (in_array($column->dataType(), [ 'decimal', 'double', diff --git a/tests/Feature/Translators/RulesTest.php b/tests/Feature/Translators/RulesTest.php index 2971dbbc..bb4f96ff 100644 --- a/tests/Feature/Translators/RulesTest.php +++ b/tests/Feature/Translators/RulesTest.php @@ -2,9 +2,9 @@ namespace Tests\Feature\Translators; +use Tests\TestCase; use Blueprint\Models\Column; use Blueprint\Translators\Rules; -use Tests\TestCase; /** * @see Rules @@ -158,12 +158,22 @@ public function forColumn_return_exists_rule_for_the_unique_modifier() $this->assertContains('unique:connection.table,column', Rules::fromColumn('connection.table', $column)); } + /** + * @test + */ + public function forColumn_return_json_rule_for_the_json_type() + { + $column = new Column('column', 'json'); + + $this->assertContains('json', Rules::fromColumn('context', $column)); + } + public function stringDataTypesProvider() { return [ ['string'], ['char'], - ['text'] + ['text'], ]; } @@ -212,7 +222,7 @@ public function relationshipColumnProvider() return [ ['test_id', 'tests'], ['user_id', 'users'], - ['sheep_id', 'sheep'] + ['sheep_id', 'sheep'], ]; } }