1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Entity; |
4
|
|
|
|
5
|
|
|
use JhFlexiTime\Entity\Booking; |
6
|
|
|
use JhFlexiTime\DateTime\DateTime; |
7
|
|
|
use JhFlexiTime\Entity\CappedCredit; |
8
|
|
|
use JhUser\Entity\User; |
9
|
|
|
use PHPUnit_Framework_TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class CappedCreditTest |
13
|
|
|
* @package JhFlexiTimeTest\Entity |
14
|
|
|
* @author Aydin Hassan <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class CappedCreditTest extends PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var CappedCredit |
21
|
|
|
*/ |
22
|
|
|
protected $cappedCredit; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* SetUp |
26
|
|
|
*/ |
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->cappedCredit = new CappedCredit; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetSetDate() |
33
|
|
|
{ |
34
|
|
|
$this->assertNull($this->cappedCredit->getdate()); |
35
|
|
|
$date = new DateTime('11 November 2013'); |
36
|
|
|
$this->cappedCredit->setDate($date); |
37
|
|
|
$this->assertSame($date, $this->cappedCredit->getDate()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Test the other setter/getters which have no default values |
42
|
|
|
* |
43
|
|
|
* @param string $name |
44
|
|
|
* @param mixed $value |
45
|
|
|
* |
46
|
|
|
* @dataProvider setterGetterProvider |
47
|
|
|
*/ |
48
|
|
|
public function testSetterGetter($name, $value) |
49
|
|
|
{ |
50
|
|
|
$getMethod = 'get' . ucfirst($name); |
51
|
|
|
$setMethod = 'set' . ucfirst($name); |
52
|
|
|
|
53
|
|
|
$this->assertNull($this->cappedCredit->$getMethod()); |
54
|
|
|
$this->cappedCredit->$setMethod($value); |
55
|
|
|
$this->assertSame($value, $this->cappedCredit->$getMethod()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function setterGetterProvider() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
['user', new User], |
65
|
|
|
['cappedCredit', 100], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetIdThrowsExceptionIfUserNotSet() |
70
|
|
|
{ |
71
|
|
|
$this->setExpectedException('\RuntimeException', 'No User is set. Needed to generate ID'); |
72
|
|
|
$this->cappedCredit->getId(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetIdContainsUserIdAndDate() |
76
|
|
|
{ |
77
|
|
|
$user = new User; |
78
|
|
|
$user->setId(2); |
79
|
|
|
$date = new DateTime("24 March 2014"); |
80
|
|
|
|
81
|
|
|
$this->cappedCredit->setUser($user); |
82
|
|
|
$this->cappedCredit->setDate($date); |
83
|
|
|
$id = $this->cappedCredit->getId(); |
84
|
|
|
$this->assertEquals($date->getTimestamp() . "-2", $id); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|