Skip to content

Allow BackedEnum as default value in Column definition#122

Merged
roxblnfk merged 1 commit into
4.xfrom
default-enum
May 19, 2026
Merged

Allow BackedEnum as default value in Column definition#122
roxblnfk merged 1 commit into
4.xfrom
default-enum

Conversation

@roxblnfk
Copy link
Copy Markdown
Member

🔍 What was changed

This pull request adds support for using backed enum values as default values in columns annotated with the Column attribute. It also introduces a corresponding test to ensure that the default value is correctly set to the enum's backing value.

Enhancements to enum default value handling:

  • Updated the Column annotation's constructor to set the default value to the enum's backing value when a backed enum is provided as the default. (src/Annotation/Column.php, src/Annotation/Column.phpR75)

Testing improvements:

  • Added a new property column10 to ColumnTest that uses a backed enum as the default value, and introduced a test method to verify the correct default handling and type. (tests/Annotated/Unit/Attribute/ColumnTest.php, [1] [2]

📝 Checklist

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.90%. Comparing base (dde50bd) to head (53c1288).

Additional details and impacted files
@@            Coverage Diff            @@
##                4.x     #122   +/-   ##
=========================================
  Coverage     91.89%   91.90%           
- Complexity      328      329    +1     
=========================================
  Files            38       38           
  Lines           839      840    +1     
=========================================
+ Hits            771      772    +1     
  Misses           68       68           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for passing a PHP BackedEnum case as the default value in the #[Column] attribute, ensuring the stored schema default uses the enum’s backing scalar value rather than the enum object.

Changes:

  • Convert BackedEnum defaults in Column construction to their backing scalar (->value).
  • Add a unit-test case covering a backed-enum default and asserting the resulting column default/type.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Annotation/Column.php Normalizes BackedEnum defaults to backing values during Column instantiation.
tests/Annotated/Unit/Attribute/ColumnTest.php Adds coverage ensuring enum-case defaults are persisted as backing scalar defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Annotation/Column.php
@roxblnfk roxblnfk merged commit 8eaec83 into 4.x May 19, 2026
16 checks passed
@roxblnfk roxblnfk deleted the default-enum branch May 19, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡 Allow setting enum cases as property defaults

2 participants