From 9126f024d016109aa57b397a6acb402d0895104a Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 28 May 2026 15:24:43 +0400 Subject: [PATCH 1/3] Support BackedEnum for discriminator values in STI --- src/Mapper/Traits/SingleTableTrait.php | 6 +- src/Parser/Typecast.php | 4 + .../Inheritance/Fixture/BossWithKind.php | 10 ++ .../Inheritance/Fixture/EmployeeKind.php | 11 ++ .../Inheritance/Fixture/EmployeeType.php | 11 ++ .../Inheritance/Fixture/WorkerWithKind.php | 13 ++ .../Inheritance/STI/EnumDiscriminatorTest.php | 163 ++++++++++++++++++ .../STI/EnumPropertyDiscriminatorTest.php | 152 ++++++++++++++++ .../STI/IntEnumDiscriminatorTest.php | 119 +++++++++++++ .../Inheritance/STI/EnumDiscriminatorTest.php | 17 ++ .../STI/EnumPropertyDiscriminatorTest.php | 17 ++ .../STI/IntEnumDiscriminatorTest.php | 17 ++ .../Inheritance/STI/EnumDiscriminatorTest.php | 17 ++ .../STI/EnumPropertyDiscriminatorTest.php | 17 ++ .../STI/IntEnumDiscriminatorTest.php | 17 ++ .../Inheritance/STI/EnumDiscriminatorTest.php | 17 ++ .../STI/EnumPropertyDiscriminatorTest.php | 17 ++ .../STI/IntEnumDiscriminatorTest.php | 17 ++ .../Inheritance/STI/EnumDiscriminatorTest.php | 17 ++ .../STI/EnumPropertyDiscriminatorTest.php | 17 ++ .../STI/IntEnumDiscriminatorTest.php | 17 ++ 21 files changed, 692 insertions(+), 1 deletion(-) create mode 100644 tests/ORM/Functional/Driver/Common/Inheritance/Fixture/BossWithKind.php create mode 100644 tests/ORM/Functional/Driver/Common/Inheritance/Fixture/EmployeeKind.php create mode 100644 tests/ORM/Functional/Driver/Common/Inheritance/Fixture/EmployeeType.php create mode 100644 tests/ORM/Functional/Driver/Common/Inheritance/Fixture/WorkerWithKind.php create mode 100644 tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/MySQL/Inheritance/STI/EnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/MySQL/Inheritance/STI/EnumPropertyDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/MySQL/Inheritance/STI/IntEnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/Postgres/Inheritance/STI/EnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/Postgres/Inheritance/STI/EnumPropertyDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/Postgres/Inheritance/STI/IntEnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/SQLServer/Inheritance/STI/EnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/SQLServer/Inheritance/STI/EnumPropertyDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/SQLServer/Inheritance/STI/IntEnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/SQLite/Inheritance/STI/EnumDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/SQLite/Inheritance/STI/EnumPropertyDiscriminatorTest.php create mode 100644 tests/ORM/Functional/Driver/SQLite/Inheritance/STI/IntEnumDiscriminatorTest.php diff --git a/src/Mapper/Traits/SingleTableTrait.php b/src/Mapper/Traits/SingleTableTrait.php index 08b9e1f9d..3024fe5ff 100644 --- a/src/Mapper/Traits/SingleTableTrait.php +++ b/src/Mapper/Traits/SingleTableTrait.php @@ -24,7 +24,11 @@ protected function resolveClass(array $data, ?string $role = null): string } $class = $this->entity; if ($this->children !== [] && isset($data[$this->discriminator])) { - $class = $this->children[$data[$this->discriminator]] ?? $this->entity; + $key = $data[$this->discriminator]; + if ($key instanceof \BackedEnum) { + $key = $key->value; + } + $class = $this->children[$key] ?? $this->entity; } return $class; diff --git a/src/Parser/Typecast.php b/src/Parser/Typecast.php index 82cd1132f..6ede87914 100644 --- a/src/Parser/Typecast.php +++ b/src/Parser/Typecast.php @@ -106,6 +106,10 @@ public function setRules(array $rules): array ? $rule::tryFrom((int) $value) : null; + $this->uncasters[$key] = static fn(mixed $value): mixed => $value instanceof \BackedEnum + ? $value->value + : $value; + unset($rules[$key]); continue; } diff --git a/tests/ORM/Functional/Driver/Common/Inheritance/Fixture/BossWithKind.php b/tests/ORM/Functional/Driver/Common/Inheritance/Fixture/BossWithKind.php new file mode 100644 index 000000000..42d29ee92 --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Inheritance/Fixture/BossWithKind.php @@ -0,0 +1,10 @@ +makeTable('employee_table', [ + static::$discriminator => 'string,nullable', + 'id' => 'primary', + 'name' => 'string', + 'email' => 'string', + 'age' => 'int', + ]); + + $this->getDatabase()->table('employee_table')->insertMultiple( + [static::$discriminator, 'name', 'email', 'age'], + [ + ['_type' => 'manager', 'name' => 'John', 'email' => 'captain@black.sea', 'age' => 38], + ['_type' => 'employee', 'name' => 'Anton', 'email' => 'antonio@mail.org', 'age' => 35], + ], + ); + + $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); + } + + public function testChildClassResolvedFromScalarInDatabase(): void + { + $selector = new Select($this->orm, Employee::class); + [$first, $second] = $selector->orderBy('id')->fetchAll(); + + $this->assertInstanceOf(Manager::class, $first); + $this->assertInstanceOf(Employee::class, $second); + $this->assertNotInstanceOf(Manager::class, $second); + } + + public function testFetchedDataExposesEnumCaseAtDiscriminatorColumn(): void + { + $rows = (new Select($this->orm, Employee::class))->orderBy('id')->fetchData(); + + $this->assertSame(EmployeeType::Manager, $rows[0]['_type']); + $this->assertSame(EmployeeType::Employee, $rows[1]['_type']); + } + + public function testPersistedChildWritesScalarToDatabase(): void + { + $manager = new Manager(); + $manager->name = 'Manager'; + $manager->email = 'admin@email.com'; + $manager->age = 69; + + $this->save($manager); + + $row = $this->getDatabase() + ->table('employee_table') + ->select() + ->where('id', $manager->id) + ->fetchAll()[0]; + + $this->assertSame('manager', $row[static::$discriminator]); + } + + public function testRoundTripChildEntity(): void + { + $manager = new Manager(); + $manager->name = 'Manager'; + $manager->email = 'admin@email.com'; + $manager->age = 69; + + $this->save($manager); + + $loaded = (new Select($this->orm->withHeap(new Heap()), Employee::class)) + ->wherePK($manager->id) + ->fetchOne(); + + $this->assertInstanceOf(Manager::class, $loaded); + } + + public function testMakeResolvesChildClassFromEnumInputData(): void + { + // Defensive: explicit BackedEnum passed as discriminator value should still resolve. + $entity = $this->orm->make(static::BASE_ROLE, [ + '_type' => EmployeeType::Manager, + 'name' => 'Senya', + 'email' => 'sene4ka@hamster.me', + 'age' => 12, + ]); + + $this->assertInstanceOf(Manager::class, $entity); + } + + public function testNoExtraWritesAfterLoadAndResave(): void + { + /** @var Manager $manager */ + $manager = (new Select($this->orm, Employee::class))->orderBy('id')->fetchOne(); + $this->assertInstanceOf(Manager::class, $manager); + + $this->captureWriteQueries(); + $this->save($manager); + $this->assertNumWrites(0); + } + + public function testUpdateChildEntityKeepsScalarDiscriminatorInDatabase(): void + { + /** @var Manager $manager */ + $manager = (new Select($this->orm, Employee::class))->orderBy('id')->fetchOne(); + $this->assertInstanceOf(Manager::class, $manager); + + $manager->name = 'Renamed'; + $this->save($manager); + + $row = $this->getDatabase() + ->table('employee_table') + ->select() + ->where('id', $manager->id) + ->fetchAll()[0]; + + $this->assertSame('manager', $row[static::$discriminator]); + $this->assertSame('Renamed', $row['name']); + } + + protected function getSchemaArray(): array + { + return [ + static::BASE_ROLE => [ + SchemaInterface::ENTITY => Employee::class, + SchemaInterface::CHILDREN => [ + 'manager' => Manager::class, + ], + SchemaInterface::MAPPER => Mapper::class, + SchemaInterface::DATABASE => 'default', + SchemaInterface::TABLE => 'employee_table', + SchemaInterface::PRIMARY_KEY => 'id', + SchemaInterface::COLUMNS => ['id', '_type' => static::$discriminator, 'name', 'email', 'age'], + SchemaInterface::TYPECAST => ['id' => 'int', 'age' => 'int', '_type' => EmployeeType::class], + SchemaInterface::SCHEMA => [], + SchemaInterface::RELATIONS => [], + ], + self::MANAGER_ROLE => [ + SchemaInterface::ENTITY => Manager::class, + ], + ]; + } +} diff --git a/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php new file mode 100644 index 000000000..7582cc2c7 --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php @@ -0,0 +1,152 @@ +makeTable('worker_table', [ + 'type' => 'string,nullable', + 'id' => 'primary', + 'name' => 'string', + 'email' => 'string', + 'age' => 'int', + 'level' => 'int,nullable', + ]); + + $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); + } + + public function testInsertChildWritesScalarDespiteEnumOnProperty(): void + { + $boss = new BossWithKind(); + $boss->type = EmployeeType::Manager; + $boss->name = 'Boss'; + $boss->email = 'boss@corp.example'; + $boss->age = 50; + $boss->level = 10; + + $this->save($boss); + + $row = $this->getDatabase() + ->table('worker_table') + ->select() + ->where('id', $boss->id) + ->fetchAll()[0]; + + $this->assertSame('manager', $row['type']); + } + + public function testInsertBaseWithEnumPropertyWritesScalar(): void + { + // Base entity does NOT match any child in CHILDREN -> getDiscriminatorValues() returns []. + // The only thing that scalarizes the enum from $entity->type is the fetchFields() branch. + $worker = new WorkerWithKind(); + $worker->type = EmployeeType::Employee; + $worker->name = 'Plain Worker'; + $worker->email = 'plain@corp.example'; + $worker->age = 30; + + $this->save($worker); + + $row = $this->getDatabase() + ->table('worker_table') + ->select() + ->where('id', $worker->id) + ->fetchAll()[0]; + + $this->assertSame('employee', $row['type']); + } + + public function testRoundTripPreservesEnumOnEntity(): void + { + $boss = new BossWithKind(); + $boss->type = EmployeeType::Manager; + $boss->name = 'Boss'; + $boss->email = 'boss@corp.example'; + $boss->age = 50; + $boss->level = 10; + $this->save($boss); + + /** @var BossWithKind $loaded */ + $loaded = (new Select($this->orm->withHeap(new Heap()), WorkerWithKind::class)) + ->wherePK($boss->id) + ->fetchOne(); + + $this->assertInstanceOf(BossWithKind::class, $loaded); + $this->assertSame(EmployeeType::Manager, $loaded->type); + } + + public function testNoExtraWritesAfterRoundTrip(): void + { + $boss = new BossWithKind(); + $boss->type = EmployeeType::Manager; + $boss->name = 'Boss'; + $boss->email = 'boss@corp.example'; + $boss->age = 50; + $boss->level = 10; + $this->save($boss); + + $this->orm = $this->orm->withHeap(new Heap()); + + /** @var BossWithKind $loaded */ + $loaded = (new Select($this->orm, WorkerWithKind::class)) + ->wherePK($boss->id) + ->fetchOne(); + + $this->captureWriteQueries(); + $this->save($loaded); + $this->assertNumWrites(0); + } + + protected function getSchemaArray(): array + { + return [ + self::WORKER_ROLE => [ + SchemaInterface::ENTITY => WorkerWithKind::class, + SchemaInterface::CHILDREN => [ + 'manager' => BossWithKind::class, + ], + SchemaInterface::MAPPER => Mapper::class, + SchemaInterface::DATABASE => 'default', + SchemaInterface::TABLE => 'worker_table', + SchemaInterface::PRIMARY_KEY => 'id', + SchemaInterface::DISCRIMINATOR => 'type', + SchemaInterface::COLUMNS => ['id', 'type', 'name', 'email', 'age', 'level'], + SchemaInterface::TYPECAST => [ + 'id' => 'int', + 'age' => 'int', + 'level' => 'int', + 'type' => EmployeeType::class, + ], + SchemaInterface::SCHEMA => [], + SchemaInterface::RELATIONS => [], + ], + self::BOSS_ROLE => [ + SchemaInterface::ENTITY => BossWithKind::class, + ], + ]; + } +} diff --git a/tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php b/tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php new file mode 100644 index 000000000..f02eca6df --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php @@ -0,0 +1,119 @@ +makeTable('employee_table', [ + 'kind' => 'int,nullable', + 'id' => 'primary', + 'name' => 'string', + 'email' => 'string', + 'age' => 'int', + ]); + + $this->getDatabase()->table('employee_table')->insertMultiple( + ['kind', 'name', 'email', 'age'], + [ + ['kind' => EmployeeKind::Manager->value, 'name' => 'John', 'email' => 'j@x', 'age' => 38], + ['kind' => EmployeeKind::Employee->value, 'name' => 'Anton', 'email' => 'a@x', 'age' => 35], + ], + ); + + $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); + } + + public function testChildClassResolvedFromIntScalarInDatabase(): void + { + [$first, $second] = (new Select($this->orm, Employee::class))->orderBy('id')->fetchAll(); + + $this->assertInstanceOf(Manager::class, $first); + $this->assertInstanceOf(Employee::class, $second); + $this->assertNotInstanceOf(Manager::class, $second); + } + + public function testPersistedChildWritesIntScalar(): void + { + $manager = new Manager(); + $manager->name = 'New Manager'; + $manager->email = 'new@manager'; + $manager->age = 40; + $this->save($manager); + + $row = $this->getDatabase() + ->table('employee_table') + ->select() + ->where('id', $manager->id) + ->fetchAll()[0]; + + $this->assertSame(EmployeeKind::Manager->value, (int) $row['kind']); + } + + public function testMakeResolvesChildClassFromIntEnumInputData(): void + { + $entity = $this->orm->make(static::BASE_ROLE, [ + '_type' => EmployeeKind::Manager, + 'name' => 'Senya', + 'email' => 'sene4ka@hamster.me', + 'age' => 12, + ]); + + $this->assertInstanceOf(Manager::class, $entity); + } + + public function testRoundTripChildEntity(): void + { + $manager = new Manager(); + $manager->name = 'Round-trip'; + $manager->email = 'rt@manager'; + $manager->age = 42; + $this->save($manager); + + $loaded = (new Select($this->orm->withHeap(new Heap()), Employee::class)) + ->wherePK($manager->id) + ->fetchOne(); + + $this->assertInstanceOf(Manager::class, $loaded); + } + + protected function getSchemaArray(): array + { + return [ + static::BASE_ROLE => [ + SchemaInterface::ENTITY => Employee::class, + SchemaInterface::CHILDREN => [ + EmployeeKind::Manager->value => Manager::class, + ], + SchemaInterface::MAPPER => Mapper::class, + SchemaInterface::DATABASE => 'default', + SchemaInterface::TABLE => 'employee_table', + SchemaInterface::PRIMARY_KEY => 'id', + SchemaInterface::COLUMNS => ['id', '_type' => 'kind', 'name', 'email', 'age'], + SchemaInterface::TYPECAST => ['id' => 'int', 'age' => 'int', '_type' => EmployeeKind::class], + SchemaInterface::SCHEMA => [], + SchemaInterface::RELATIONS => [], + ], + self::MANAGER_ROLE => [ + SchemaInterface::ENTITY => Manager::class, + ], + ]; + } +} diff --git a/tests/ORM/Functional/Driver/MySQL/Inheritance/STI/EnumDiscriminatorTest.php b/tests/ORM/Functional/Driver/MySQL/Inheritance/STI/EnumDiscriminatorTest.php new file mode 100644 index 000000000..1de0cf6f2 --- /dev/null +++ b/tests/ORM/Functional/Driver/MySQL/Inheritance/STI/EnumDiscriminatorTest.php @@ -0,0 +1,17 @@ + Date: Thu, 28 May 2026 11:25:44 +0000 Subject: [PATCH 2/3] style(php-cs-fixer): fix coding standards --- .../Inheritance/STI/EnumDiscriminatorTest.php | 46 +++++++++---------- .../STI/EnumPropertyDiscriminatorTest.php | 32 ++++++------- .../STI/IntEnumDiscriminatorTest.php | 46 +++++++++---------- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumDiscriminatorTest.php b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumDiscriminatorTest.php index a6481368c..e0fd178e2 100644 --- a/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumDiscriminatorTest.php +++ b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumDiscriminatorTest.php @@ -20,29 +20,6 @@ abstract class EnumDiscriminatorTest extends StiBaseTest protected static string $discriminator = 'discriminator_value'; - public function setUp(): void - { - parent::setUp(); - - $this->makeTable('employee_table', [ - static::$discriminator => 'string,nullable', - 'id' => 'primary', - 'name' => 'string', - 'email' => 'string', - 'age' => 'int', - ]); - - $this->getDatabase()->table('employee_table')->insertMultiple( - [static::$discriminator, 'name', 'email', 'age'], - [ - ['_type' => 'manager', 'name' => 'John', 'email' => 'captain@black.sea', 'age' => 38], - ['_type' => 'employee', 'name' => 'Anton', 'email' => 'antonio@mail.org', 'age' => 35], - ], - ); - - $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); - } - public function testChildClassResolvedFromScalarInDatabase(): void { $selector = new Select($this->orm, Employee::class); @@ -138,6 +115,29 @@ public function testUpdateChildEntityKeepsScalarDiscriminatorInDatabase(): void $this->assertSame('Renamed', $row['name']); } + public function setUp(): void + { + parent::setUp(); + + $this->makeTable('employee_table', [ + static::$discriminator => 'string,nullable', + 'id' => 'primary', + 'name' => 'string', + 'email' => 'string', + 'age' => 'int', + ]); + + $this->getDatabase()->table('employee_table')->insertMultiple( + [static::$discriminator, 'name', 'email', 'age'], + [ + ['_type' => 'manager', 'name' => 'John', 'email' => 'captain@black.sea', 'age' => 38], + ['_type' => 'employee', 'name' => 'Anton', 'email' => 'antonio@mail.org', 'age' => 35], + ], + ); + + $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); + } + protected function getSchemaArray(): array { return [ diff --git a/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php index 7582cc2c7..c2bca1600 100644 --- a/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php +++ b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php @@ -23,22 +23,6 @@ abstract class EnumPropertyDiscriminatorTest extends StiBaseTest protected const WORKER_ROLE = 'worker'; protected const BOSS_ROLE = 'boss'; - public function setUp(): void - { - parent::setUp(); - - $this->makeTable('worker_table', [ - 'type' => 'string,nullable', - 'id' => 'primary', - 'name' => 'string', - 'email' => 'string', - 'age' => 'int', - 'level' => 'int,nullable', - ]); - - $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); - } - public function testInsertChildWritesScalarDespiteEnumOnProperty(): void { $boss = new BossWithKind(); @@ -121,6 +105,22 @@ public function testNoExtraWritesAfterRoundTrip(): void $this->assertNumWrites(0); } + public function setUp(): void + { + parent::setUp(); + + $this->makeTable('worker_table', [ + 'type' => 'string,nullable', + 'id' => 'primary', + 'name' => 'string', + 'email' => 'string', + 'age' => 'int', + 'level' => 'int,nullable', + ]); + + $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); + } + protected function getSchemaArray(): array { return [ diff --git a/tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php b/tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php index f02eca6df..b066f481f 100644 --- a/tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php +++ b/tests/ORM/Functional/Driver/Common/Inheritance/STI/IntEnumDiscriminatorTest.php @@ -18,29 +18,6 @@ abstract class IntEnumDiscriminatorTest extends StiBaseTest protected const BASE_ROLE = 'employee'; protected const MANAGER_ROLE = 'manager'; - public function setUp(): void - { - parent::setUp(); - - $this->makeTable('employee_table', [ - 'kind' => 'int,nullable', - 'id' => 'primary', - 'name' => 'string', - 'email' => 'string', - 'age' => 'int', - ]); - - $this->getDatabase()->table('employee_table')->insertMultiple( - ['kind', 'name', 'email', 'age'], - [ - ['kind' => EmployeeKind::Manager->value, 'name' => 'John', 'email' => 'j@x', 'age' => 38], - ['kind' => EmployeeKind::Employee->value, 'name' => 'Anton', 'email' => 'a@x', 'age' => 35], - ], - ); - - $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); - } - public function testChildClassResolvedFromIntScalarInDatabase(): void { [$first, $second] = (new Select($this->orm, Employee::class))->orderBy('id')->fetchAll(); @@ -94,6 +71,29 @@ public function testRoundTripChildEntity(): void $this->assertInstanceOf(Manager::class, $loaded); } + public function setUp(): void + { + parent::setUp(); + + $this->makeTable('employee_table', [ + 'kind' => 'int,nullable', + 'id' => 'primary', + 'name' => 'string', + 'email' => 'string', + 'age' => 'int', + ]); + + $this->getDatabase()->table('employee_table')->insertMultiple( + ['kind', 'name', 'email', 'age'], + [ + ['kind' => EmployeeKind::Manager->value, 'name' => 'John', 'email' => 'j@x', 'age' => 38], + ['kind' => EmployeeKind::Employee->value, 'name' => 'Anton', 'email' => 'a@x', 'age' => 35], + ], + ); + + $this->orm = $this->withSchema(new Schema($this->getSchemaArray())); + } + protected function getSchemaArray(): array { return [ From 5041fd95b00d3b005285302054117dadab3eb9a5 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 28 May 2026 16:18:04 +0400 Subject: [PATCH 3/3] Fix after review --- .../Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php index c2bca1600..79a54a5fc 100644 --- a/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php +++ b/tests/ORM/Functional/Driver/Common/Inheritance/STI/EnumPropertyDiscriminatorTest.php @@ -16,7 +16,7 @@ /** * STI scenario where the entity exposes the discriminator as a BackedEnum-typed property * (so `extractData` returns an enum case in the discriminator slot). Exercises the - * scalarization branch in `Mapper::fetchFields`. + * enum -> scalar conversion performed by the BackedEnum uncaster in {@see \Cycle\ORM\Parser\Typecast::uncast()}. */ abstract class EnumPropertyDiscriminatorTest extends StiBaseTest { @@ -46,7 +46,7 @@ public function testInsertChildWritesScalarDespiteEnumOnProperty(): void public function testInsertBaseWithEnumPropertyWritesScalar(): void { // Base entity does NOT match any child in CHILDREN -> getDiscriminatorValues() returns []. - // The only thing that scalarizes the enum from $entity->type is the fetchFields() branch. + // The enum on $entity->type is converted to a scalar by the BackedEnum uncaster in Typecast::uncast(). $worker = new WorkerWithKind(); $worker->type = EmployeeType::Employee; $worker->name = 'Plain Worker';