Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\ORM\Tools\ToolsException;
/**
* @coversNothing
*/
class DDC9999Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
/**
* {@inheritDoc}
*/
public function setUp()
{
$this->enableSecondLevelCache();
parent::setUp();
$schemaValidator = new SchemaValidator($this->_em);
self::assertEmpty($schemaValidator->validateClass($this->_em->getClassMetadata(DDC999InverseSide::class)));
self::assertEmpty($schemaValidator->validateClass($this->_em->getClassMetadata(DDC9999OwningSide::class)));
try {
$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(DDC999InverseSide::class),
$this->_em->getClassMetadata(DDC9999OwningSide::class),
]);
} catch (ToolsException $ignored) {
}
}
public function testIssue()
{
$inverseSide = new DDC999InverseSide();
$owningSide = new DDC9999OwningSide();
$name = $inverseSide->name = uniqid('name', true);
$this->_em->persist($inverseSide);
$this->_em->flush();
$owningSide->owning = $inverseSide;
$inverseSide->inverse = $owningSide;
$this->_em->persist($owningSide);
$this->_em->flush();
$id = $inverseSide->id;
self::assertInternalType('integer', $inverseSide->id);
$this->_em->clear();
//$queryCountBeforeFind = $this->getCurrentQueryCount();
/* @var $fetchedInverseSide DDC999InverseSide */
//$fetchedInverseSide = $this->_em->getRepository(DDC999InverseSide::class)->findOneBy(['name' => $name]);
$fetchedInverseSide = $this->_em->getRepository(DDC999InverseSide::class)->find($id);
self::assertInstanceOf(DDC999InverseSide::class, $fetchedInverseSide);
self::assertSame($id, $fetchedInverseSide->id);
self::assertInstanceOf(DDC9999OwningSide::class, $fetchedInverseSide->inverse);
self::assertSame($fetchedInverseSide, $fetchedInverseSide->inverse->owning);
//self::assertSame($queryCountBeforeFind, $this->getCurrentQueryCount());
}
}
/**
* @Entity
*/
class DDC9999OwningSide
{
/**
* @Id
* @OneToOne(targetEntity=DDC999InverseSide::class, inversedBy="inverse")
* @JoinColumn(name="ddc9999_inverse_side_id", referencedColumnName="id")
*
* @var DDC999InverseSide|null
*/
public $owning;
}
/**
* @Entity
* @Cache(usage="NONSTRICT_READ_WRITE")
*/
class DDC999InverseSide
{
/**
* @OneToOne(targetEntity=DDC9999OwningSide::class, mappedBy="owning")
*
* @var DDC9999OwningSide|null
*/
public $inverse;
/**
* @Id
* @Column(name="id", type="integer")
* @GeneratedValue(strategy="IDENTITY")
*
* @var int
*/
public $id;
/**
* @Column(name="name", type="string", nullable=false)
*
* @var string
*/
public $name = 'foo';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment