diff --git a/tests/Tests/Models/IssueKanbanBOX/EntityA.php b/tests/Tests/Models/IssueKanbanBOX/EntityA.php new file mode 100644 index 0000000000..1e5e859ccf --- /dev/null +++ b/tests/Tests/Models/IssueKanbanBOX/EntityA.php @@ -0,0 +1,33 @@ +id = $id; + } + + #[OneToOne(targetEntity: EntityVersion::class, cascade: ['persist'])] + #[JoinColumn(name: 'id', referencedColumnName: 'entityId', nullable: true, onDelete: 'CASCADE')] + protected EntityVersion|null $version = null; + + protected function createVersion(string $version): EntityVersion + { + return new EntityAVersion($this->id, $version); + } +} diff --git a/tests/Tests/Models/IssueKanbanBOX/EntityAVersion.php b/tests/Tests/Models/IssueKanbanBOX/EntityAVersion.php new file mode 100644 index 0000000000..5c858cc11f --- /dev/null +++ b/tests/Tests/Models/IssueKanbanBOX/EntityAVersion.php @@ -0,0 +1,12 @@ +id = $id; + } + + #[OneToOne(targetEntity: EntityBVersion::class)] + #[JoinColumn(name: 'id', referencedColumnName: 'entityId')] + protected EntityVersion|null $version = null; + + protected function createVersion(string $version): EntityVersion + { + return new EntityBVersion($this->id, $version); + } +} diff --git a/tests/Tests/Models/IssueKanbanBOX/EntityBVersion.php b/tests/Tests/Models/IssueKanbanBOX/EntityBVersion.php new file mode 100644 index 0000000000..e12a6a40cc --- /dev/null +++ b/tests/Tests/Models/IssueKanbanBOX/EntityBVersion.php @@ -0,0 +1,12 @@ + EntityAVersion::class, EntityB::class => EntityBVersion::class])] +#[DiscriminatorColumn(name: 'entityType', type: 'string')] +abstract class EntityVersion +{ + /** @var class-string */ + #[Id] + public $entityType; + + /** @var int */ + #[Id] + #[Column(type: 'integer')] + public $entityId; + + /** @var string */ + #[Column(type: 'string')] + public $version; + + public function __construct( + int $entityId, + string $version, + ) { + $this->entityType = static::class; + $this->entityId = $entityId; + $this->version = $version; + } + + public function setVersion(string $version): void + { + $this->version = $version; + } +} diff --git a/tests/Tests/Models/IssueKanbanBOX/VersionedEntity.php b/tests/Tests/Models/IssueKanbanBOX/VersionedEntity.php new file mode 100644 index 0000000000..a2af894296 --- /dev/null +++ b/tests/Tests/Models/IssueKanbanBOX/VersionedEntity.php @@ -0,0 +1,51 @@ +ensureJoinedEntityPropertyInitialized($this, 'version'); + + if ($this->version === null) { + $this->version = $this->createVersion($version); + + return; + } + + $this->version->version = $version; + } + + public function getVersion(): string|null + { + //$this->ensureJoinedEntityPropertyInitialized($this, 'version'); + + return $this->version?->version; + } + + private function ensureJoinedEntityPropertyInitialized(object $entity, string $propertyName): void + { + $reflection = new ReflectionProperty($entity, $propertyName); + $value = $reflection->getValue($entity); + if (! ($value instanceof Proxy)) { + return; + } + + try { + $value->__load(); + } catch (EntityNotFoundException) { + $reflection->setValue($entity, null); + } + } +} diff --git a/tests/Tests/ORM/Functional/Ticket/IssueKanbanBOXTest.php b/tests/Tests/ORM/Functional/Ticket/IssueKanbanBOXTest.php new file mode 100644 index 0000000000..3c25976560 --- /dev/null +++ b/tests/Tests/ORM/Functional/Ticket/IssueKanbanBOXTest.php @@ -0,0 +1,28 @@ +useModelSet('issueKanbanBOX'); + + parent::setUp(); + } + + public function testEntityVersion(): void + { + $entityA = new EntityA(1); + $this->_em->persist($entityA); + $this->_em->flush(); + $this->_em->clear(); + $dbRetrievedEntityA = $this->_em->getRepository(EntityA::class)->find(1); + self::assertNull($dbRetrievedEntityA->getVersion()); + } +} diff --git a/tests/Tests/OrmFunctionalTestCase.php b/tests/Tests/OrmFunctionalTestCase.php index edec9ca261..0261cd92fb 100644 --- a/tests/Tests/OrmFunctionalTestCase.php +++ b/tests/Tests/OrmFunctionalTestCase.php @@ -483,6 +483,13 @@ abstract class OrmFunctionalTestCase extends OrmTestCase Models\Issue9300\Issue9300Child::class, Models\Issue9300\Issue9300Parent::class, ], + 'issueKanbanBOX' => [ + Models\IssueKanbanBOX\EntityVersion::class, + Models\IssueKanbanBOX\EntityAVersion::class, + Models\IssueKanbanBOX\EntityBVersion::class, + Models\IssueKanbanBOX\EntityA::class, + Models\IssueKanbanBOX\EntityB::class, + ], ]; /** @param class-string ...$models */