2017-06-28 20:40:25 +02:00
< ? php
namespace Doctrine\Tests\Functional\Ticket ;
use Doctrine\Common\Collections\ArrayCollection ;
use Doctrine\Tests\OrmFunctionalTestCase ;
/**
* @ group DDC - 6499
*/
class DDC6499Test extends OrmFunctionalTestCase
{
/**
* { @ inheritDoc }
*/
2017-06-29 17:16:35 +02:00
protected function setUp () : void
2017-06-28 20:40:25 +02:00
{
parent :: setUp ();
$this -> _schemaTool -> createSchema (
[
$this -> _em -> getClassMetadata ( DDC6499A :: class ),
$this -> _em -> getClassMetadata ( DDC6499B :: class ),
]
);
}
2017-06-29 17:16:35 +02:00
/**
* { @ inheritDoc }
*/
protected function tearDown () : void
{
parent :: tearDown ();
$this -> _schemaTool -> dropSchema (
[
$this -> _em -> getClassMetadata ( DDC6499A :: class ),
$this -> _em -> getClassMetadata ( DDC6499B :: class ),
]
);
}
2017-06-28 20:40:25 +02:00
/**
* Test for the bug described in issue #6499.
*/
2017-06-29 17:16:35 +02:00
public function testIssue () : void
2017-06-28 20:40:25 +02:00
{
$a = new DDC6499A ();
$this -> _em -> persist ( $a );
$b = new DDC6499B ();
2017-06-29 17:16:35 +02:00
$a -> b = $b ;
2017-06-28 20:40:25 +02:00
$this -> _em -> persist ( $b );
$this -> _em -> flush ();
2017-06-29 17:16:35 +02:00
$this -> _em -> clear ();
2017-06-28 20:40:25 +02:00
2017-06-29 17:16:35 +02:00
self :: assertEquals ( $this -> _em -> find ( DDC6499A :: class , $a -> id ) -> b -> id , $b -> id , " Issue #6499 will result in a Integrity constraint violation before reaching this point. " );
2017-06-28 20:40:25 +02:00
}
/**
2017-06-29 17:16:35 +02:00
* Test for the bug described in issue #6499 (reversed order).
2017-06-28 20:40:25 +02:00
*/
2017-06-29 17:16:35 +02:00
public function testIssueReversed () : void
2017-06-28 20:40:25 +02:00
{
2017-06-29 17:16:35 +02:00
$a = new DDC6499A ();
2017-06-28 20:40:25 +02:00
2017-06-29 17:16:35 +02:00
$b = new DDC6499B ();
$a -> b = $b ;
2017-06-28 20:40:25 +02:00
2017-06-29 17:16:35 +02:00
$this -> _em -> persist ( $b );
$this -> _em -> persist ( $a );
2017-06-28 20:40:25 +02:00
2017-06-29 17:16:35 +02:00
$this -> _em -> flush ();
$this -> _em -> clear ();
2017-06-28 20:40:25 +02:00
2017-06-29 17:16:35 +02:00
self :: assertEquals ( $this -> _em -> find ( DDC6499A :: class , $a -> id ) -> b -> id , $b -> id , " Issue #6499 will result in a Integrity constraint violation before reaching this point. " );
2017-06-28 20:40:25 +02:00
}
2017-06-29 17:16:35 +02:00
}
2017-06-28 20:40:25 +02:00
2017-06-29 17:16:35 +02:00
/** @Entity */
class DDC6499A
{
2017-06-28 20:40:25 +02:00
/**
2017-06-29 17:16:35 +02:00
* @ Id @ Column ( type = " integer " ) @ GeneratedValue
2017-06-28 20:40:25 +02:00
*/
2017-06-29 17:16:35 +02:00
public $id ;
2017-06-28 20:40:25 +02:00
/**
2017-06-29 17:16:35 +02:00
* @ OneToOne ( targetEntity = " DDC6499B " )
* @ JoinColumn ( nullable = false )
2017-06-28 20:40:25 +02:00
*/
2017-06-29 17:16:35 +02:00
public $b ;
2017-06-28 20:40:25 +02:00
}
/** @Entity */
class DDC6499B
{
/**
2017-06-29 17:16:35 +02:00
* @ Id @ Column ( type = " integer " ) @ GeneratedValue
2017-06-28 20:40:25 +02:00
*/
2017-06-29 17:16:35 +02:00
public $id ;
2017-06-28 20:40:25 +02:00
/**
2017-06-29 17:16:35 +02:00
* @ ManyToOne ( targetEntity = " DDC6499A " , inversedBy = " bs " )
2017-06-28 20:40:25 +02:00
*/
2017-06-29 17:16:35 +02:00
public $a ;
2017-06-28 20:40:25 +02:00
}