|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket; |
| 6 | + |
| 7 | +use Doctrine\ORM\Mapping as ORM; |
| 8 | +use Doctrine\ORM\Mapping\Column; |
| 9 | +use Doctrine\ORM\Mapping\Entity; |
| 10 | +use Doctrine\ORM\Mapping\GeneratedValue; |
| 11 | +use Doctrine\ORM\Mapping\Id; |
| 12 | +use Doctrine\Tests\OrmFunctionalTestCase; |
| 13 | + |
| 14 | +class GH12063 extends OrmFunctionalTestCase |
| 15 | +{ |
| 16 | + protected function setUp(): void |
| 17 | + { |
| 18 | + parent::setUp(); |
| 19 | + |
| 20 | + $this->createSchemaForModels(GH12063Association::class, GH12063Entity::class); |
| 21 | + } |
| 22 | + |
| 23 | + public function testLoadedAssociationWithBackedEnum(): void |
| 24 | + { |
| 25 | + $association = new GH12063Association(); |
| 26 | + $association->code = GH12063Code::One; |
| 27 | + |
| 28 | + $this->_em->persist($association); |
| 29 | + $this->_em->flush(); |
| 30 | + $this->_em->clear(); |
| 31 | + |
| 32 | + $entity = new GH12063Entity(); |
| 33 | + $entity->association = $this->_em->find(GH12063Association::class, GH12063Code::One); |
| 34 | + |
| 35 | + $this->_em->persist($entity); |
| 36 | + $this->_em->flush(); |
| 37 | + |
| 38 | + $this->assertNotNull($entity->id); |
| 39 | + } |
| 40 | + |
| 41 | + public function testProxyAssociationWithBackedEnum(): void |
| 42 | + { |
| 43 | + $association = new GH12063Association(); |
| 44 | + $association->code = GH12063Code::Two; |
| 45 | + |
| 46 | + $this->_em->persist($association); |
| 47 | + $this->_em->flush(); |
| 48 | + $this->_em->clear(); |
| 49 | + |
| 50 | + $entity = new GH12063Entity(); |
| 51 | + $entity->association = $this->_em->getReference(GH12063Association::class, GH12063Code::Two); |
| 52 | + |
| 53 | + $this->_em->persist($entity); |
| 54 | + $this->_em->flush(); |
| 55 | + |
| 56 | + $this->assertNotNull($entity->id); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +enum GH12063Code: string |
| 61 | +{ |
| 62 | + case One = 'one'; |
| 63 | + case Two = 'two'; |
| 64 | +} |
| 65 | + |
| 66 | +#[Entity] |
| 67 | +class GH12063Association |
| 68 | +{ |
| 69 | + #[Id] |
| 70 | + #[Column] |
| 71 | + public GH12063Code $code; |
| 72 | +} |
| 73 | + |
| 74 | +#[Entity] |
| 75 | +class GH12063Entity |
| 76 | +{ |
| 77 | + #[Id] |
| 78 | + #[Column] |
| 79 | + #[GeneratedValue] |
| 80 | + public int|null $id = null; |
| 81 | + |
| 82 | + #[ORM\ManyToOne] |
| 83 | + #[ORM\JoinColumn(referencedColumnName: 'code')] |
| 84 | + public GH12063Association $association; |
| 85 | +} |
0 commit comments