mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 18:44:04 +00:00
Add test for generating the column name
This commit is contained in:
parent
43f0b2c30f
commit
c0cd839acc
2 changed files with 71 additions and 0 deletions
|
|
@ -88,6 +88,23 @@ class VirtualColumnTest extends TestCase
|
|||
MyModel::first();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function column_names_are_generated_correctly()
|
||||
{
|
||||
// AnotherModel's virtual data column name is 'virtual'
|
||||
$virtualColumnName = 'virtual->foo';
|
||||
$customColumnName = 'custom1';
|
||||
|
||||
/** @var FooModel $model */
|
||||
$model = FooModel::create([
|
||||
'custom1' => $customColumnName,
|
||||
'foo' => $virtualColumnName
|
||||
]);
|
||||
|
||||
$this->assertSame($customColumnName, $model->generateColumnName('custom1'));
|
||||
$this->assertSame($virtualColumnName, $model->generateColumnName('foo'));
|
||||
}
|
||||
|
||||
// maybe add an explicit test that the saving() and updating() listeners don't run twice?
|
||||
}
|
||||
|
||||
|
|
@ -107,3 +124,25 @@ class MyModel extends Model
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
class FooModel extends Model
|
||||
{
|
||||
use VirtualColumn;
|
||||
|
||||
protected $guarded = [];
|
||||
public $timestamps = false;
|
||||
|
||||
public static function getCustomColumns(): array
|
||||
{
|
||||
return [
|
||||
'id',
|
||||
'custom1',
|
||||
'custom2',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getDataColumn(): string
|
||||
{
|
||||
return 'virtual';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue