GetSetDateTraitTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetDateReturnsCurrentDateTmeObjectWhenParamsInvalid() 0 9 1
A invalidDateParamsProvider() 0 7 1
A testGetDateReturnsDateTimeObjectBasedOnParams() 0 4 1
A validDateParamsProvider() 0 7 1
A testGetDateReturnsCurrentlySetObjectIfSet() 0 7 1
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