Completed
Push — 119-timezones ( b64d06...bcb54d )
by Christian
10:34 queued 09:10
created

TimeTest::createDateTime()   A

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 1
1
<?php
2
/**
3
 * Copyright Zikula Foundation 2014 - Zikula Application Framework
4
 *
5
 * This work is contributed to the Zikula Foundation under one or more
6
 * Contributor Agreements and licensed to You under the following license:
7
 *
8
 * @license GNU/LGPv3 (or at your option any later version).
9
 * @package OpenWeatherMap-PHP-Api
10
 *
11
 * Please see the NOTICE file distributed with this source code for further
12
 * information regarding copyright and licensing.
13
 */
14
15
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
16
17
use Cmfcmf\OpenWeatherMap\Util\Time;
18
19
class TimeTest extends \PHPUnit_Framework_TestCase
20
{
21
    private function createDateTime($time)
22
    {
23
        return new \DateTime($time, new \DateTimeZone('UTC'));
24
    }
25
26
    public function testFromTo()
27
    {
28
        $fromS = '2014-01-01 08:00:00';
29
        $toS = '2014-01-01 20:00:00';
30
        $from = $this->createDateTime($fromS);
31
        $to = $this->createDateTime($toS);
32
        $day = $this->createDateTime('2014-01-01');
33
34
        $time = new Time($from, $to);
35
        $this->assertSame($from->format('c'), $time->from->format('c'));
36
        $this->assertSame($to->format('c'), $time->to->format('c'));
37
        $this->assertSame($day->format('c'), $time->day->format('c'));
38
39
        $time = new Time($fromS, $toS);
40
        $this->assertSame($from->format('c'), $time->from->format('c'));
41
        $this->assertSame($to->format('c'), $time->to->format('c'));
42
        $this->assertSame($day->format('c'), $time->day->format('c'));
43
    }
44
    public function testFrom()
45
    {
46
        $fromS = '2014-01-01 00:00:00';
47
        $from = $this->createDateTime($fromS);
48
        $day = $this->createDateTime('2014-01-01');
49
        $to = $this->createDateTime('2014-01-01 23:59:59');
50
51
        $time = new Time($from);
52
        $this->assertSame($from->format('c'), $time->from->format('c'));
53
        $this->assertSame($to->format('c'), $time->to->format('c'));
54
        $this->assertSame($day->format('c'), $time->day->format('c'));
55
56
        $time = new Time($fromS);
57
        $this->assertSame($from->format('c'), $time->from->format('c'));
58
        $this->assertSame($to->format('c'), $time->to->format('c'));
59
        $this->assertSame($day->format('c'), $time->day->format('c'));
60
    }
61
}
62