Skip to content

Commit

Permalink
Fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lukinovec committed Nov 7, 2023
1 parent 36493d0 commit 955860d
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions tests/VirtualColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@ public function models_extending_a_parent_model_using_virtualcolumn_get_encoded_
// 'foo' is a custom column, 'data' is the virtual column
FooChild::create(['foo' => 'foo']);
$encodedFoo = DB::select('select * from foo_childs limit 1')[0];

// Assert that the model was encoded correctly
$this->assertNull($encodedFoo->data);
$this->assertSame($encodedFoo->data, '[]');
$this->assertSame($encodedFoo->foo, 'foo');

// Create another child model of the same parent
// 'bar' is a custom column, 'data' is the virtual column
BarChild::create(['bar' => 'bar']);
$encodedBar = DB::select('select * from bar_childs limit 1')[0];

$this->assertNull($encodedBar->data);
$this->assertSame($encodedBar->data, '[]');
$this->assertSame($encodedBar->bar, 'bar');
}

Expand Down Expand Up @@ -164,17 +165,8 @@ class ParentModel extends Model
{
use VirtualColumn;

protected $guarded = [];
public $timestamps = false;

public function getCustomColumns(): array
{
return [
'id',
'custom1',
'custom2',
];
}
protected $guarded = [];
}

class MyModel extends ParentModel
Expand Down Expand Up @@ -210,20 +202,11 @@ public function set($model, $key, $value, $attributes)
}
}

class ParentModel extends Model
{
use VirtualColumn;

public $timestamps = false;
protected $guarded = [];
}


class FooChild extends ParentModel
{
public $table = 'foo_childs';

public static function getCustomColumns(): array
public function getCustomColumns(): array
{
return [
'id',
Expand All @@ -235,7 +218,7 @@ class BarChild extends ParentModel
{
public $table = 'bar_childs';

public static function getCustomColumns(): array
public function getCustomColumns(): array
{
return [
'id',
Expand Down

0 comments on commit 955860d

Please sign in to comment.