Skip to content

Commit

Permalink
Merge pull request #5 from sagautam5/fetch-all-municipalities-of-a-pr…
Browse files Browse the repository at this point in the history
…ovince

get all municipalities of a province
  • Loading branch information
sagautam5 authored Feb 10, 2021
2 parents 3e86c96 + 277a33a commit 0cc5b67
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Entities/Municipality.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public function getMunicipalityByCategory($categoryId)
}));
}

public function getMunicipalityByProvince($provinceId)
{
$district = new District();
$districts = $district->getDistrictsByProvince($provinceId);
$municipalities = array_map(function ($item) {
return $this->getMunicipalitiesByDistrict($item->id);
}, $districts);

return array_merge(...$municipalities);
}

/**
* Find municipality by id
*
Expand Down
39 changes: 39 additions & 0 deletions tests/Unit/MunicipalityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,43 @@ public function testSortBy()
}
}
}

/**
* Individual Province Municipality Count Test
*/
public function test_GetMunicipalityByProvince_For_Individual_Correct_Count()
{
$expectedSet = array(
'1' => 137,
'2' => 136,
'3' => 119,
'4' => 85,
'5' => 109,
'6' => 79,
'7' => 88
);

$actualSet = array();

for ($index = 1; $index<=7; $index++){
$actualSet[(string)$index] = count($this->municipality->getMunicipalityByProvince($index));
}

$this->assertSame($expectedSet, $actualSet);
}

/**
* Total Municipality Count Test
*/
public function test_GetMunicipalityByProvince_For_Total_Count()
{
$expectedTotal = 753;

$actualTotal = 0;
for ($index = 1; $index<=7; $index++){
$actualTotal += count($this->municipality->getMunicipalityByProvince($index));
}

$this->assertSame($actualTotal, $expectedTotal);
}
}

0 comments on commit 0cc5b67

Please sign in to comment.