HolidayTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Holiday Library.
5
 *
6
 * (c) Michał Mańko <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Michalmanko\Holiday\Test;
13
14
use DateTime;
15
use Michalmanko\Holiday\Holiday;
16
use PHPUnit_Framework_TestCase;
17
18
/**
19
 * @author Michał Mańko <[email protected]>
20
 */
21
class HolidayTest extends PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var Holiday
25
     */
26
    protected $object;
27
28
    protected function setUp()
29
    {
30
        $this->object = new Holiday('name', '2015-01-01');
31
    }
32
33
    public function testInstance()
34
    {
35
        $this->assertInstanceOf('\DateTime', $this->object);
36
    }
37
38
    public function testName()
39
    {
40
        $this->assertEquals('name', $this->object->getName());
41
42
        $this->assertSame($this->object, $this->object->setName('newName'));
43
44
        $this->assertEquals('newName', $this->object->getName());
45
    }
46
47
    public function testType()
48
    {
49
        $this->assertEquals(Holiday::TYPE_HOLIDAY, $this->object->getType());
50
51
        $this->assertSame($this->object, $this->object->setType(Holiday::TYPE_SCHOOL_HOLIDAY));
52
53
        $this->assertEquals(Holiday::TYPE_SCHOOL_HOLIDAY, $this->object->getType());
54
    }
55
56
    public function testConstructDefaultValues()
57
    {
58
        $this->assertEquals(Holiday::TYPE_HOLIDAY, $this->object->getType());
59
60
        $this->assertEquals(
61
            date_default_timezone_get(),
62
            $this->object->getTimezone()->getName()
63
        );
64
    }
65
66
    public function testInvalidTimeInConstruct()
67
    {
68
        $this->setExpectedException(
69
            '\\Exception',
70
            'DateTime::__construct(): Failed to parse time string (invalid-date) '
71
            . 'at position 0 (i): The timezone could not be found in the database'
72
        );
73
        new Holiday('name', 'invalid-date');
74
    }
75
76
    public function testInvalidTimezoneInConstruct()
77
    {
78
        $this->setExpectedException(
79
            '\\PHPUnit_Framework_Error',
80
            'Argument 3 passed to Michalmanko\Holiday\Holiday::__construct() '
81
            . 'must be an instance of DateTimeZone, string given'
82
        );
83
        new Holiday('name', '2015-01-01', 'timezone');
84
    }
85
86
    public function testTimeAsDateTimeInConstruct()
87
    {
88
        $date = new DateTime('2015-01-01');
89
90
        $holiday = new Holiday('name', $date);
91
92
        $this->assertEquals($date->getTimestamp(), $holiday->getTimestamp());
93
    }
94
}
95