mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add test for AddressReferenceBaseImporter
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user