UserSettingsTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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