1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2020 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Census; 21 22use Fisharebest\Webtrees\Date; 23use Fisharebest\Webtrees\Family; 24use Fisharebest\Webtrees\Individual; 25use Fisharebest\Webtrees\TestCase; 26use Illuminate\Support\Collection; 27 28/** 29 * Test harness for the class CensusColumnChildrenLiving 30 */ 31class CensusColumnChildrenLivingTest extends TestCase 32{ 33 /** 34 * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving 35 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 36 * 37 * @return void 38 */ 39 public function testMale(): void 40 { 41 $individual = self::createMock(Individual::class); 42 $individual->method('sex')->willReturn('M'); 43 $individual->method('spouseFamilies')->willReturn(new Collection([])); 44 45 $census = self::createMock(CensusInterface::class); 46 47 $column = new CensusColumnChildrenLiving($census, '', ''); 48 49 self::assertSame('', $column->generate($individual, $individual)); 50 } 51 52 /** 53 * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving 54 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 55 * 56 * @return void 57 */ 58 public function testCountChildren(): void 59 { 60 // Stillborn 61 $child1 = self::createMock(Individual::class); 62 $child1->method('getBirthDate')->willReturn(new Date('01 FEB 1904')); 63 $child1->method('getDeathDate')->willReturn(new Date('01 FEB 1904')); 64 65 // Died after census 66 $child2 = self::createMock(Individual::class); 67 $child2->method('getBirthDate')->willReturn(new Date('02 FEB 1904')); 68 $child2->method('getDeathDate')->willReturn(new Date('20 DEC 1912')); 69 70 // Died before census 71 $child3 = self::createMock(Individual::class); 72 $child3->method('getBirthDate')->willReturn(new Date('02 FEB 1904')); 73 $child3->method('getDeathDate')->willReturn(new Date('20 DEC 1910')); 74 75 // Still living 76 $child4 = self::createMock(Individual::class); 77 $child4->method('getBirthDate')->willReturn(new Date('01 FEB 1904')); 78 $child4->method('getDeathDate')->willReturn(new Date('')); 79 80 $family = self::createMock(Family::class); 81 $family->method('children')->willReturn(new Collection([ 82 $child1, 83 $child2, 84 $child3, 85 $child4, 86 ])); 87 88 $individual = self::createMock(Individual::class); 89 $individual->method('sex')->willReturn('F'); 90 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 91 92 $census = self::createMock(CensusInterface::class); 93 $census->method('censusDate')->willReturn('30 MAR 1911'); 94 95 $column = new CensusColumnChildrenLiving($census, '', ''); 96 97 self::assertSame('2', $column->generate($individual, $individual)); 98 } 99} 100