1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
/**
* Specifically, GH6499B has a dependency on GH6499A, and GH6499A
* has a dependency on GH6499B. Since GH6499A#b is not nullable,
* the database row for GH6499B should be inserted first.
*/
#[Group('GH6499')]
class GH6499Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->createSchemaForModels(GH6499A::class, GH6499B::class);
}
public function testIssue(): void
{
$b = new GH6499B();
$a = new GH6499A();
$this->_em->persist($a);
$a->b = $b;
$this->_em->persist($b);
$this->_em->flush();
self::assertIsInt($a->id);
self::assertIsInt($b->id);
}
public function testIssueReversed(): void
{
$b = new GH6499B();
$a = new GH6499A();
$a->b = $b;
$this->_em->persist($b);
$this->_em->persist($a);
$this->_em->flush();
self::assertIsInt($a->id);
self::assertIsInt($b->id);
}
}
#[ORM\Entity]
class GH6499A
{
/** @var int */
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
public $id;
/** @var GH6499B */
#[ORM\JoinColumn(nullable: false)]
#[ORM\OneToOne(targetEntity: GH6499B::class)]
public $b;
}
#[ORM\Entity]
class GH6499B
{
/** @var int */
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
public $id;
/** @var GH6499A */
#[ORM\ManyToOne(targetEntity: GH6499A::class)]
private $a;
}
|