mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
Resolve manyToMany cases
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user