. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Census; use Fisharebest\Webtrees\Date; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Place; use Mockery; /** * Test harness for the class CensusColumnNationality */ class CensusColumnNationalityTest 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 { $placeMock = Mockery::mock(Place::class); $placeMock->shouldReceive('getGedcomName')->andReturn($place); return $placeMock; } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testNoBirthPlace() { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('')); $individual->shouldReceive('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->andReturn([]); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('Deutschland'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('Deutsch', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testPlaceCountry() { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia')); $individual->shouldReceive('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->andReturn([]); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('England'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('Australia', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testBritish() { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); $individual->shouldReceive('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->andReturn([]); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('England'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('British', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testEmigrated() { $place1 = Mockery::mock('Fisharebest\Webtrees\Place'); $place1->shouldReceive('getGedcomName')->andReturn('United States'); $fact1 = Mockery::mock(Fact::class); $fact1->shouldReceive('place')->andReturn($place1); $fact1->shouldReceive('date')->andReturn(new Date('1855')); $place2 = Mockery::mock('Fisharebest\Webtrees\Place'); $place2->shouldReceive('getGedcomName')->andReturn('Australia'); $fact2 = Mockery::mock(Fact::class); $fact2->shouldReceive('place')->andReturn($place2); $fact2->shouldReceive('date')->andReturn(new Date('1865')); $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); $individual->shouldReceive('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->andReturn([ $fact1, $fact2, ]); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('England'); $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); $column = new CensusColumnNationality($census, '', ''); $this->assertSame('United States', $column->generate($individual, $individual)); } }