. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Census; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Place; use Mockery; /** * Test harness for the class CensusColumnBirthPlaceSimple */ class CensusColumnBirthPlaceSimpleTest 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('gedcomName')->andReturn($place); return $placeMock; } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testForeignCountry(): void { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Westminster, London, England')); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('England', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testJustCountry(): void { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('United States')); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testKnownState(): void { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Maryland, United States')); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('Maryland', $column->generate($individual, $individual)); } /** * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn * * @return void */ public function testKnownStateAndTown(): void { $individual = Mockery::mock(Individual::class); $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Miami, Florida, United States')); $census = Mockery::mock(CensusInterface::class); $census->shouldReceive('censusPlace')->andReturn('United States'); $column = new CensusColumnBirthPlaceSimple($census, '', ''); $this->assertSame('Florida', $column->generate($individual, $individual)); } }