Skip to content

Support BackedEnum for discriminator values in STI#566

Merged
roxblnfk merged 3 commits into
2.xfrom
sti-enum
May 29, 2026
Merged

Support BackedEnum for discriminator values in STI#566
roxblnfk merged 3 commits into
2.xfrom
sti-enum

Conversation

@roxblnfk

Copy link
Copy Markdown
Member

🔍 What was changed

Added an ability to use BackedEnum as an STI discriminator.

📝 Checklist

  • Closes #
  • How was this tested:
    • Tested manually
    • Unit tests added

📃 Documentation

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.60%. Comparing base (abaaa51) to head (5041fd9).

Additional details and impacted files
@@            Coverage Diff            @@
##                2.x     #566   +/-   ##
=========================================
  Coverage     91.59%   91.60%           
- Complexity     2013     2015    +2     
=========================================
  Files           131      131           
  Lines          5223     5229    +6     
=========================================
+ Hits           4784     4790    +6     
  Misses          439      439           

☔ 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds BackedEnum support for Single Table Inheritance discriminator values, allowing enum cases to be used when resolving child classes and scalar-backed values to be persisted through typecasting.

Changes:

  • Normalizes BackedEnum discriminator values in STI class resolution.
  • Adds BackedEnum uncasting in Typecast so enum cases persist as scalar backing values.
  • Adds cross-driver functional coverage for string-backed, int-backed, and entity-property discriminator scenarios.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Mapper/Traits/SingleTableTrait.php Resolves STI child classes using enum backing values.
src/Parser/Typecast.php Adds enum case to scalar conversion during uncast.
tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumDiscriminatorTest.php Adds string-backed enum discriminator tests.
tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php Adds int-backed enum discriminator tests.
tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php Adds tests for enum discriminator exposed as entity property.
tests/ORM/Functional/Driver/Common/Inheritance/Fixture/EmployeeType.php Adds string-backed enum fixture.
tests/ORM/Functional/Driver/Common/Inheritance/Fixture/EmployeeKind.php Adds int-backed enum fixture.
tests/ORM/Functional/Driver/Common/Inheritance/Fixture/WorkerWithKind.php Adds base fixture with enum discriminator property.
tests/ORM/Functional/Driver/Common/Inheritance/Fixture/BossWithKind.php Adds child fixture for enum-property STI tests.
tests/ORM/Functional/Driver/MySQL/Inheritance/STI/*Enum*Test.php Wires common enum STI tests for MySQL.
tests/ORM/Functional/Driver/Postgres/Inheritance/STI/*Enum*Test.php Wires common enum STI tests for Postgres.
tests/ORM/Functional/Driver/SQLite/Inheritance/STI/*Enum*Test.php Wires common enum STI tests for SQLite.
tests/ORM/Functional/Driver/SQLServer/Inheritance/STI/*Enum*Test.php Wires common enum STI tests for SQL Server.

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

@roxblnfk roxblnfk merged commit 42af3d2 into 2.x May 29, 2026
28 of 30 checks passed
@roxblnfk roxblnfk deleted the sti-enum branch May 29, 2026 08:35
@roxblnfk roxblnfk added this to the 2.17.x milestone Jun 2, 2026
@roxblnfk roxblnfk added the type:feature New feature. label Jun 2, 2026
@roxblnfk roxblnfk added this to Cycle Jun 2, 2026
@github-project-automation github-project-automation Bot moved this to Done in Cycle Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants