mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add test for AddressReferenceBaseImporter
This commit is contained in:
parent
0f63548d5a
commit
658e846120
@ -73,7 +73,7 @@ final class AddressReferenceBaseImporter
|
||||
|
||||
public function importAddress(
|
||||
string $refAddress,
|
||||
string $refPostalCode,
|
||||
?string $refPostalCode,
|
||||
string $postalCode,
|
||||
string $street,
|
||||
string $streetNumber,
|
||||
@ -157,7 +157,11 @@ final class AddressReferenceBaseImporter
|
||||
$statement = $this->cachingStatements[$forNumber];
|
||||
|
||||
try {
|
||||
$statement->executeStatement(array_merge(...$this->waitingForInsert));
|
||||
$affected = $statement->executeStatement(array_merge(...$this->waitingForInsert));
|
||||
|
||||
if ($affected === 0) {
|
||||
throw new \RuntimeException('no row affected');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// in some case, we can add debug code here
|
||||
//dump($this->waitingForInsert);
|
||||
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Services\Import;
|
||||
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Repository\AddressReferenceRepository;
|
||||
use Chill\MainBundle\Repository\PostalCodeRepository;
|
||||
use Chill\MainBundle\Service\Import\AddressReferenceBaseImporter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class AddressReferenceBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
private AddressReferenceBaseImporter $importer;
|
||||
private AddressReferenceRepository $addressReferenceRepository;
|
||||
private EntityManagerInterface $entityManager;
|
||||
private PostalCodeRepository $postalCodeRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
self::bootKernel();
|
||||
|
||||
$this->importer = self::$container->get(AddressReferenceBaseImporter::class);
|
||||
$this->addressReferenceRepository = self::$container->get(AddressReferenceRepository::class);
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
$this->postalCodeRepository = self::$container->get(PostalCodeRepository::class);
|
||||
}
|
||||
|
||||
public function testImportAddress(): void
|
||||
{
|
||||
$postalCode = (new PostalCode())
|
||||
->setRefPostalCodeId($postalCodeId = '1234'.uniqid())
|
||||
->setPostalCodeSource('testing')
|
||||
->setCode('TEST456')
|
||||
->setName('testing');
|
||||
|
||||
$this->entityManager->persist($postalCode);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->importer->importAddress(
|
||||
'0000',
|
||||
$postalCodeId,
|
||||
'TEST456',
|
||||
'Rue test abccc-guessed',
|
||||
'-1',
|
||||
'unit-test',
|
||||
50.0,
|
||||
5.0,
|
||||
4326
|
||||
);
|
||||
|
||||
$this->importer->finalize();
|
||||
|
||||
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
|
||||
$postalCode,
|
||||
'Rue test abcc guessed');
|
||||
|
||||
$this->assertCount(1, $addresses);
|
||||
$this->assertEquals('Rue test abccc-guessed', $addresses[0]->getStreet());
|
||||
|
||||
$this->entityManager->clear();
|
||||
|
||||
$this->importer->importAddress(
|
||||
'0000',
|
||||
$postalCodeId,
|
||||
'TEST456',
|
||||
'Rue test abccc guessed fixed',
|
||||
'-1',
|
||||
'unit-test',
|
||||
50.0,
|
||||
5.0,
|
||||
4326
|
||||
);
|
||||
|
||||
$this->importer->finalize();
|
||||
|
||||
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
|
||||
$postalCode,
|
||||
'abcc guessed fixed');
|
||||
|
||||
$this->assertCount('1', $addresses);
|
||||
$this->assertEquals( 'Rue test abccc guessed fixed', $addresses[0]->getStreet());
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user