diff --git a/CHANGELOG.md b/CHANGELOG.md index b97b4413..aa00c8f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +3.3.1 (unreleased) +------------------ + +* Updated the `GeoIp2\Model\City` constructor to handle an empty + `subdivisions` array. This provides compatibility with some third-party + databases that publish empty subdivisions arrays. Pull request by Jarek + Jakubowski. GitHub #290. + 3.3.0 (2025-11-20) ------------------ diff --git a/tests/GeoIp2/Test/Model/InsightsTest.php b/tests/GeoIp2/Test/Model/InsightsTest.php index f2cb9f68..195623b9 100644 --- a/tests/GeoIp2/Test/Model/InsightsTest.php +++ b/tests/GeoIp2/Test/Model/InsightsTest.php @@ -497,4 +497,24 @@ public function testMostSpecificSubdivisionWithNoSubdivisions(): void 'mostSpecificSubdivision is set even on an empty response' ); } + + // We do not expect well-formed databases from MaxMind to have empty + // subdivisions arrays, but we support it due to encountering a third-party + // database that had them. + public function testEmptySubdivisionsArray(): void + { + $raw = [ + 'subdivisions' => [], + 'traits' => ['ip_address' => '1.1.1.1'], + ]; + + $model = new Insights($raw, ['en']); + + $this->assertCount(0, $model->subdivisions); + + $this->assertInstanceOf( + 'GeoIp2\Record\Subdivision', + $model->mostSpecificSubdivision + ); + } }