From 8129739d27b76497e87d9c6e4e7932ed9d56b771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 17 Sep 2022 10:59:04 +0200 Subject: [PATCH] test for postal code base importer --- .../AddressReferenceBaseImporterTest.php | 3 + .../Import/PostalCodeBaseImporterTest.php | 85 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Tests/Services/Import/PostalCodeBaseImporterTest.php diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Import/AddressReferenceBaseImporterTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Import/AddressReferenceBaseImporterTest.php index d4302413e..cb23634f1 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/Import/AddressReferenceBaseImporterTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/Import/AddressReferenceBaseImporterTest.php @@ -59,6 +59,8 @@ class AddressReferenceBaseImporterTest extends KernelTestCase $this->assertCount(1, $addresses); $this->assertEquals('Rue test abccc-guessed', $addresses[0]->getStreet()); + $previousAddressId = $addresses[0]->getId(); + $this->entityManager->clear(); $this->importer->importAddress( @@ -81,6 +83,7 @@ class AddressReferenceBaseImporterTest extends KernelTestCase $this->assertCount('1', $addresses); $this->assertEquals( 'Rue test abccc guessed fixed', $addresses[0]->getStreet()); + $this->assertEquals($previousAddressId, $addresses[0]->getId()); } diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Import/PostalCodeBaseImporterTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Import/PostalCodeBaseImporterTest.php new file mode 100644 index 000000000..826e581ac --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Services/Import/PostalCodeBaseImporterTest.php @@ -0,0 +1,85 @@ +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()); + } + + + +} \ No newline at end of file