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