Completed
Pull Request — master (#1)
by
unknown
01:54
created

DateTimeZoneTest::filterNonStringArgument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
     * @expectedException \TraderInteractive\Exceptions\FilterException
50
     * @expectedExceptionMessage Value failed filtering, $allowNull is set to false
51
     *
52
     * @return void
53
     */
54
    public function filterNullNotAllowed()
55
    {
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
     * @expectedException \TraderInteractive\Exceptions\FilterException
79
     * @expectedExceptionMessage Unknown or bad timezone (INVALID)
80
     */
81
    public function filterInvalidName()
82
    {
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
     * @expectedException \TraderInteractive\Exceptions\FilterException
92
     * @expectedExceptionMessage $value not a non-empty string
93
     *
94
     * @return void
95
     */
96
    public function filterEmptyValue()
97
    {
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
     * @expectedException \TraderInteractive\Exceptions\FilterException
107
     * @expectedExceptionMessage $value not a non-empty string
108
     *
109
     * @return void
110
     */
111
    public function filterNonStringArgument()
112
    {
113
        DateTimeZone::filter(42);
114
    }
115
}
116