. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Census; use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Place; use Mockery; /** * Test harness for the class CensusColumnMotherBirthPlace */ class CensusColumnMotherBirthPlaceTest extends \Fisharebest\Webtrees\TestCase { /** * Delete mock objects * * @return void */ public function tearDown() { Mockery::close(); } /** * Get place mock. * * @param string $place Gedcom Place * * @return Place */ private function getPlaceMock($place): Place { $placeParts = explode(', ', $place); $placeMock = Mockery::mock(Place::class); $placeMock->shouldReceive('getGedcomName')->andReturn($place); $placeMock->shouldReceive('lastPart')->andReturn(end($placeParts)); return $placeMock; } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testSameCountry() { $mother = Mockery::mock(Individual::class); $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); $family = Mockery::mock(Family::class); $family->shouldReceive('getWife')->andReturn($mother); $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('England'); $column = new CensusColumnMotherBirthPlace($census, '', ''); $this->assertSame('London', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testDifferentCountry() { $mother = Mockery::mock(Individual::class); $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); $family = Mockery::mock(Family::class); $family->shouldReceive('getWife')->andReturn($mother); $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('Ireland'); $column = new CensusColumnMotherBirthPlace($census, '', ''); $this->assertSame('London, England', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testPlaceNoParent() { $family = Mockery::mock(Family::class); $family->shouldReceive('getWife')->andReturn(null); $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('England'); $column = new CensusColumnMotherBirthPlace($census, '', ''); $this->assertSame('', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testPlaceNoParentFamily() { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getPrimaryChildFamily')->andReturn(null); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('England'); $column = new CensusColumnMotherBirthPlace($census, '', ''); $this->assertSame('', $column->generate($individual, $individual)); } }