InstanceTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceFromDateTime() 0 5 1
A testInstanceFromDateTimeKeepsTimezoneName() 0 9 1
A testInstanceFromDateTimeKeepsMicros() 0 7 1
1
<?php
2
3
namespace HMLB\Date\Tests\Date;
4
5
/*
6
 * This file is part of the Date package.
7
 *
8
 * (c) Hugues Maignol <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use HMLB\Date\Date;
15
use HMLB\Date\Tests\AbstractTestCase;
16
17
class InstanceTest extends AbstractTestCase
18
{
19
    public function testInstanceFromDateTime()
20
    {
21
        $dating = Date::instance(\DateTime::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11'));
22
        $this->assertDate($dating, 1975, 5, 21, 22, 32, 11);
23
    }
24
25
    public function testInstanceFromDateTimeKeepsTimezoneName()
26
    {
27
        $dating = Date::instance(
28
            \DateTime::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11')->setTimezone(
29
                new \DateTimeZone('America/Vancouver')
30
            )
31
        );
32
        $this->assertSame('America/Vancouver', $dating->getTimezoneName());
33
    }
34
35
    public function testInstanceFromDateTimeKeepsMicros()
36
    {
37
        $micro = 254687;
38
        $datetime = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.'.$micro);
39
        $date = Date::instance($datetime);
40
        $this->assertSame($micro, $date->getMicro());
41
    }
42
}
43