1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Stdlib\Test\Unit\DateTime;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
/**
* Magento\Framework\Stdlib\DateTimeTest test case
*/
class DateTimeTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
private $testDate = '2015-04-02 21:03:00';
/**
* @param int|string|\DateTimeInterface $input
* @dataProvider dateTimeInputDataProvider
*/
public function testGmtTimestamp($input)
{
/** @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject $timezone */
$timezone = $this->getMockBuilder(TimezoneInterface::class)->getMock();
$timezone->method('date')->willReturn(new \DateTime($this->testDate));
$expected = gmdate('U', strtotime($this->testDate));
$this->assertEquals($expected, (new DateTime($timezone))->gmtTimestamp($input));
}
/**
* @param int|string|\DateTimeInterface $input
* @dataProvider dateTimeInputDataProvider
*/
public function testTimestamp($input)
{
/** @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject $timezone */
$timezone = $this->getMockBuilder(TimezoneInterface::class)->getMock();
$timezone->method('date')->willReturn(new \DateTime($this->testDate));
$expected = gmdate('U', strtotime($this->testDate));
$this->assertEquals($expected, (new DateTime($timezone))->timestamp($input));
}
/**
* @return array
*/
public function dateTimeInputDataProvider()
{
return [
'string' => [$this->testDate],
'int' => [strtotime($this->testDate)],
\DateTimeInterface::class => [new \DateTimeImmutable($this->testDate)],
];
}
}