diff --git a/src/Client.php b/src/Client.php index cfe596f..ffd2eea 100644 --- a/src/Client.php +++ b/src/Client.php @@ -52,7 +52,7 @@ public function getCommunesByDepartementCode(string $departementCode): array coordinates: $commune['centre']['coordinates'], ), surface: $commune['surface'], - population: $commune['population'], + population: $commune['population'] ?? 0, departement: new CommuneDepartement( nom: $commune['departement']['nom'], code: $commune['departement']['code'], diff --git a/tests/GeoGouvTest.php b/tests/GeoGouvTest.php index 614c3dc..f7bebcc 100644 --- a/tests/GeoGouvTest.php +++ b/tests/GeoGouvTest.php @@ -30,9 +30,11 @@ public function testGetCommunesByDepartementCode(): void { $client = new Client(); - $communes = $client->getCommunesByDepartementCode('01'); + foreach ($client->getDepartements() as $departement) { + $communes = $client->getCommunesByDepartementCode($departement->code); - self::assertIsArray($communes); - self::assertInstanceOf(Commune::class, $communes[0]); + self::assertIsArray($communes); + self::assertInstanceOf(Commune::class, $communes[0]); + } } }