From 67cfc6b01c50545a5f050fa4f88633993e759f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Almeida?= Date: Fri, 13 Aug 2021 19:44:57 +0100 Subject: [PATCH] Added support for `useCurrentOnUpdate` modifier (#493) --- src/Lexers/ModelLexer.php | 1 + tests/Feature/Lexers/ModelLexerTest.php | 4 +++- tests/fixtures/drafts/post.yaml | 3 ++- tests/fixtures/factories/post-configured-laravel8.php | 1 + tests/fixtures/factories/post-configured.php | 1 + tests/fixtures/factories/post-laravel8.php | 1 + tests/fixtures/factories/post.php | 1 + 7 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Lexers/ModelLexer.php b/src/Lexers/ModelLexer.php index dd9f0b0b..baf268f3 100644 --- a/src/Lexers/ModelLexer.php +++ b/src/Lexers/ModelLexer.php @@ -90,6 +90,7 @@ class ModelLexer implements Lexer 'nullable' => 'nullable', 'unsigned' => 'unsigned', 'usecurrent' => 'useCurrent', + 'usecurrentonupdate' => 'useCurrentOnUpdate', 'always' => 'always', 'unique' => 'unique', 'index' => 'index', diff --git a/tests/Feature/Lexers/ModelLexerTest.php b/tests/Feature/Lexers/ModelLexerTest.php index 7b7ba19f..4e9be2a8 100644 --- a/tests/Feature/Lexers/ModelLexerTest.php +++ b/tests/Feature/Lexers/ModelLexerTest.php @@ -226,6 +226,7 @@ public function it_accepts_lowercase_keywords() 'sequence' => 'unsignedbiginteger autoincrement', 'content' => 'longtext', 'saved_at' => 'timestamptz usecurrent', + 'updated_at' => 'timestamptz usecurrent usecurrentOnUpdate', ], ], ]; @@ -241,7 +242,7 @@ public function it_accepts_lowercase_keywords() $this->assertFalse($model->usesSoftDeletes()); $columns = $model->columns(); - $this->assertCount(4, $columns); + $this->assertCount(5, $columns); $this->assertEquals('id', $columns['id']->name()); $this->assertEquals('id', $columns['id']->dataType()); $this->assertEquals([], $columns['id']->attributes()); @@ -258,6 +259,7 @@ public function it_accepts_lowercase_keywords() $this->assertEquals('timestampTz', $columns['saved_at']->dataType()); $this->assertEquals([], $columns['saved_at']->attributes()); $this->assertEquals(['useCurrent'], $columns['saved_at']->modifiers()); + $this->assertEquals(['useCurrent', 'useCurrentOnUpdate'], $columns['updated_at']->modifiers()); } /** diff --git a/tests/fixtures/drafts/post.yaml b/tests/fixtures/drafts/post.yaml index b6fb45ec..eda9189e 100644 --- a/tests/fixtures/drafts/post.yaml +++ b/tests/fixtures/drafts/post.yaml @@ -4,5 +4,6 @@ models: author_id: id author_bio: longtext content: bigtext nullable - published_at: timestamp nullable + published_at: timestamp nullable useCurrent + updated_at: timestamp nullable useCurrent useCurrentOnUpdate word_count: integer unsigned \ No newline at end of file diff --git a/tests/fixtures/factories/post-configured-laravel8.php b/tests/fixtures/factories/post-configured-laravel8.php index 7144d875..fb305a49 100644 --- a/tests/fixtures/factories/post-configured-laravel8.php +++ b/tests/fixtures/factories/post-configured-laravel8.php @@ -29,6 +29,7 @@ public function definition() 'author_bio' => $this->faker->text, 'content' => $this->faker->paragraphs(3, true), 'published_at' => $this->faker->dateTime(), + 'updated_at' => $this->faker->dateTime(), 'word_count' => $this->faker->randomNumber(), ]; } diff --git a/tests/fixtures/factories/post-configured.php b/tests/fixtures/factories/post-configured.php index a49a99ed..e57b3859 100644 --- a/tests/fixtures/factories/post-configured.php +++ b/tests/fixtures/factories/post-configured.php @@ -12,6 +12,7 @@ 'author_bio' => $faker->text, 'content' => $faker->paragraphs(3, true), 'published_at' => $faker->dateTime(), + 'updated_at' => $faker->dateTime(), 'word_count' => $faker->randomNumber(), ]; }); diff --git a/tests/fixtures/factories/post-laravel8.php b/tests/fixtures/factories/post-laravel8.php index 1cfaab74..3a62d557 100644 --- a/tests/fixtures/factories/post-laravel8.php +++ b/tests/fixtures/factories/post-laravel8.php @@ -29,6 +29,7 @@ public function definition() 'author_bio' => $this->faker->text, 'content' => $this->faker->paragraphs(3, true), 'published_at' => $this->faker->dateTime(), + 'updated_at' => $this->faker->dateTime(), 'word_count' => $this->faker->randomNumber(), ]; } diff --git a/tests/fixtures/factories/post.php b/tests/fixtures/factories/post.php index ee9e8bc7..2057c340 100644 --- a/tests/fixtures/factories/post.php +++ b/tests/fixtures/factories/post.php @@ -12,6 +12,7 @@ 'author_bio' => $faker->text, 'content' => $faker->paragraphs(3, true), 'published_at' => $faker->dateTime(), + 'updated_at' => $faker->dateTime(), 'word_count' => $faker->randomNumber(), ]; });