xref: /webtrees/tests/app/Census/CensusColumnAgeMale5YearsTest.php (revision 9b802b22a7b94d1d30e0433dd46fe641f3757505)
1db7d25eeSGreg Roach<?php
2db7d25eeSGreg Roach/**
3db7d25eeSGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
5db7d25eeSGreg Roach * This program is free software: you can redistribute it and/or modify
6db7d25eeSGreg Roach * it under the terms of the GNU General Public License as published by
7db7d25eeSGreg Roach * the Free Software Foundation, either version 3 of the License, or
8db7d25eeSGreg Roach * (at your option) any later version.
9db7d25eeSGreg Roach * This program is distributed in the hope that it will be useful,
10db7d25eeSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11db7d25eeSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12db7d25eeSGreg Roach * GNU General Public License for more details.
13db7d25eeSGreg Roach * You should have received a copy of the GNU General Public License
14db7d25eeSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15db7d25eeSGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
18db7d25eeSGreg Roachnamespace Fisharebest\Webtrees\Census;
19db7d25eeSGreg Roach
20db7d25eeSGreg Roachuse Fisharebest\Webtrees\Date;
21ddf438a5SGreg Roachuse Fisharebest\Webtrees\Individual;
22db7d25eeSGreg Roachuse Mockery;
23db7d25eeSGreg Roach
24db7d25eeSGreg Roach/**
25db7d25eeSGreg Roach * Test harness for the class CensusColumnAgeMale5Years5Years
26db7d25eeSGreg Roach */
2784e2cf4eSGreg Roachclass CensusColumnAgeMale5YearsTest extends \Fisharebest\Webtrees\TestCase
28c1010edaSGreg Roach{
29db7d25eeSGreg Roach    /**
30db7d25eeSGreg Roach     * Delete mock objects
3152348eb8SGreg Roach     *
3252348eb8SGreg Roach     * @return void
33db7d25eeSGreg Roach     */
34c1010edaSGreg Roach    public function tearDown()
35c1010edaSGreg Roach    {
36db7d25eeSGreg Roach        Mockery::close();
37db7d25eeSGreg Roach    }
38db7d25eeSGreg Roach
39db7d25eeSGreg Roach    /**
4015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
4115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
4252348eb8SGreg Roach     *
4352348eb8SGreg Roach     * @return void
44db7d25eeSGreg Roach     */
45*9b802b22SGreg Roach    public function testMale(): void
46c1010edaSGreg Roach    {
47ddf438a5SGreg Roach        $individual = Mockery::mock(Individual::class);
48db7d25eeSGreg Roach        $individual->shouldReceive('getSex')->andReturn('M');
49db7d25eeSGreg Roach        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
50db7d25eeSGreg Roach
51ddf438a5SGreg Roach        $census = Mockery::mock(CensusInterface::class);
52db7d25eeSGreg Roach        $census->shouldReceive('censusDate')->andReturn('30 JUN 1830');
53db7d25eeSGreg Roach
54ef21b467SGreg Roach        $column = new CensusColumnAgeMale5Years($census, '', '');
55db7d25eeSGreg Roach
56342dcecdSGreg Roach        $this->assertSame('30', $column->generate($individual, $individual));
57db7d25eeSGreg Roach    }
58db7d25eeSGreg Roach
59db7d25eeSGreg Roach    /**
6015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
6115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
6252348eb8SGreg Roach     *
6352348eb8SGreg Roach     * @return void
64db7d25eeSGreg Roach     */
65*9b802b22SGreg Roach    public function testFemale(): void
66c1010edaSGreg Roach    {
67ddf438a5SGreg Roach        $individual = Mockery::mock(Individual::class);
68db7d25eeSGreg Roach        $individual->shouldReceive('getSex')->andReturn('F');
69db7d25eeSGreg Roach
70ddf438a5SGreg Roach        $census = Mockery::mock(CensusInterface::class);
71db7d25eeSGreg Roach
72ef21b467SGreg Roach        $column = new CensusColumnAgeMale5Years($census, '', '');
73db7d25eeSGreg Roach
74342dcecdSGreg Roach        $this->assertSame('', $column->generate($individual, $individual));
75db7d25eeSGreg Roach    }
76db7d25eeSGreg Roach
77db7d25eeSGreg Roach    /**
7815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
7915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
8052348eb8SGreg Roach     *
8152348eb8SGreg Roach     * @return void
82db7d25eeSGreg Roach     */
83*9b802b22SGreg Roach    public function testUnknownSex(): void
84c1010edaSGreg Roach    {
85ddf438a5SGreg Roach        $individual = Mockery::mock(Individual::class);
86db7d25eeSGreg Roach        $individual->shouldReceive('getSex')->andReturn('U');
87db7d25eeSGreg Roach        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
88db7d25eeSGreg Roach
89ddf438a5SGreg Roach        $census = Mockery::mock(CensusInterface::class);
90db7d25eeSGreg Roach        $census->shouldReceive('censusDate')->andReturn('30 JUN 1830');
91db7d25eeSGreg Roach
92ef21b467SGreg Roach        $column = new CensusColumnAgeMale5Years($census, '', '');
93db7d25eeSGreg Roach
94342dcecdSGreg Roach        $this->assertSame('30', $column->generate($individual, $individual));
95db7d25eeSGreg Roach    }
96db7d25eeSGreg Roach
97db7d25eeSGreg Roach    /**
9815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
9915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
10052348eb8SGreg Roach     *
10152348eb8SGreg Roach     * @return void
102db7d25eeSGreg Roach     */
103*9b802b22SGreg Roach    public function testLessThanOneYear(): void
104c1010edaSGreg Roach    {
105ddf438a5SGreg Roach        $individual = Mockery::mock(Individual::class);
106db7d25eeSGreg Roach        $individual->shouldReceive('getSex')->andReturn('M');
107db7d25eeSGreg Roach        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
108db7d25eeSGreg Roach
109ddf438a5SGreg Roach        $census = Mockery::mock(CensusInterface::class);
110db7d25eeSGreg Roach        $census->shouldReceive('censusDate')->andReturn('30 JUN 1800');
111db7d25eeSGreg Roach
112ef21b467SGreg Roach        $column = new CensusColumnAgeMale5Years($census, '', '');
113db7d25eeSGreg Roach
114342dcecdSGreg Roach        $this->assertSame('0', $column->generate($individual, $individual));
115db7d25eeSGreg Roach    }
116db7d25eeSGreg Roach
117db7d25eeSGreg Roach    /**
11815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
11915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
12052348eb8SGreg Roach     *
12152348eb8SGreg Roach     * @return void
122db7d25eeSGreg Roach     */
123*9b802b22SGreg Roach    public function testLessThanFifteenYears(): void
124c1010edaSGreg Roach    {
125ddf438a5SGreg Roach        $individual = Mockery::mock(Individual::class);
126db7d25eeSGreg Roach        $individual->shouldReceive('getSex')->andReturn('M');
127db7d25eeSGreg Roach        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
128db7d25eeSGreg Roach
129ddf438a5SGreg Roach        $census = Mockery::mock(CensusInterface::class);
130db7d25eeSGreg Roach        $census->shouldReceive('censusDate')->andReturn('30 JUN 1814');
131db7d25eeSGreg Roach
132ef21b467SGreg Roach        $column = new CensusColumnAgeMale5Years($census, '', '');
133db7d25eeSGreg Roach
134342dcecdSGreg Roach        $this->assertSame('14', $column->generate($individual, $individual));
135db7d25eeSGreg Roach    }
136db7d25eeSGreg Roach
137db7d25eeSGreg Roach    /**
13815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
13915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
14052348eb8SGreg Roach     *
14152348eb8SGreg Roach     * @return void
142db7d25eeSGreg Roach     */
143*9b802b22SGreg Roach    public function testRoundedDownToFiveYears(): void
144c1010edaSGreg Roach    {
145ddf438a5SGreg Roach        $individual = Mockery::mock(Individual::class);
146db7d25eeSGreg Roach        $individual->shouldReceive('getSex')->andReturn('M');
147db7d25eeSGreg Roach        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
148db7d25eeSGreg Roach
149ddf438a5SGreg Roach        $census = Mockery::mock(CensusInterface::class);
150db7d25eeSGreg Roach        $census->shouldReceive('censusDate')->andReturn('30 JUN 1844');
151db7d25eeSGreg Roach
152ef21b467SGreg Roach        $column = new CensusColumnAgeMale5Years($census, '', '');
153db7d25eeSGreg Roach
154342dcecdSGreg Roach        $this->assertSame('40', $column->generate($individual, $individual));
155db7d25eeSGreg Roach    }
156db7d25eeSGreg Roach}
157