Skip to content

Commit

Permalink
add test to demonstrate doctrine#6499 persistence ordering bug on non…
Browse files Browse the repository at this point in the history
…-nullable cascading relationship
  • Loading branch information
rvanlaak committed May 20, 2021
1 parent 535bc92 commit 135c9cd
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group DDC-6499
*/
class DDC6499Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC6499A::class),
$this->_em->getClassMetadata(DDC6499B::class),
]
);
}

protected function tearDown(): void
{
parent::tearDown();

$this->_schemaTool->dropSchema(
[
$this->_em->getClassMetadata(DDC6499A::class),
$this->_em->getClassMetadata(DDC6499B::class),
]
);
}

/**
* Test for the bug described in issue #6499.
*/
public function testIssue(): void
{
$a = new DDC6499A();

$this->_em->flush();
$this->_em->clear();

self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $a->b->id, 'Issue #6499 will result in a Integrity constraint violation before reaching this point.');
}
}

/** @Entity */
class DDC6499A
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;

/**
* @OneToOne(targetEntity="DDC6499B", cascade={"persist"})
* @JoinColumn(nullable=false)
*/
public $b;

public function __construct()
{
$this->b = new DDC6499B();
}
}

/** @Entity */
class DDC6499B
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;
}

0 comments on commit 135c9cd

Please sign in to comment.