Skip to content

Commit

Permalink
Cherry-pick (and slightly simplify) tests from doctrine#9377
Browse files Browse the repository at this point in the history
Co-authored-by: Josef Šupka <[email protected]>
  • Loading branch information
mpdude and jusephe committed Feb 27, 2023
1 parent f9a8d11 commit eee75bf
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH9376Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH9376Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(GH9376GiftVariant::class),
$this->_em->getClassMetadata(GH9376Product::class),
$this->_em->getClassMetadata(GH9376Gift::class),
]);
}

protected function tearDown(): void
{
$this->_schemaTool->dropSchema([
$this->_em->getClassMetadata(GH9376GiftVariant::class),
$this->_em->getClassMetadata(GH9376Product::class),
$this->_em->getClassMetadata(GH9376Gift::class),
]);

parent::tearDown();
}

public function testRemoveCircularRelatedEntities(): void
{
if (! $this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
self::markTestSkipped('Platform does not support foreign keys.');
}

$product = new GH9376Product();
$gift = new GH9376Gift($product);
$giftVariant = new GH9376GiftVariant($gift);

$this->_em->persist($product);
$this->_em->persist($gift);
$this->_em->persist($giftVariant);
$this->_em->flush();
$this->_em->clear();

$persistedGiftVariant = $this->_em->find(GH9376GiftVariant::class, 1);
$this->_em->remove($persistedGiftVariant);

$persistedGift = $this->_em->find(GH9376Gift::class, 1);
$this->_em->remove($persistedGift);

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

self::assertEmpty($this->_em->getRepository(GH9376Gift::class)->findAll());
self::assertEmpty($this->_em->getRepository(GH9376GiftVariant::class)->findAll());
}
}

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

/**
* @ORM\ManyToOne(targetEntity=GH9376Gift::class)
* @ORM\JoinColumn(nullable=false)
*
* @var GH9376Gift
*/
public $gift;

public function __construct(GH9376Gift $gift)
{
$this->gift = $gift;
}
}

/**
* @Entity
*/

class GH9376Product
{
/**
* @var int
* @Id @Column(type="integer")
* @GeneratedValue
*/
public $id;
}

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

/**
* @ORM\ManyToOne(targetEntity=GH9376Product::class)
* @ORM\JoinColumn(nullable=false)
*
* @var GH9376Product
*/
public $product;

public function __construct(GH9376Product $product)
{
$this->product = $product;
}
}

0 comments on commit eee75bf

Please sign in to comment.