From e1072fc8126de09535de7e141babea79eb08e0b7 Mon Sep 17 00:00:00 2001 From: Vladimir Klimes Date: Fri, 23 Aug 2024 11:15:39 +0200 Subject: [PATCH] test ManyToManyMultipleRelationshipSameTargetEntity with ID field of both common and custom names --- ...ultipleRelationshipCustomIdNamedEntity.php | 20 ++++++++++ tests/RelationTest.php | 37 ++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/Relation/ManyToManyMultipleRelationshipCustomIdNamedEntity.php diff --git a/tests/Fixtures/Relation/ManyToManyMultipleRelationshipCustomIdNamedEntity.php b/tests/Fixtures/Relation/ManyToManyMultipleRelationshipCustomIdNamedEntity.php new file mode 100644 index 00000000..35f8b447 --- /dev/null +++ b/tests/Fixtures/Relation/ManyToManyMultipleRelationshipCustomIdNamedEntity.php @@ -0,0 +1,20 @@ +addPrimaryTarget($targetOne); $manyToMany->addSecondaryTarget($targetTwo); + $targetThree = new ManyToManyMultipleTargetEntity(); + $targetFour = new ManyToManyMultipleTargetEntity(); + + $manyToManyWithCustomNameOfIdColumn = new ManyToManyMultipleRelationshipCustomIdNamedEntity(); + $manyToManyWithCustomNameOfIdColumn->setTitle('manyToMany#2'); + $manyToManyWithCustomNameOfIdColumn->addPrimaryTarget($targetThree); + $manyToManyWithCustomNameOfIdColumn->addSecondaryTarget($targetFour); + $em->persist($targetOne); $em->persist($targetTwo); + $em->persist($targetThree); + $em->persist($targetFour); $em->persist($manyToMany); + $em->persist($manyToManyWithCustomNameOfIdColumn); - $em->flush(); // #1 + $em->flush(); // #1 + #2 + // manyToMany#1 $manyToManyId = $manyToMany->getId(); static::assertNotNull($manyToManyId); @@ -399,6 +414,26 @@ public function testManyToManyMultipleRelationshipSameTargetEntity(): void // ensure that there is an audited entry for the secondaryTargets property static::assertInstanceOf(Collection::class, $audited->getSecondaryTargets()); static::assertCount(1, $audited->getSecondaryTargets()); + + // manyToMany#2 + $manyToManyId = $manyToManyWithCustomNameOfIdColumn->getId(); + static::assertNotNull($manyToManyId); + + $audited = $auditReader->find( + ManyToManyMultipleRelationshipCustomIdNamedEntity::class, + $manyToManyId, + 1 + ); + + static::assertNotNull($audited); + + // ensure that there is an audited entry for the primaryTargets property + static::assertInstanceOf(Collection::class, $audited->getPrimaryTargets()); + static::assertCount(1, $audited->getPrimaryTargets()); + + // ensure that there is an audited entry for the secondaryTargets property + static::assertInstanceOf(Collection::class, $audited->getSecondaryTargets()); + static::assertCount(1, $audited->getSecondaryTargets()); } /**