Completed
Pull Request — master (#140)
by Christian
10:52 queued 09:44
created

CityTest::timezoneDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * OpenWeatherMap-PHP-API — A PHP API to parse weather data from https://OpenWeatherMap.org.
5
 *
6
 * @license MIT
7
 *
8
 * Please see the LICENSE file distributed with this source code for further
9
 * information regarding copyright and licensing.
10
 *
11
 * Please visit the following links to read about the usage policies and the license of
12
 * OpenWeatherMap data before using this library:
13
 *
14
 * @see https://OpenWeatherMap.org/price
15
 * @see https://OpenWeatherMap.org/terms
16
 * @see https://OpenWeatherMap.org/appid
17
 */
18
19
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
20
21
use Cmfcmf\OpenWeatherMap\Util\City;
22
23
class CityTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @dataProvider timezoneDataProvider
27
     */
28
    public function testTimezoneConversion($offsetString, $offsetSeconds)
29
    {
30
        $class = new \ReflectionClass(City::class);
31
        $method = $class->getMethod("timezoneOffsetInSecondsToHours");
32
        $method->setAccessible(true);
33
34
        $this->assertSame($offsetString, $method->invoke(null, $offsetSeconds));
35
        $offsetTimezone = new \DateTimeZone($offsetString);
36
        $this->assertSame($offsetSeconds, $offsetTimezone->getOffset(new \DateTime("now", new \DateTimeZone("GMT"))));
37
    }
38
39
    public function timezoneDataProvider()
40
    {
41
        return [
42
            ["+0100", 3600],
43
            ["+0100", 3600],
44
            ["+0030", 1800],
45
            ["+0015", 900],
46
            ["+0000", 0],
47
            ["+0545", 20700],
48
        ];
49
    }
50
}
51