Resolve manyToMany cases

This commit is contained in:
2025-02-19 12:35:25 +01:00
parent 5999c73c98
commit 13b1d20ade
4 changed files with 57 additions and 23 deletions

View File

@@ -1,5 +1,14 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\ThirdPartyBundle\Tests\Service;
use Chill\ActivityBundle\Entity\Activity;
@@ -10,6 +19,11 @@ use Doctrine\ORM\EntityManagerInterface;
use libphonenumber\PhoneNumber;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
*
* @coversNothing
*/
class ThirdpartyMergeServiceTest extends KernelTestCase
{
private $mergeManager;
@@ -33,7 +47,7 @@ class ThirdpartyMergeServiceTest extends KernelTestCase
try {
// Rollback the transaction after each test to ensure no data is persisted
$this->connection->rollBack();
} catch (\Exception $e) {
} catch (\Exception) {
$this->connection->close();
}
@@ -47,7 +61,7 @@ class ThirdpartyMergeServiceTest extends KernelTestCase
$toKeep->setName('Thirdparty ToKeep');
$toKeep->setEmail('keep@example.com');
$toDelete = new Thirdparty();
$toDelete = new ThirdParty();
$toDelete->setName('Thirdparty ToDelete'); // This should be ignored
$toDelete->setTelephone(new PhoneNumber('123456789'));
@@ -69,7 +83,7 @@ class ThirdpartyMergeServiceTest extends KernelTestCase
$this->em->clear();
// Verify data was merged correctly
$mergedThirdparty = $this->em->getRepository(Thirdparty::class)->find($toKeep->getId());
$mergedThirdparty = $this->em->getRepository(ThirdParty::class)->find($toKeep->getId());
$this->assertNotNull($mergedThirdparty);
$this->assertEquals('Primary Name', $mergedThirdparty->getName(), 'Name should remain unchanged');
$this->assertEquals('keep@example.com', $mergedThirdparty->getEmail(), 'Email should remain unchanged');
@@ -82,7 +96,7 @@ class ThirdpartyMergeServiceTest extends KernelTestCase
'Activity should be linked to the merged Thirdparty'
);
$this->assertFalse(
$updatedActivity->getThirdParties()->exists(fn($key, $tp) => $tp->getId() === $toDelete->getId()),
$updatedActivity->getThirdParties()->exists(fn ($key, $tp) => $tp->getId() === $toDelete->getId()),
'Activity should no longer reference the deleted Thirdparty'
);
@@ -94,7 +108,7 @@ class ThirdpartyMergeServiceTest extends KernelTestCase
);
// Ensure the 'toDelete' entity is removed
$deletedThirdparty = $this->em->getRepository(Thirdparty::class)->find($toDelete->getId());
$deletedThirdparty = $this->em->getRepository(ThirdParty::class)->find($toDelete->getId());
$this->assertNull($deletedThirdparty, 'The deleted Thirdparty should no longer exist in the database');
}
}