Skip to content

Commit ac55a5b

Browse files
committed
Add regression test for timestamps being included in the data column
1 parent 0f4d04e commit ac55a5b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/VirtualColumnTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,28 @@ public function testEncryptedCastsWorkWithVirtualColumn() {
157157
// Reset static property
158158
MyModel::$customEncryptedCastables = [];
159159
}
160+
161+
public function testUpdatingModelDoesNotStoreTimestampsInTheVirtualColumn() {
162+
/** @var TimestampModel $model */
163+
$model = TimestampModel::create();
164+
$dbRecordDataColumn = fn () => DB::selectOne('select * from timestamp_models where id = ?', [$model->id])->data;
165+
166+
$this->assertStringNotContainsString('created_at', $dbRecordDataColumn());
167+
$this->assertStringNotContainsString('updated_at', $dbRecordDataColumn());
168+
169+
$model->update(['data' => ['virtual' => 'bar']]);
170+
171+
$this->assertStringNotContainsString('created_at', $dbRecordDataColumn());
172+
$this->assertStringNotContainsString('updated_at', $dbRecordDataColumn());
173+
}
174+
}
175+
176+
class TimestampModel extends Model
177+
{
178+
use VirtualColumn;
179+
180+
public $timestamps = true;
181+
protected $guarded = [];
160182
}
161183

162184
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)