Completed
Push — master ( 2dd332...d6426f )
by steef
02:53
created

AbstractDateTester::testSpecialDate()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
ccs 18
cts 18
cp 1
rs 8.9713
cc 3
eloc 15
nc 4
nop 7
crap 3
1
<?php
2
namespace Stefanius\SpecialDates\Tests;
3
4
use Stefanius\SpecialDates\SDK\SpecialDateInterface;
5
6
abstract class AbstractDateTester extends \PHPUnit_Framework_TestCase
7
{
8
    /**
9
     * @param int $year
10
     * @param string $description
11
     * @param bool $isValid
12
     * @param bool $bankHoliday
13
     * @param int $totalLength
14
     * @param string $endDateString (yyyy-mm-dd)
15
     * @param string $startDateString (yyyy-mm-dd)
16
     *
17
     * @dataProvider provider
18
     */
19 51
    public function testSpecialDate($year, $description, $isValid, $bankHoliday, $totalLength, $startDateString, $endDateString)
20
    {
21 51
        $specialDate = $this->createDateObject($year);
22
23 51
        $startDate = $specialDate->getStartDate();
24 51
        $endDate = $specialDate->getEndDate();
25
26 51
        $this->assertEquals($description, $specialDate->getDescription());
27 51
        $this->assertEquals($isValid, $specialDate->isValid());
28 51
        $this->assertEquals($bankHoliday, $specialDate->isBankHoliday());
29 51
        $this->assertEquals($totalLength, $specialDate->getTotalLength());
30
31 51
        $this->assertEquals($startDateString, $startDate->format('Y') . '-' . $startDate->format('m') . '-' . $startDate->format('d'));
32 51
        $this->assertEquals($endDateString, $endDate->format('Y') . '-' . $endDate->format('m') . '-' . $endDate->format('d'));
33
34 51
        if ($isValid) {
35 26
            $this->assertEquals($year, $startDate->format('Y'));
36 26
            $this->assertEquals($year, $endDate->format('Y'));
37 26
        }
38
39 51
        if ($totalLength === 1) {
40 22
            $this->assertEquals($startDateString, $endDateString);
41 22
        }
42 51
    }
43
44
    /**
45
     * Dataprovider for the unittest. Extend this method in your concrete test.
46
     *
47
     * @return array
48
     */
49
    abstract public function provider();
50
51
    /**
52
     * Create and return the SpecialDateObject you want to test.
53
     *
54
     * @param $year
55
     *
56
     * @return SpecialDateInterface
57
     */
58
    abstract protected function createDateObject($year);
59
}
60