-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update test as suggested in #10868 (comment)
- Loading branch information
Showing
1 changed file
with
128 additions
and
11 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
|
@@ -14,33 +15,49 @@ protected function setUp(): void | |
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
GH10868AcceptanceItem::class, | ||
GH10868Shop::class, | ||
GH10868Offer::class, | ||
GH10868Order::class, | ||
GH10868OrderProduct::class, | ||
]); | ||
} | ||
|
||
public function testReferenceAndLazyLoadProxyAreTheSame(): void | ||
{ | ||
$offer = new GH10868Offer(); | ||
$acceptanceItem = new GH10868AcceptanceItem(); | ||
$acceptanceItem->offer = $offer; | ||
$shop = new GH10868Shop(); | ||
$offer = new GH10868Offer($shop, 1); | ||
$order = new GH10868Order(); | ||
$orderProduct = new GH10868OrderProduct(); | ||
|
||
$orderProduct->order = $order; | ||
$orderProduct->productOffer = $offer; | ||
$order->shop = $shop; | ||
$order->orderProducts->add($orderProduct); | ||
|
||
$this->_em->persist($shop); | ||
$this->_em->persist($offer); | ||
$this->_em->persist($acceptanceItem); | ||
$this->_em->persist($order); | ||
$this->_em->persist($orderProduct); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$reference = $this->_em->getReference(GH10868Offer::class, $offer->id); | ||
$acceptanceItemReloaded = $this->_em->find(GH10868AcceptanceItem::class, $acceptanceItem->id); | ||
$order->orderProducts->count(); | ||
|
||
$reference = $this->_em->getReference(GH10868Offer::class, [ | ||
'shop' => $shop->id, | ||
'id' => $offer->id, | ||
]); | ||
|
||
$orderProductFromOrder = $order->orderProducts->first(); | ||
|
||
self::assertSame($reference, $acceptanceItemReloaded->offer); | ||
self::assertSame($reference, $orderProductFromOrder->productOffer); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10868AcceptanceItem | ||
class GH10868Order | ||
{ | ||
/** | ||
* @ORM\Id | ||
|
@@ -52,17 +69,117 @@ class GH10868AcceptanceItem | |
public $id; | ||
|
||
/** | ||
* @ORM\OneToOne(targetEntity="GH10868Offer") | ||
* @ORM\ManyToOne(targetEntity="GH10868Shop") | ||
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id", nullable=false) | ||
* | ||
* @var GH10868Shop | ||
*/ | ||
public $shop; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="GH10868OrderProduct", mappedBy="order") | ||
* | ||
* @var GH10868OrderProduct | ||
*/ | ||
public $orderProducts; | ||
|
||
public function __construct() | ||
{ | ||
$this->orderProducts = new ArrayCollection(); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10868OrderProduct | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
* | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH10868Order", inversedBy="orderProducts", fetch="EXTRA_LAZY") | ||
* @ORM\JoinColumn(name="order_id", referencedColumnName="id") | ||
* | ||
* @var GH10868Order | ||
*/ | ||
public $order; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH10868Shop") | ||
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id") | ||
* | ||
* @var GH10868Shop | ||
*/ | ||
public $shop; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH10868Offer", fetch="EXTRA_LAZY") | ||
* @ORM\JoinColumns({ | ||
* @ORM\JoinColumn(name="productoffer_id", referencedColumnName="id"), | ||
* @ORM\JoinColumn(name="shop_id", referencedColumnName="shop_id") | ||
* }) | ||
* | ||
* @var GH10868Offer | ||
*/ | ||
public $offer; | ||
public $productOffer; | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10868Offer | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="NONE") | ||
* @ORM\Column(type="bigint") | ||
* | ||
* @var ?int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="NONE") | ||
* @ORM\ManyToOne(targetEntity="GH10868Shop") | ||
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id") | ||
* | ||
* @var GH10868Shop | ||
*/ | ||
protected $shop; | ||
|
||
protected $name = 'Test'; | ||
Check failure on line 158 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH10868Test.php GitHub Actions / coding-standards / Coding Standards (8.2)
|
||
|
||
public function __construct(GH10868Shop $shop = null, int $id = null) | ||
Check failure on line 160 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH10868Test.php GitHub Actions / coding-standards / Coding Standards (8.2)
|
||
{ | ||
$this->shop = $shop; | ||
$this->id = $id; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): GH10868Offer | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10868Shop | ||
{ | ||
/** | ||
* @ORM\Id | ||
|