diff --git a/src/Annotation/Column.php b/src/Annotation/Column.php index 6e25c45..295c3fb 100644 --- a/src/Annotation/Column.php +++ b/src/Annotation/Column.php @@ -72,6 +72,7 @@ public function __construct( ) { if ($default !== null) { $this->hasDefault = true; + $default instanceof \BackedEnum and $this->default = $default->value; } $this->setAttributes($attributes); } diff --git a/tests/Annotated/Unit/Attribute/ColumnTest.php b/tests/Annotated/Unit/Attribute/ColumnTest.php index 4860e41..897d984 100644 --- a/tests/Annotated/Unit/Attribute/ColumnTest.php +++ b/tests/Annotated/Unit/Attribute/ColumnTest.php @@ -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'); @@ -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');