diff --git a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php index 0ca17b5de..6f1d218a9 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php +++ b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php @@ -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); diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Import/AddressReferenceBaseImporterTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Import/AddressReferenceBaseImporterTest.php new file mode 100644 index 000000000..d4302413e --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Services/Import/AddressReferenceBaseImporterTest.php @@ -0,0 +1,87 @@ +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()); + } + + +} \ No newline at end of file