mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
90 lines
2.7 KiB
PHP
90 lines
2.7 KiB
PHP
<?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());
|
|
|
|
$previousAddressId = $addresses[0]->getId();
|
|
|
|
$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());
|
|
$this->assertEquals($previousAddressId, $addresses[0]->getId());
|
|
}
|
|
|
|
|
|
} |