Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Try to) add a reproducer for #10868 #10873

Draft
wants to merge 2 commits into
base: 2.16.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
192 changes: 192 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH10868Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH10868Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->setUpEntitySchema([
GH10868Shop::class,
GH10868Offer::class,
GH10868Order::class,
GH10868OrderProduct::class,
]);
}

public function testReferenceAndLazyLoadProxyAreTheSame(): void
{
$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($order);
$this->_em->persist($orderProduct);
$this->_em->flush();
$this->_em->clear();

$order->orderProducts->count();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do that, since $order belongs to an EM instance that has been cleared.


$reference = $this->_em->getReference(GH10868Offer::class, [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reference (proxy) for a GH10868Offer object.

'shop' => $shop->id,
'id' => $offer->id,
]);

$orderProductFromOrder = $order->orderProducts->first();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do anything off $order, since it is an entity from an EM that has been cleared.


self::assertSame($reference, $orderProductFromOrder->productOffer);
}
}

/**
* @ORM\Entity
*/
class GH10868Order
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @var ?int
*/
public $id;

/**
* @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 $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

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Property \Doctrine\Tests\ORM\Functional\Ticket\GH10868Offer::$name does not have @var annotation for its value.

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
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @var ?int
*/
public $id;
}