forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproduce exception on same class relation
- Loading branch information
1 parent
85ac276
commit 2abff4c
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
tests/Doctrine/Tests/Models/GH10348/GH10348ChildEntity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\GH10348; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="gh10348_child_entities") | ||
*/ | ||
#[ORM\Entity] | ||
#[ORM\Table(name: 'gh10348_child_entities')] | ||
class GH10348ChildEntity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
*/ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'integer')] | ||
#[ORM\GeneratedValue] | ||
private ?int $id = null; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH10348ParentEntity", inversedBy="children") | ||
*/ | ||
#[ORM\ManyToOne(targetEntity: GH10348ParentEntity::class, inversedBy: 'children')] | ||
private ?GH10348ParentEntity $parent = null; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH10348ChildEntity", cascade={"remove"}) | ||
*/ | ||
#[ORM\ManyToOne(targetEntity: GH10348ChildEntity::class, cascade: ['remove'])] | ||
private ?GH10348ChildEntity $origin = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(?int $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getParent(): ?GH10348ParentEntity | ||
{ | ||
return $this->parent; | ||
} | ||
|
||
public function setParent(?GH10348ParentEntity $parent): void | ||
{ | ||
$this->parent = $parent; | ||
} | ||
|
||
public function getOrigin(): ?GH10348ChildEntity | ||
{ | ||
return $this->origin; | ||
} | ||
|
||
public function setOrigin(?GH10348ChildEntity $origin): void | ||
{ | ||
$this->origin = $origin; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/Doctrine/Tests/Models/GH10348/GH10348ParentEntity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\GH10348; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="gh10348_parent_entities") | ||
*/ | ||
#[ORM\Entity] | ||
#[ORM\Table(name: 'gh10348_parent_entities')] | ||
class GH10348ParentEntity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
*/ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'integer')] | ||
#[ORM\GeneratedValue] | ||
private ?int $id = null; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="GH10348ChildEntity", mappedBy="parent", cascade={"persist", "remove"}) | ||
*/ | ||
#[ORM\OneToMany(targetEntity: GH10348ChildEntity::class, mappedBy: 'parent', cascade: ['persist', 'remove'])] | ||
private Collection $children; | ||
|
||
public function __construct() | ||
{ | ||
$this->children = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function addChild(GH10348ChildEntity $childEntity): self | ||
{ | ||
$childEntity->setParent($this); | ||
$this->children->add($childEntity); | ||
|
||
return $this; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/Doctrine/Tests/ORM/Functional/Ticket/GH10348Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Mapping\Driver\AttributeDriver; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use Doctrine\Tests\Models\GH10348\GH10348ChildEntity; | ||
use Doctrine\Tests\Models\GH10348\GH10348ParentEntity; | ||
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->setOrigin($child1); | ||
|
||
$parent = new GH10348ParentEntity(); | ||
$parent->addChild($child1)->addChild($child2); | ||
|
||
$this->_em->persist($parent); | ||
$this->_em->flush(); | ||
|
||
$parent = $this->_em->find(GH10348ParentEntity::class, $parent->getId()); | ||
|
||
$this->_em->remove($parent); | ||
|
||
$this->assertNull($this->_em->flush()); | ||
} | ||
} |