forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request doctrine#11387 from valkars/enum-reflection
Fixed proxy initialization for EnumReflectionProperty
- Loading branch information
Showing
5 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tests/Tests/ORM/Functional/Ticket/GH11386/GH11386EntityCart.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\GeneratedValue; | ||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\OneToOne; | ||
|
||
#[Entity] | ||
class GH11386EntityCart | ||
{ | ||
#[Id] | ||
#[GeneratedValue] | ||
#[Column] | ||
private int|null $id = null; | ||
|
||
#[Column] | ||
private int|null $amount = null; | ||
|
||
#[OneToOne(inversedBy: 'cart', cascade: ['persist', 'remove'], orphanRemoval: true)] | ||
private GH11386EntityCustomer|null $customer = null; | ||
|
||
public function getId(): int|null | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getAmount(): int|null | ||
{ | ||
return $this->amount; | ||
} | ||
|
||
public function setAmount(int $amount): static | ||
{ | ||
$this->amount = $amount; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCustomer(): GH11386EntityCustomer|null | ||
{ | ||
return $this->customer; | ||
} | ||
|
||
public function setCustomer(GH11386EntityCustomer|null $customer): self | ||
{ | ||
$this->customer = $customer; | ||
|
||
return $this; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
tests/Tests/ORM/Functional/Ticket/GH11386/GH11386EntityCustomer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\GeneratedValue; | ||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\OneToOne; | ||
|
||
#[Entity] | ||
class GH11386EntityCustomer | ||
{ | ||
#[Id] | ||
#[GeneratedValue] | ||
#[Column] | ||
private int|null $id = null; | ||
|
||
#[Column] | ||
private string|null $name = null; | ||
|
||
#[Column(type: 'smallint', nullable: true, enumType: GH11386EnumType::class, options: ['unsigned' => true])] | ||
private GH11386EnumType|null $type = null; | ||
|
||
#[OneToOne(mappedBy: 'customer')] | ||
private GH11386EntityCart|null $cart = null; | ||
|
||
public function getId(): int|null | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): string|null | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): static | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getType(): GH11386EnumType|null | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function setType(GH11386EnumType $type): static | ||
{ | ||
$this->type = $type; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCart(): GH11386EntityCart|null | ||
{ | ||
return $this->cart; | ||
} | ||
|
||
public function setCart(GH11386EntityCart|null $cart): self | ||
{ | ||
// unset the owning side of the relation if necessary | ||
if ($cart === null && $this->cart !== null) { | ||
$this->cart->setCustomer(null); | ||
} | ||
|
||
// set the owning side of the relation if necessary | ||
if ($cart !== null && $cart->getCustomer() !== $this) { | ||
$cart->setCustomer($this); | ||
} | ||
|
||
$this->cart = $cart; | ||
|
||
return $this; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Tests/ORM/Functional/Ticket/GH11386/GH11386EnumType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386; | ||
|
||
enum GH11386EnumType: int | ||
{ | ||
case MALE = 1; | ||
case FEMALE = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11386; | ||
|
||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
final class GH11386Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createSchemaForModels( | ||
GH11386EntityCart::class, | ||
GH11386EntityCustomer::class, | ||
); | ||
} | ||
|
||
public function testInitializeClonedProxy(): void | ||
{ | ||
$cart = new GH11386EntityCart(); | ||
$cart->setAmount(1000); | ||
|
||
$customer = new GH11386EntityCustomer(); | ||
$customer->setName('John Doe') | ||
->setType(GH11386EnumType::MALE) | ||
->setCart($cart); | ||
|
||
$this->_em->persist($cart); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$cart = $this->_em->find(GH11386EntityCart::class, 1); | ||
$customer = clone $cart->getCustomer(); | ||
self::assertEquals('John Doe', $customer->getName()); | ||
} | ||
} |