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