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
|
<?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;
#[Group('GH6499')]
class GH6499OneToOneRelationshipTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->createSchemaForModels(GH6499OTOA::class, GH6499OTOB::class);
}
/**
* Test for the bug described in issue #6499.
*/
public function testIssue(): void
{
$a = new GH6499OTOA();
$this->_em->persist($a);
$this->_em->flush();
$this->_em->clear();
self::assertEquals(
$this->_em->find(GH6499OTOA::class, $a->id)->b->id,
$a->b->id,
'Issue #6499 will result in an integrity constraint violation before reaching this point.',
);
}
}
#[ORM\Entity]
class GH6499OTOA
{
/** @var int */
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
public $id;
/** @var GH6499OTOB */
#[ORM\OneToOne(targetEntity: GH6499OTOB::class, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false)]
public $b;
public function __construct()
{
$this->b = new GH6499OTOB();
}
}
#[ORM\Entity]
class GH6499OTOB
{
/** @var int */
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
public $id;
}
|