Skip to content

Commit 67ac5a8

Browse files
author
Valentin Karnauhov
committed
Fixed proxy initialization for EnumReflectionProperty
1 parent 55c4845 commit 67ac5a8

File tree

5 files changed

+186
-1
lines changed

5 files changed

+186
-1
lines changed

src/Proxy/ProxyFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private function createLazyInitializer(ClassMetadata $classMetadata, EntityPersi
234234
$class = $entityPersister->getClassMetadata();
235235

236236
foreach ($class->getReflectionProperties() as $property) {
237-
if (! $property || ! $class->hasField($property->name) && ! $class->hasAssociation($property->name)) {
237+
if (! $property || ! $class->hasField($property->getName()) && ! $class->hasAssociation($property->getName())) {
238238
continue;
239239
}
240240

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386;
6+
7+
use Doctrine\ORM\Mapping\Column;
8+
use Doctrine\ORM\Mapping\Entity;
9+
use Doctrine\ORM\Mapping\GeneratedValue;
10+
use Doctrine\ORM\Mapping\Id;
11+
use Doctrine\ORM\Mapping\OneToOne;
12+
13+
#[Entity]
14+
class GH11386EntityCart
15+
{
16+
#[Id]
17+
#[GeneratedValue]
18+
#[Column]
19+
private int|null $id = null;
20+
21+
#[Column]
22+
private int|null $amount = null;
23+
24+
#[OneToOne(inversedBy: 'cart', cascade: ['persist', 'remove'], orphanRemoval: true)]
25+
private GH11386EntityCustomer|null $customer = null;
26+
27+
public function getId(): int|null
28+
{
29+
return $this->id;
30+
}
31+
32+
public function getAmount(): int|null
33+
{
34+
return $this->amount;
35+
}
36+
37+
public function setAmount(int $amount): static
38+
{
39+
$this->amount = $amount;
40+
41+
return $this;
42+
}
43+
44+
public function getCustomer(): GH11386EntityCustomer|null
45+
{
46+
return $this->customer;
47+
}
48+
49+
public function setCustomer(GH11386EntityCustomer|null $customer): self
50+
{
51+
$this->customer = $customer;
52+
53+
return $this;
54+
}
55+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386;
6+
7+
use Doctrine\ORM\Mapping\Column;
8+
use Doctrine\ORM\Mapping\Entity;
9+
use Doctrine\ORM\Mapping\GeneratedValue;
10+
use Doctrine\ORM\Mapping\Id;
11+
use Doctrine\ORM\Mapping\OneToOne;
12+
13+
#[Entity]
14+
class GH11386EntityCustomer
15+
{
16+
#[Id]
17+
#[GeneratedValue]
18+
#[Column]
19+
private int|null $id = null;
20+
21+
#[Column]
22+
private string|null $name = null;
23+
24+
#[Column(type: 'smallint', nullable: true, enumType: GH11386EnumType::class, options: ['unsigned' => true])]
25+
private GH11386EnumType|null $type = null;
26+
27+
#[OneToOne(mappedBy: 'customer')]
28+
private GH11386EntityCart|null $cart = null;
29+
30+
public function getId(): int|null
31+
{
32+
return $this->id;
33+
}
34+
35+
public function getName(): string|null
36+
{
37+
return $this->name;
38+
}
39+
40+
public function setName(string $name): static
41+
{
42+
$this->name = $name;
43+
44+
return $this;
45+
}
46+
47+
public function getType(): GH11386EnumType|null
48+
{
49+
return $this->type;
50+
}
51+
52+
public function setType(GH11386EnumType $type): static
53+
{
54+
$this->type = $type;
55+
56+
return $this;
57+
}
58+
59+
public function getCart(): GH11386EntityCart|null
60+
{
61+
return $this->cart;
62+
}
63+
64+
public function setCart(GH11386EntityCart|null $cart): self
65+
{
66+
// unset the owning side of the relation if necessary
67+
if ($cart === null && $this->cart !== null) {
68+
$this->cart->setCustomer(null);
69+
}
70+
71+
// set the owning side of the relation if necessary
72+
if ($cart !== null && $cart->getCustomer() !== $this) {
73+
$cart->setCustomer($this);
74+
}
75+
76+
$this->cart = $cart;
77+
78+
return $this;
79+
}
80+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386;
6+
7+
enum GH11386EnumType: int
8+
{
9+
case MALE = 1;
10+
case FEMALE = 2;
11+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386;
6+
7+
use Doctrine\Tests\OrmFunctionalTestCase;
8+
9+
final class GH11386Test extends OrmFunctionalTestCase
10+
{
11+
protected function setUp(): void
12+
{
13+
parent::setUp();
14+
15+
$this->createSchemaForModels(
16+
GH11386EntityCart::class,
17+
GH11386EntityCustomer::class,
18+
);
19+
}
20+
21+
public function testInitializeClonedProxy(): void
22+
{
23+
$cart = new GH11386EntityCart();
24+
$cart->setAmount(1000);
25+
26+
$customer = new GH11386EntityCustomer();
27+
$customer->setName('John Doe')
28+
->setType(GH11386EnumType::MALE)
29+
->setCart($cart);
30+
31+
$this->_em->persist($cart);
32+
$this->_em->flush();
33+
$this->_em->clear();
34+
35+
$cart = $this->_em->find(GH11386EntityCart::class, 1);
36+
$customer = clone $cart->getCustomer();
37+
self::assertEquals('John Doe', $customer->getName());
38+
}
39+
}

0 commit comments

Comments
 (0)