Skip to content

Commit

Permalink
More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Jun 30, 2024
1 parent 307703f commit a169b25
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/Build/Province.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ public function checkMunicipalityData(stdClass $data): void
}
}

public function checkFlatEntry(FlatMunicipality $flatMunicipality): void
{
if ($this->id !== $flatMunicipality->utsID
|| $this->oldID !== $flatMunicipality->utsOldID
|| $this->vehicleCode !== $flatMunicipality->utsVehicleCode
|| $this->type !== $flatMunicipality->utsType
|| $this->name !== $flatMunicipality->utsName
) {
throw new RuntimeException('Incompatible FlatMunicipality for ' . __CLASS__);
}
}

public function serialize(Collator $collator): array
{
$result = [
Expand Down
49 changes: 49 additions & 0 deletions test/tests/SingletonsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use MLocati\ComuniItaliani\TerritoryWithChildren;
use MLocati\ComuniItaliani\Region;
use MLocati\ComuniItaliani\Province;
use MLocati\ComuniItaliani\GeographicalSubdivision;

class SingletonsTest extends TerritoryTestCase
{
Expand All @@ -32,4 +33,52 @@ public function testSingletons(bool $unminified): void
$geographicalSubdivisions = $factory->getGeographicalSubdivisions();
$this->assertSame($geographicalSubdivisions, $factory->getGeographicalSubdivisions());
}

/**
* @dataProvider provideGeographicalSubdivisions
*/
public function testGeographicalSubdivision(GeographicalSubdivision $geographicalSubdivision): void
{
$this->assertNull($geographicalSubdivision->getParent());
$children = $geographicalSubdivision->getChildren();
$this->assertSame($children, $geographicalSubdivision->getRegions());
foreach ($children as $child) {
$this->assertSame($geographicalSubdivision, $child->getParent());
}
}

/**
* @dataProvider provideRegions
*/
public function testRegion(Region $region): void
{
$this->assertInstanceOf(GeographicalSubdivision::class, $region->getParent());
$children = $region->getChildren();
$this->assertSame($children, $region->getProvinces());
foreach ($children as $child) {
$this->assertSame($region, $child->getParent());
}
}

/**
* @dataProvider provideProvinces
*/
public function testProvince(Province $province): void
{
$this->assertInstanceOf(Region::class, $province->getParent());
$children = $province->getChildren();
$this->assertSame($children, $province->getMunicipalities());
foreach ($children as $child) {
$this->assertSame($province, $child->getParent());
}
}

/**
* @dataProvider provideMunicipalities
*/
public function testMunicipality(Municipality $municipality): void
{
$this->assertInstanceOf(Province::class, $municipality->getParent());
$this->assertNotInstanceOf(TerritoryWithChildren::class, $municipality);
}
}

0 comments on commit a169b25

Please sign in to comment.