Skip to content

Commit bb38940

Browse files
committed
Add regression test for timestamps being included in the data column
1 parent ab128b1 commit bb38940

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

tests/VirtualColumnTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,29 @@ public function encrypted_casts_work_with_virtual_column() {
163163
// Reset static property
164164
MyModel::$customEncryptedCastables = [];
165165
}
166+
167+
#[Test]
168+
public function updating_model_does_not_store_timestamps_in_the_virtual_column() {
169+
/** @var TimestampModel $model */
170+
$model = TimestampModel::create();
171+
$dbRecordDataColumn = fn () => DB::selectOne('select * from timestamp_models where id = ?', [$model->id])->data;
172+
173+
$this->assertStringNotContainsString('created_at', $dbRecordDataColumn());
174+
$this->assertStringNotContainsString('updated_at', $dbRecordDataColumn());
175+
176+
$model->update(['data' => ['virtual' => 'bar']]);
177+
178+
$this->assertStringNotContainsString('created_at', $dbRecordDataColumn());
179+
$this->assertStringNotContainsString('updated_at', $dbRecordDataColumn());
180+
}
181+
}
182+
183+
class TimestampModel extends Model
184+
{
185+
use VirtualColumn;
186+
187+
public $timestamps = true;
188+
protected $guarded = [];
166189
}
167190

168191
class ParentModel extends Model
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
class CreateTimestampModelsTable extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*
14+
* @return void
15+
*/
16+
public function up()
17+
{
18+
Schema::create('timestamp_models', function (Blueprint $table) {
19+
$table->increments('id');
20+
21+
$table->timestamps();
22+
$table->json('data');
23+
});
24+
}
25+
26+
public function down()
27+
{
28+
Schema::dropIfExists('timestamp_models');
29+
}
30+
}

0 commit comments

Comments
 (0)