mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Services\Import;
|
|
|
|
use Chill\MainBundle\Repository\CountryRepository;
|
|
use Chill\MainBundle\Repository\PostalCodeRepository;
|
|
use Chill\MainBundle\Service\Import\PostalCodeBaseImporter;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
class PostalCodeBaseImporterTest extends KernelTestCase
|
|
{
|
|
private EntityManagerInterface $entityManager;
|
|
|
|
private PostalCodeBaseImporter $importer;
|
|
|
|
private PostalCodeRepository $postalCodeRepository;
|
|
|
|
private CountryRepository $countryRepository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
self::bootKernel();
|
|
|
|
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
|
$this->importer = self::$container->get(PostalCodeBaseImporter::class);
|
|
$this->postalCodeRepository = self::$container->get(PostalCodeRepository::class);
|
|
$this->countryRepository = self::$container->get(CountryRepository::class);
|
|
}
|
|
|
|
public function testImportPostalCode(): void
|
|
{
|
|
$this->importer->importCode(
|
|
'BE',
|
|
'tested with pattern '. ($uniqid = uniqid()),
|
|
'12345',
|
|
$refPostalCodeId = 'test'.uniqid(),
|
|
'test',
|
|
50.0,
|
|
5.0,
|
|
4326
|
|
);
|
|
|
|
$this->importer->finalize();
|
|
|
|
$postalCodes = $this->postalCodeRepository->findByPattern(
|
|
'with pattern '.$uniqid,
|
|
$this->countryRepository->findOneBy(['countryCode' => 'BE'])
|
|
);
|
|
|
|
$this->assertCount(1, $postalCodes);
|
|
$this->assertStringStartsWith('tested with pattern', $postalCodes[0]->getName());
|
|
|
|
$previousId = $postalCodes[0]->getId();
|
|
|
|
$this->entityManager->clear();
|
|
|
|
$this->importer->importCode(
|
|
'BE',
|
|
'tested with adapted pattern '. ($uniqid = uniqid()),
|
|
'12345',
|
|
$refPostalCodeId,
|
|
'test',
|
|
50.0,
|
|
5.0,
|
|
4326
|
|
);
|
|
|
|
$this->importer->finalize();
|
|
|
|
$postalCodes = $this->postalCodeRepository->findByPattern(
|
|
'with pattern '.$uniqid,
|
|
$this->countryRepository->findOneBy(['countryCode' => 'BE'])
|
|
);
|
|
|
|
$this->assertCount(1, $postalCodes);
|
|
$this->assertStringStartsWith('tested with adapted pattern', $postalCodes[0]->getName());
|
|
$this->assertEquals($previousId, $postalCodes[0]->getId());
|
|
}
|
|
|
|
|
|
|
|
} |