Allow BackedEnum as default value in Column definition#122
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
BackedEnumdefaults inColumnconstruction 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 What was changed
This pull request adds support for using backed enum values as default values in columns annotated with the
Columnattribute. 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:
Columnannotation'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:
column10toColumnTestthat 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