Skip to content

Commit

Permalink
Include a functional test for issue #10348
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Pigulla <mp@webfactory.de>
  • Loading branch information
simonberger and mpdude committed Mar 6, 2023
1 parent 632e855 commit 3917692
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH10348Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

final class GH10348Test extends OrmFunctionalTestCase
{
public function setUp(): void
{
parent::setUp();

$this->setUpEntitySchema([
GH10348ChildEntity::class,
GH10348ParentEntity::class,
]);
}

public function testCanRemoveParentWithChildRelatesToOwnEntity(): void
{
$child1 = new GH10348ChildEntity();
$child2 = new GH10348ChildEntity();
$child2->origin = $child1;

$parent = new GH10348ParentEntity();
$parent->addChild($child1)->addChild($child2);

$this->_em->persist($parent);
$this->_em->flush();

$parent = $this->_em->find(GH10348ParentEntity::class, $parent->id);

$this->_em->remove($parent);

$this->expectNotToPerformAssertions();
$this->_em->flush();
}
}

/**
* @ORM\Entity
* @ORM\Table(name="gh10348_child_entities")
*/
class GH10348ChildEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*
* @var ?int
*/
public $id = null;

/**
* @ORM\ManyToOne(targetEntity="GH10348ParentEntity", inversedBy="children")
*
* @var ?GH10348ParentEntity
*/
public $parent = null;

/**
* @ORM\ManyToOne(targetEntity="GH10348ChildEntity", cascade={"remove"})
*
* @var ?GH10348ChildEntity
*/
public $origin = null;
}

/**
* @ORM\Entity
* @ORM\Table(name="gh10348_parent_entities")
*/
class GH10348ParentEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*
* @var ?int
*/
public $id = null;

/**
* @ORM\OneToMany(targetEntity="GH10348ChildEntity", mappedBy="parent", cascade={"persist", "remove"})
*
* @var Collection
*/
private $children;

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

public function addChild(GH10348ChildEntity $childEntity): self
{
$childEntity->parent = $this;
$this->children->add($childEntity);

return $this;
}
}

0 comments on commit 3917692

Please sign in to comment.