Completed
Pull Request — master (#17)
by
unknown
20:59
created

DateTimeCreatorTest::microtimeProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Smartbox\CoreBundle\Tests\Utils\Helper;
4
5
use Smartbox\CoreBundle\Utils\Helper\DateTimeCreator;
6
use Symfony\Bridge\PhpUnit\ClockMock;
7
8
/**
9
 * @coversDefaultClass Smartbox\CoreBundle\Utils\Helper\DateTimeCreator
10
 */
11
class DateTimeCreatorTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @covers ::getNowDateTime
15
     * @dataProvider microtimeProvider
16
     */
17
    public function testGetNowDateTime($microtime, $expectedDateTime)
18
    {
19
20
        $clockReflection = new \ReflectionClass(ClockMock::class);
21
22
        $reflectionProperty = $clockReflection->getProperty('now');
23
        $reflectionProperty->setAccessible(true);
24
        $reflectionProperty->setValue($microtime);
25
26
        ClockMock::register(DateTimeCreator::class);
27
28
        $datetime = DateTimeCreator::getNowDateTime();
29
30
        $this->assertEquals($expectedDateTime, $datetime);
31
    }
32
33
    public function microtimeProvider()
34
    {
35
        return [
36
            'with-decimal' => [
37
                1544538334.9465,
38
                new \DateTime('2018-12-11 14:25:34.946500'),
39
            ],
40
            'without-decimal' => [
41
                1544538334,
42
                new \DateTime('2018-12-11 14:25:34.000000'),
43
            ],
44
            'with-decimal-zero' => [
45
                1544538334.0,
46
                new \DateTime('2018-12-11 14:25:34.000000'),
47
            ],
48
        ];
49
    }
50
}
51