mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 15:14:04 +00:00
Add regression test for timestamps being included in the data column
This commit is contained in:
parent
ab128b1fbc
commit
bb38940cbf
2 changed files with 53 additions and 0 deletions
|
|
@ -163,6 +163,29 @@ class VirtualColumnTest extends TestCase
|
||||||
// Reset static property
|
// Reset static property
|
||||||
MyModel::$customEncryptedCastables = [];
|
MyModel::$customEncryptedCastables = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function updating_model_does_not_store_timestamps_in_the_virtual_column() {
|
||||||
|
/** @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
|
class ParentModel extends Model
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateTimestampModelsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('timestamp_models', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
$table->json('data');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('timestamp_models');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue