Skip to content

Commit

Permalink
Update test as suggested in doctrine#10868 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Aug 5, 2023
1 parent ec85d4e commit cfd17f0
Showing 1 changed file with 128 additions and 11 deletions.
139 changes: 128 additions & 11 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH10868Test.php
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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';

public function __construct(GH10868Shop $shop = null, int $id = null)
{
$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
Expand Down

0 comments on commit cfd17f0

Please sign in to comment.