CappedCreditTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 71
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetSetDate() 0 7 1
A testSetterGetter() 0 9 1
A setterGetterProvider() 0 7 1
A testGetIdThrowsExceptionIfUserNotSet() 0 5 1
A testGetIdContainsUserIdAndDate() 0 11 1
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