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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
/**
* Tests suggested in https://github.com/doctrine/orm/pull/7180#issuecomment-380841413 and
* https://github.com/doctrine/orm/pull/7180#issuecomment-381067448.
*/
#[Group('GH7180')]
final class GH7180Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->setUpEntitySchema([GH7180A::class, GH7180B::class, GH7180C::class, GH7180D::class, GH7180E::class, GH7180F::class, GH7180G::class]);
}
public function testIssue(): void
{
$a = new GH7180A();
$b = new GH7180B();
$c = new GH7180C();
$a->b = $b;
$b->a = $a;
$c->a = $a;
$this->_em->persist($a);
$this->_em->persist($b);
$this->_em->persist($c);
$this->_em->flush();
self::assertIsInt($a->id);
self::assertIsInt($b->id);
self::assertIsInt($c->id);
}
public function testIssue3NodeCycle(): void
{
$d = new GH7180D();
$e = new GH7180E();
$f = new GH7180F();
$g = new GH7180G();
$d->e = $e;
$e->f = $f;
$f->d = $d;
$g->d = $d;
$this->_em->persist($d);
$this->_em->persist($e);
$this->_em->persist($f);
$this->_em->persist($g);
$this->_em->flush();
self::assertIsInt($d->id);
self::assertIsInt($e->id);
self::assertIsInt($f->id);
self::assertIsInt($g->id);
}
}
#[Entity]
class GH7180A
{
/** @var int */
#[GeneratedValue]
#[Id]
#[Column(type: 'integer')]
public $id;
/** @var GH7180B */
#[OneToOne(targetEntity: GH7180B::class, inversedBy: 'a')]
#[JoinColumn(nullable: false)]
public $b;
}
#[Entity]
class GH7180B
{
/** @var int */
#[GeneratedValue]
#[Id]
#[Column(type: 'integer')]
public $id;
/** @var GH7180A */
#[OneToOne(targetEntity: GH7180A::class, mappedBy: 'b')]
public $a;
}
#[Entity]
class GH7180C
{
/** @var int */
#[GeneratedValue]
#[Id]
#[Column(type: 'integer')]
public $id;
/** @var GH7180A */
#[ManyToOne(targetEntity: GH7180A::class)]
#[JoinColumn(nullable: false)]
public $a;
}
#[Entity]
class GH7180D
{
/** @var int */
#[GeneratedValue]
#[Id]
#[Column(type: 'integer')]
public $id;
/** @var GH7180E */
#[OneToOne(targetEntity: GH7180E::class)]
#[JoinColumn(nullable: false)]
public $e;
}
#[Entity]
class GH7180E
{
/** @var int */
#[GeneratedValue]
#[Id]
#[Column(type: 'integer')]
public $id;
/** @var GH7180F */
#[OneToOne(targetEntity: GH7180F::class)]
#[JoinColumn(nullable: false)]
public $f;
}
#[Entity]
class GH7180F
{
/** @var int */
#[GeneratedValue]
#[Id]
#[Column(type: 'integer')]
public $id;
/** @var GH7180D */
#[ManyToOne(targetEntity: GH7180D::class)]
#[JoinColumn(nullable: true)]
public $d;
}
#[Entity]
class GH7180G
{
/** @var int */
#[GeneratedValue]
#[Id]
#[Column(type: 'integer')]
public $id;
/** @var GH7180D */
#[ManyToOne(targetEntity: GH7180D::class)]
#[JoinColumn(nullable: false)]
public $d;
}
|