1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TraderInteractive\Filter; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Unit tests for the \TraderInteractive\Filter\DateTimeZone class. |
9
|
|
|
* |
10
|
|
|
* @coversDefaultClass \TraderInteractive\Filter\DateTimeZone |
11
|
|
|
*/ |
12
|
|
|
final class DateTimeZoneTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Verify basic usage of filter(). |
16
|
|
|
* |
17
|
|
|
* @test |
18
|
|
|
* @covers ::filter |
19
|
|
|
* |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
public function filter() |
23
|
|
|
{ |
24
|
|
|
$value = 'Pacific/Honolulu'; |
25
|
|
|
$timezone = DateTimeZone::filter($value); |
26
|
|
|
$this->assertSame($value, $timezone->getName()); |
27
|
|
|
$this->assertSame(-36000, $timezone->getOffset(new \DateTime('now', $timezone))); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Verify behavior of filter() when $allowNull is true and $value is null. |
32
|
|
|
* |
33
|
|
|
* @test |
34
|
|
|
* @covers ::filter |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function filterNullAllowed() |
39
|
|
|
{ |
40
|
|
|
$this->assertNull(DateTimeZone::filter(null, true)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Verify behavior of filter() when $allowNull is false and $value is null. |
45
|
|
|
* |
46
|
|
|
* @test |
47
|
|
|
* @covers ::filter |
48
|
|
|
* @expectedException \TraderInteractive\Exceptions\FilterException |
49
|
|
|
* @expectedExceptionMessage Value failed filtering, $allowNull is set to false |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function filterNullNotAllowed() |
54
|
|
|
{ |
55
|
|
|
$this->assertNull(DateTimeZone::filter(null, false)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Verify behavior of filter() when $value is a \DateTimeZone object. |
60
|
|
|
* |
61
|
|
|
* @test |
62
|
|
|
* @covers ::filter |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function filterTimeZonePass() |
67
|
|
|
{ |
68
|
|
|
$timezone = new \DateTimeZone('America/New_York'); |
69
|
|
|
$this->assertSame($timezone, DateTimeZone::filter($timezone)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Verify behavior of filter() when $value is not a valid timezone. |
74
|
|
|
* |
75
|
|
|
* @test |
76
|
|
|
* @covers ::filter |
77
|
|
|
* @expectedException \TraderInteractive\Exceptions\FilterException |
78
|
|
|
* @expectedExceptionMessage Unknown or bad timezone (INVALID) |
79
|
|
|
*/ |
80
|
|
|
public function filterInvalidName() |
81
|
|
|
{ |
82
|
|
|
DateTimeZone::filter('INVALID'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Verify behavior of filter() $value is a string with only whitespace. |
87
|
|
|
* |
88
|
|
|
* @test |
89
|
|
|
* @covers ::filter |
90
|
|
|
* @expectedException \TraderInteractive\Exceptions\FilterException |
91
|
|
|
* @expectedExceptionMessage $value not a non-empty string |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function filterEmptyValue() |
96
|
|
|
{ |
97
|
|
|
DateTimeZone::filter("\n\t"); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Verify behavior of filter() when $value is not a string. |
102
|
|
|
* |
103
|
|
|
* @test |
104
|
|
|
* @covers ::filter |
105
|
|
|
* @expectedException \TraderInteractive\Exceptions\FilterException |
106
|
|
|
* @expectedExceptionMessage $value not a non-empty string |
107
|
|
|
* |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
public function filterNonStringArgument() |
111
|
|
|
{ |
112
|
|
|
DateTimeZone::filter(42); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|