UserSettingsTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 70
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testSetGetUser() 0 8 1
A testDateSetterGetter() 0 11 1
A dateSetterGetterProvider() 0 8 1
A testJsonSerialize() 0 4 1
A testGetSetStartingBalance() 0 6 1
1
<?php
2
3
namespace JhFlexiTimeTest\Entity;
4
5
use JhFlexiTime\Entity\UserSettings;
6
use JhUser\Entity\User;
7
use JhFlexiTime\DateTime\DateTime;
8
9
class UserSettingsTest extends \PHPUnit_Framework_TestCase
10
{
11
12
    /**
13
     * @var UserSettings
14
     */
15
    protected $userSettings;
16
17
    /**
18
     * SetUp
19
     */
20
    public function setUp()
21
    {
22
        $this->userSettings = new UserSettings();
23
    }
24
25
    public function testSetGetUser()
26
    {
27
        $user = $this->getMock('ZfcUser\Entity\UserInterface');
28
29
        $this->assertNull($this->userSettings->getUser());
30
        $this->userSettings->setUser($user);
31
        $this->assertSame($user, $this->userSettings->getUser());
32
    }
33
34
    /**
35
     * Test The Date/Time setter/getters and default values
36
     *
37
     * @param string $name
38
     * @param DateTime $default
39
     * @param DateTime $newValue
40
     *
41
     * @dataProvider dateSetterGetterProvider
42
     */
43
    public function testDateSetterGetter($name, $default, $newValue)
44
    {
45
        $getMethod = 'get' . ucfirst($name);
46
        $setMethod = 'set' . ucfirst($name);
47
48
        $this->assertEquals($default, $this->userSettings->$getMethod());
49
50
        $this->userSettings->$setMethod($newValue);
51
        $this->assertSame($newValue, $this->userSettings->$getMethod());
52
        $this->assertInstanceOf('DateTime', $this->userSettings->$getMethod());
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function dateSetterGetterProvider()
59
    {
60
        return [
61
            ['flexStartDate',     null,    new DateTime("24 March 2014")],
62
            ['defaultStartTime',  null,    new DateTime("10:00")],
63
            ['defaultEndTime',    null,    new DateTime("18:30")],
64
        ];
65
    }
66
67
    public function testGetSetStartingBalance()
68
    {
69
        $this->assertEquals(0, $this->userSettings->getStartingBalance());
70
        $this->userSettings->setStartingBalance(5.5);
71
        $this->assertEquals(5.5, $this->userSettings->getStartingBalance());
72
    }
73
74
    public function testJsonSerialize()
75
    {
76
        $this->assertEquals([], $this->userSettings->jsonSerialize());
77
    }
78
}
79