Skip to content

Commit 3a872b7

Browse files
Change: Code improvements
- $iso is now required - Remove duplicated code on tests
1 parent c20d21e commit 3a872b7

File tree

11 files changed

+68
-161
lines changed

11 files changed

+68
-161
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
},
2020
"autoload": {
2121
"psr-0": { "Checkdomain\\Holiday": "lib/" }
22+
},
23+
"autoload-dev": {
24+
"psr-0": { "Checkdomain\\Holiday": "tests/" }
2225
}
2326
}

lib/Checkdomain/Holiday/Provider/AbstractEaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class AbstractEaster extends AbstractProvider
1313
*
1414
* @param int $year
1515
*
16-
* @return array
16+
* @return \DateTime[]
1717
*/
1818
protected function getEasterDates($year)
1919
{

lib/Checkdomain/Holiday/Util.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected function getProvider($iso)
2020
{
2121
$instance = null;
2222

23-
$class = '\\Checkdomain\\Holiday\\Provider\\'.$iso;
23+
$class = '\\Checkdomain\\Holiday\\Provider\\' . $iso;
2424

2525
if (class_exists($class)) {
2626
$instance = new $class;
@@ -59,27 +59,27 @@ protected function getIsoCode($iso)
5959
* This method can be used to check whether a specific date is a holiday
6060
* in a specified country and state
6161
*
62-
* @param \DateTime|string $date
6362
* @param string $iso
63+
* @param \DateTime|string $date
6464
* @param string $state
6565
*
6666
* @return bool
6767
*/
68-
public function isHoliday($date = 'now', $iso = null, $state = null)
68+
public function isHoliday($iso, $date = 'now', $state = null)
6969
{
70-
return ($this->getHoliday($date, $iso, $state) !== null);
70+
return ($this->getHoliday($iso, $date, $state) !== null);
7171
}
7272

7373
/**
7474
* Provides detailed information about a specific holiday
7575
*
76-
* @param \DateTime|string $date
7776
* @param string $iso
77+
* @param \DateTime|string $date
7878
* @param string $state
7979
*
8080
* @return Holiday|null
8181
*/
82-
public function getHoliday($date = 'now', $iso = null, $state = null)
82+
public function getHoliday($iso, $date = 'now', $state = null)
8383
{
8484
$iso = $this->getIsoCode($iso);
8585
$date = $this->getDateTime($date);

tests/Checkdomain/Holiday/Provider/ATTest.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace Checkdomain\Holiday\Provider;
44

5-
65
/**
76
* Class DE
87
*/
9-
class ATTest extends \PHPUnit_Framework_TestCase
8+
class ATTest extends AbstractTest
109
{
1110

1211
/**
@@ -22,33 +21,6 @@ public function setUp()
2221
$this->provider = new AT();
2322
}
2423

25-
/**
26-
* @param string $date
27-
* @param string $state
28-
* @param array $expectation
29-
*
30-
* @dataProvider dateProvider
31-
*/
32-
public function testHolidays($date, $state = null, array $expectation = null)
33-
{
34-
$date = new \DateTime($date);
35-
$holiday = $this->provider->getHolidayByDate($date, $state);
36-
37-
if ($expectation === null) {
38-
$this->assertNull($holiday);
39-
} else {
40-
$this->assertNotNull($holiday, 'No Holiday found but assumed to find one on '.$date->format('Y-m-d'));
41-
$this->assertEquals($date->format('d.m.Y'), $holiday->getDate()->format('d.m.Y'));
42-
43-
foreach ($expectation as $property => $expectedValue) {
44-
$method = 'get'.ucfirst($property);
45-
$value = $holiday->$method();
46-
47-
$this->assertEquals($expectedValue, $value);
48-
}
49-
}
50-
}
51-
5224
/**
5325
* Provides some test dates and the expectation
5426
*
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Checkdomain\Holiday\Provider;
4+
5+
/**
6+
* Class DK
7+
*/
8+
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Checkdomain\Holiday\ProviderInterface
12+
*/
13+
protected $provider;
14+
15+
/**
16+
* @param string $date
17+
* @param string $state
18+
* @param array $expectation
19+
*
20+
* @dataProvider dateProvider
21+
*/
22+
public function testHolidays($date, $state = null, array $expectation = null)
23+
{
24+
$date = new \DateTime($date);
25+
$holiday = $this->provider->getHolidayByDate($date, $state);
26+
27+
if ($expectation === null) {
28+
$this->assertNull($holiday);
29+
} else {
30+
$this->assertNotNull($holiday, 'No Holiday found but assumed to find one on ' . $date->format('Y-m-d'));
31+
$this->assertEquals($date->format('d.m.Y'), $holiday->getDate()->format('d.m.Y'));
32+
33+
foreach ($expectation as $property => $expectedValue) {
34+
$method = 'get' . ucfirst($property);
35+
$value = $holiday->$method();
36+
37+
$this->assertEquals($expectedValue, $value);
38+
}
39+
}
40+
}
41+
}

tests/Checkdomain/Holiday/Provider/DETest.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace Checkdomain\Holiday\Provider;
44

5-
65
/**
76
* Class DE
87
*/
9-
class DETest extends \PHPUnit_Framework_TestCase
8+
class DETest extends AbstractTest
109
{
1110

1211
/**
@@ -22,33 +21,6 @@ public function setUp()
2221
$this->provider = new DE();
2322
}
2423

25-
/**
26-
* @param string $date
27-
* @param string $state
28-
* @param array $expectation
29-
*
30-
* @dataProvider dateProvider
31-
*/
32-
public function testHolidays($date, $state = null, array $expectation = null)
33-
{
34-
$date = new \DateTime($date);
35-
$holiday = $this->provider->getHolidayByDate($date, $state);
36-
37-
if ($expectation === null) {
38-
$this->assertNull($holiday);
39-
} else {
40-
$this->assertNotNull($holiday, 'No Holiday found but assumed to find one on '.$date->format('Y-m-d'));
41-
$this->assertEquals($date->format('d.m.Y'), $holiday->getDate()->format('d.m.Y'));
42-
43-
foreach ($expectation as $property => $expectedValue) {
44-
$method = 'get'.ucfirst($property);
45-
$value = $holiday->$method();
46-
47-
$this->assertEquals($expectedValue, $value);
48-
}
49-
}
50-
}
51-
5224
/**
5325
* Provides some test dates and the expectation
5426
*

tests/Checkdomain/Holiday/Provider/FRTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Class FR
77
*/
8-
class FRTest extends \PHPUnit_Framework_TestCase
8+
class FRTest extends AbstractTest
99
{
1010

1111
/**

tests/Checkdomain/Holiday/Provider/ITTest.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Class IT
1212
*/
13-
class ITTest extends \PHPUnit_Framework_TestCase
13+
class ITTest extends AbstractTest
1414
{
1515

1616
/**
@@ -26,33 +26,6 @@ public function setUp()
2626
$this->provider = new IT();
2727
}
2828

29-
/**
30-
* @param string $date
31-
* @param string $state
32-
* @param array $expectation
33-
*
34-
* @dataProvider dateProvider
35-
*/
36-
public function testHolidays($date, $state = null, array $expectation = null)
37-
{
38-
$date = new \DateTime($date);
39-
$holiday = $this->provider->getHolidayByDate($date, $state);
40-
41-
if ($expectation === null) {
42-
$this->assertNull($holiday);
43-
} else {
44-
$this->assertNotNull($holiday, 'No Holiday found but assumed to find one on '.$date->format('d.m.Y'));
45-
$this->assertEquals($date->format('d.m.Y'), $holiday->getDate()->format('d.m.Y'));
46-
47-
foreach ($expectation as $property => $expectedValue) {
48-
$method = 'get'.ucfirst($property);
49-
$value = $holiday->$method();
50-
51-
$this->assertEquals($expectedValue, $value);
52-
}
53-
}
54-
}
55-
5629
/**
5730
* Provides some test dates and the expectation
5831
*

tests/Checkdomain/Holiday/Provider/NOTest.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Class NO
1212
*/
13-
class NOTest extends \PHPUnit_Framework_TestCase
13+
class NOTest extends AbstractTest
1414
{
1515

1616
/**
@@ -26,33 +26,6 @@ public function setUp()
2626
$this->provider = new NO();
2727
}
2828

29-
/**
30-
* @param string $date
31-
* @param string $state
32-
* @param array $expectation
33-
*
34-
* @dataProvider dateProvider
35-
*/
36-
public function testHolidays($date, $state = null, array $expectation = null)
37-
{
38-
$date = new \DateTime($date);
39-
$holiday = $this->provider->getHolidayByDate($date, $state);
40-
41-
if ($expectation === null) {
42-
$this->assertNull($holiday);
43-
} else {
44-
$this->assertNotNull($holiday, 'No Holiday found but assumed to find one on '.$date->format('d.m.Y'));
45-
$this->assertEquals($date->format('d.m.Y'), $holiday->getDate()->format('d.m.Y'));
46-
47-
foreach ($expectation as $property => $expectedValue) {
48-
$method = 'get'.ucfirst($property);
49-
$value = $holiday->$method();
50-
51-
$this->assertEquals($expectedValue, $value);
52-
}
53-
}
54-
}
55-
5629
/**
5730
* Provides some test dates and the expectation
5831
*

tests/Checkdomain/Holiday/Provider/SETest.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Class SE
1212
*/
13-
class SETest extends \PHPUnit_Framework_TestCase
13+
class SETest extends AbstractTest
1414
{
1515

1616
/**
@@ -26,33 +26,6 @@ public function setUp()
2626
$this->provider = new SE();
2727
}
2828

29-
/**
30-
* @param string $date
31-
* @param string $state
32-
* @param array $expectation
33-
*
34-
* @dataProvider dateProvider
35-
*/
36-
public function testHolidays($date, $state = null, array $expectation = null)
37-
{
38-
$date = new \DateTime($date);
39-
$holiday = $this->provider->getHolidayByDate($date, $state);
40-
41-
if ($expectation === null) {
42-
$this->assertNull($holiday);
43-
} else {
44-
$this->assertNotNull($holiday, 'No Holiday found but assumed to find one on '.$date->format('d.m.Y'));
45-
$this->assertEquals($date->format('d.m.Y'), $holiday->getDate()->format('d.m.Y'));
46-
47-
foreach ($expectation as $property => $expectedValue) {
48-
$method = 'get'.ucfirst($property);
49-
$value = $holiday->$method();
50-
51-
$this->assertEquals($expectedValue, $value);
52-
}
53-
}
54-
}
55-
5629
/**
5730
* Provides some test dates and the expectation
5831
*

tests/Checkdomain/Holiday/UtilTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ public function setUp()
1919
}
2020

2121
/**
22-
* @param string $date
2322
* @param string $iso
23+
* @param string $date
2424
* @param array $expectation
2525
*
2626
* @dataProvider providerHoliday
2727
*/
28-
public function testIsHoliday($date, $iso, array $expectation)
28+
public function testIsHoliday($iso, $date, array $expectation)
2929
{
30-
$isHoliday = $this->service->isHoliday($date, $iso);
30+
$isHoliday = $this->service->isHoliday($iso, $date);
3131

3232
$this->assertEquals($expectation[0], $isHoliday);
3333
}
3434

3535
/**
36-
* @param string $date
3736
* @param string $iso
37+
* @param string $date
3838
* @param array $expectation
3939
*
4040
* @dataProvider providerHoliday
4141
*/
42-
public function testGetHoliday($date, $iso, array $expectation)
42+
public function testGetHoliday($iso, $date, array $expectation)
4343
{
44-
$holiday = $this->service->getHoliday($date, $iso);
44+
$holiday = $this->service->getHoliday($iso, $date);
4545

4646
if ($expectation[1] === null) {
4747
$this->assertNull($holiday);
@@ -63,20 +63,20 @@ public function testGetHoliday($date, $iso, array $expectation)
6363
public function providerHoliday()
6464
{
6565
return array(
66-
array('25.12.2013', 'DE', array(true, array(
66+
array('DE', '25.12.2013', array(true, array(
6767
'name' => '1. Weihnachtstag',
6868
'national' => true
6969
))),
70-
array('01.05.2013', 'DE', array(true, array(
70+
array('DE', '01.05.2013', array(true, array(
7171
'name' => 'Tag der Arbeit',
7272
'national' => true
7373
))),
74-
array('02.01.2013', 'DE', array(false, null)),
75-
array('26.04.2038', 'DE', array(true, array(
74+
array('DE', '02.01.2013', array(false, null)),
75+
array('DE', '26.04.2038', array(true, array(
7676
'name' => 'Ostermontag',
7777
'national' => true
7878
)))
7979
);
8080
}
8181

82-
}
82+
}

0 commit comments

Comments
 (0)