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

AbstractDateTester   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 54
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testSpecialDate() 0 24 3
provider() 0 1 ?
createDateObject() 0 1 ?
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