diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php new file mode 100644 index 000000000..d3b9b16c1 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php @@ -0,0 +1,52 @@ +id1 = $id1; + $this->otherParent = $otherParent; + $this->parents = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php new file mode 100644 index 000000000..04e27e616 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php @@ -0,0 +1,23 @@ +id = $id; + } +} diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php new file mode 100644 index 000000000..3007a1013 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php @@ -0,0 +1,39 @@ +id = $id; + $this->children = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php new file mode 100644 index 000000000..989fc8493 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php @@ -0,0 +1,53 @@ +children->add($child); + $child->parents->add($parent); + + $em = $this->_getTestEntityManager(); + $em->persist($parent); + $em->flush(); + + /** @var ChildClass|null $childReloaded */ + $childReloaded = $em->find(ChildClass::class, ['id1' => 1, 'otherParent' => $otherParent]); + + self::assertNotNull($childReloaded); + + $persister = new ManyToManyPersister($em); + $persister->delete($childReloaded->parents); + + /** @var ConnectionMock $conn */ + $conn = $em->getConnection(); + + $updates = $conn->getExecuteUpdates(); + $lastUpdate = array_pop($updates); + + self::assertEquals('DELETE FROM parent_child WHERE child_id1 = ? AND child_id2 = ?', $lastUpdate['query']); + self::assertEquals([1, 42], $lastUpdate['params']); + } +}