Skip to content

Commit

Permalink
Add a test for #7006
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Feb 28, 2023
1 parent 3f767a5 commit ba8c3dd
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
Expand Down
142 changes: 110 additions & 32 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7006Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group GH6499
*
* Specifically, GH6499B has a dependency on GH6499A, and GH6499A
* has a dependency on GH6499B. Since GH6499A#b is not nullable,
* the GH6499B should be inserted first.
*/
class GH6499Test extends OrmFunctionalTestCase
class GH7006Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(GH6499A::class),
$this->_em->getClassMetadata(GH6499B::class),
$this->_em->getClassMetadata(GH7006Book::class),
$this->_em->getClassMetadata(GH7006PCT::class),
$this->_em->getClassMetadata(GH7006PCTFee::class),
]);
}

Expand All @@ -32,41 +26,125 @@ protected function tearDown(): void
parent::tearDown();

$this->_schemaTool->dropSchema([
$this->_em->getClassMetadata(GH6499A::class),
$this->_em->getClassMetadata(GH6499B::class),
$this->_em->getClassMetadata(GH7006Book::class),
$this->_em->getClassMetadata(GH7006PCT::class),
$this->_em->getClassMetadata(GH7006PCTFee::class),
]);
}

public function testIssue(): void
{
$b = new GH6499B();
$a = new GH6499A();
$book = new GH7006Book();
$book->exchangeCode = 'first';
$this->_em->persist($book);

$this->_em->persist($a);
$book->exchangeCode = 'second'; // change sth.

$a->b = $b;
$paymentCardTransaction = new GH7006PCT();
$paymentCardTransaction->book = $book;
$paymentCardTransactionFee = new GH7006PCTFee($paymentCardTransaction);

$this->_em->persist($b);
$this->_em->persist($paymentCardTransaction);

$this->_em->flush();

self::assertIsInt($a->id);
self::assertIsInt($b->id);
self::assertIsInt($book->id);
self::assertIsInt($paymentCardTransaction->id);
self::assertIsInt($paymentCardTransactionFee->id);
}
}

public function testIssueReversed(): void
{
$b = new GH6499B();
$a = new GH6499A();

$a->b = $b;

$this->_em->persist($b);
$this->_em->persist($a);
/**
* @ORM\Entity
*/
class GH7006Book
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var int
*/
public $id;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
public $exchangeCode;

/**
* @ORM\OneToOne(targetEntity="GH7006PCT", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="paymentCardTransactionId", referencedColumnName="id")
*
* @var GH7006PCT
*/
public $paymentCardTransaction;
}

$this->_em->flush();
/**
* @ORM\Entity
*/
class GH7006PCT
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var int
*/
public $id;

/**
* @ORM\ManyToOne(targetEntity="GH7006Book")
* @ORM\JoinColumn(name="bookingId", referencedColumnName="id", nullable=false)
*
* @var GH7006Book
*/
public $book;

/**
* @ORM\OneToMany(targetEntity="GH7006PCTFee", mappedBy="pct", cascade={"persist", "remove"})
* @ORM\OrderBy({"id" = "ASC"})
*
* @var GH7006PCTFee[]
*/
public $fees;

public function __construct()
{
$this->fees = new ArrayCollection();
}
}

self::assertIsInt($a->id);
self::assertIsInt($b->id);
/**
* @ORM\Entity
*/
class GH7006PCTFee
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var int
*/
public $id;

/**
* @ORM\ManyToOne(targetEntity="GH7006PCT", inversedBy="fees")
* @ORM\JoinColumn(name="paymentCardTransactionId", referencedColumnName="id", nullable=false)
*
* @var GH7006PCT
*/
public $pct;

public function __construct(GH7006PCT $pct)
{
$this->pct = $pct;
$pct->fees->add($this);
}
}

0 comments on commit ba8c3dd

Please sign in to comment.