From ac55a5b5ecb8b4f3544453254b9d5a7234a55624 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 22 Jul 2025 09:43:26 +0200 Subject: [PATCH] Add regression test for timestamps being included in the data column --- tests/VirtualColumnTest.php | 22 ++++++++++++++ ...1_000001_create_timestamp_models_table.php | 30 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/etc/migrations/2020_05_11_000001_create_timestamp_models_table.php diff --git a/tests/VirtualColumnTest.php b/tests/VirtualColumnTest.php index 29c2e4b..18755fa 100644 --- a/tests/VirtualColumnTest.php +++ b/tests/VirtualColumnTest.php @@ -157,6 +157,28 @@ class VirtualColumnTest extends TestCase // Reset static property MyModel::$customEncryptedCastables = []; } + + public function testUpdatingModelDoesNotStoreTimestampsInTheVirtualColumn() { + /** @var TimestampModel $model */ + $model = TimestampModel::create(); + $dbRecordDataColumn = fn () => DB::selectOne('select * from timestamp_models where id = ?', [$model->id])->data; + + $this->assertStringNotContainsString('created_at', $dbRecordDataColumn()); + $this->assertStringNotContainsString('updated_at', $dbRecordDataColumn()); + + $model->update(['data' => ['virtual' => 'bar']]); + + $this->assertStringNotContainsString('created_at', $dbRecordDataColumn()); + $this->assertStringNotContainsString('updated_at', $dbRecordDataColumn()); + } +} + +class TimestampModel extends Model +{ + use VirtualColumn; + + public $timestamps = true; + protected $guarded = []; } class ParentModel extends Model diff --git a/tests/etc/migrations/2020_05_11_000001_create_timestamp_models_table.php b/tests/etc/migrations/2020_05_11_000001_create_timestamp_models_table.php new file mode 100644 index 0000000..975f135 --- /dev/null +++ b/tests/etc/migrations/2020_05_11_000001_create_timestamp_models_table.php @@ -0,0 +1,30 @@ +increments('id'); + + $table->timestamps(); + $table->json('data'); + }); + } + + public function down() + { + Schema::dropIfExists('timestamp_models'); + } +}