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 CreateFromTimeTest extends AbstractTestCase |
18
|
|
|
{ |
19
|
|
|
public function testCreateFromDateWithDefaults() |
20
|
|
|
{ |
21
|
|
|
$d = Date::createFromTime(); |
22
|
|
|
$this->assertSame($d->getTimestamp(), Date::create(null, null, null, null, null, null)->getTimestamp()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testCreateFromDate() |
26
|
|
|
{ |
27
|
|
|
$d = Date::createFromTime(23, 5, 21); |
28
|
|
|
$this->assertDate($d, Date::now()->getYear(), Date::now()->getMonth(), Date::now()->getDay(), 23, 5, 21); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testCreateFromTimeWithHour() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$d = Date::createFromTime(22); |
34
|
|
|
$this->assertSame(22, $d->getHour()); |
35
|
|
|
$this->assertSame(0, $d->getMinute()); |
36
|
|
|
$this->assertSame(0, $d->getSecond()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testCreateFromTimeWithMinute() |
40
|
|
|
{ |
41
|
|
|
$d = Date::createFromTime(null, 5); |
42
|
|
|
$this->assertSame(5, $d->getMinute()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCreateFromTimeWithSecond() |
46
|
|
|
{ |
47
|
|
|
$d = Date::createFromTime(null, null, 21); |
48
|
|
|
$this->assertSame(21, $d->getSecond()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testCreateFromTimeWithDateTimeZone() |
52
|
|
|
{ |
53
|
|
|
$d = Date::createFromTime(12, 0, 0, new \DateTimeZone('Europe/London')); |
54
|
|
|
$this->assertDate($d, Date::now()->getYear(), Date::now()->getMonth(), Date::now()->getDay(), 12, 0, 0); |
55
|
|
|
$this->assertSame('Europe/London', $d->getTimezoneName()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testCreateFromTimeWithTimeZoneString() |
59
|
|
|
{ |
60
|
|
|
$d = Date::createFromTime(12, 0, 0, 'Europe/London'); |
61
|
|
|
$this->assertDate($d, Date::now()->getYear(), Date::now()->getMonth(), Date::now()->getDay(), 12, 0, 0); |
62
|
|
|
$this->assertSame('Europe/London', $d->getTimezoneName()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.