Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Annotation/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __construct(
) {
if ($default !== null) {
$this->hasDefault = true;
$default instanceof \BackedEnum and $this->default = $default->value;
Comment thread
roxblnfk marked this conversation as resolved.
}
$this->setAttributes($attributes);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Annotated/Unit/Attribute/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class ColumnTest extends TestCase
#[Column(type: 'string', length: 255, charset: 'ascii', collation: 'ascii_bin')]
private string $column9;

#[Column(
type: 'enum',
default: StringEnum::A,
values: StringEnum::class,
)]
private StringEnum $column10 = StringEnum::A;

public function testOneAttribute(): void
{
$column = $this->getColumn('column1');
Expand Down Expand Up @@ -122,6 +129,15 @@ public function testEnumTypeArrayBackedEnum(): void
$this->assertArrayNotHasKey('values', $column->getAttributes());
}

public function testEnumTypeBackedEnumAsDefault(): void
{
$column = $this->getColumn('column10');

$this->assertSame('enum(a,b)', $column->getType());
$this->assertSame('a', $column->getDefault());
$this->assertArrayNotHasKey('values', $column->getAttributes());
}

public function testCharsetAndCollationAttributes(): void
{
$column = $this->getColumn('column9');
Expand Down
Loading