|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use JhFlexiTime\DateTime\DateTime; |
|
6
|
|
|
|
|
7
|
|
|
class GetSetDateTraitTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
protected $traitObject; |
|
10
|
|
|
|
|
11
|
|
|
public function setUp() |
|
12
|
|
|
{ |
|
13
|
|
|
$this->traitObject = $this->getObjectForTrait('JhFlexiTime\Controller\GetSetDateTrait'); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @dataProvider invalidDateParamsProvider |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testGetDateReturnsCurrentDateTmeObjectWhenParamsInvalid($month, $year, $notExpected) |
|
20
|
|
|
{ |
|
21
|
|
|
$date = $this->traitObject->getDate($month, $year); |
|
22
|
|
|
$this->assertNotEquals($date, $notExpected); |
|
23
|
|
|
$this->assertInstanceOf('\DateTime', $date); |
|
24
|
|
|
|
|
25
|
|
|
$today = new \DateTime; |
|
26
|
|
|
$this->assertEquals($date->format('d-m-Y'), $today->format('d-m-Y')); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function invalidDateParamsProvider() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
["not-a-month", 20145, new \DateTime("last day of March 2014 23:59:59")], |
|
33
|
|
|
["Apr", '1988v', new \DateTime("last day of April 1988 23:59:59")], |
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @dataProvider validDateParamsProvider |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testGetDateReturnsDateTimeObjectBasedOnParams($month, $year, $expected) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertEquals($expected, $this->traitObject->getDate($month, $year)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function validDateParamsProvider() |
|
46
|
|
|
{ |
|
47
|
|
|
return [ |
|
48
|
|
|
["Mar", 2014, new \DateTime("last day of March 2014 23:59:59")], |
|
49
|
|
|
["Apr", 1988, new \DateTime("last day of April 1988 23:59:59")], |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testGetDateReturnsCurrentlySetObjectIfSet() |
|
54
|
|
|
{ |
|
55
|
|
|
$date = new DateTime(); |
|
56
|
|
|
$this->traitObject->setDate($date); |
|
57
|
|
|
$this->assertEquals($date, $this->traitObject->getDate()); |
|
58
|
|
|
$this->assertEquals($date, $this->traitObject->getDate("Mar", 2014)); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|