GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 864bdc...94a255 )
by Francisco
03:51
created

CalculatorTest   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 254
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 19
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 254
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A getDataLocalDate() 0 19 1
A getDataCorrectTimestamp() 0 17 1
A getDataTimeZoneName() 0 15 1
A getDataWrongLatitude() 0 13 1
A getDataWrongLongitude() 0 14 1
A getDataMaxLatitude() 0 15 1
A getDataMaxLongitude() 0 15 1
A testGetTimeZoneNameWithWrongLatitude() 0 10 2
A testGetTimeZoneNameWithWrongLongitude() 0 10 2
A testGetTimeZoneNameWithMaxLatitude() 0 5 1
A testGetTimeZoneNameWithMaxLongitude() 0 5 1
A testAdjustLatitudeWithMaxLatitude() 0 6 1
A testAdjustMaxLongitudeWithMaxLongitude() 0 6 1
A testGetLocalDate() 0 14 1
A testGetCorrectTimestamp() 0 5 1
A testGetTimeZoneName() 0 5 1
1
<?php
2
3
namespace Tests\GeoTimeZone;
4
5
use GeoTimeZone\Calculator;
6
use PHPUnit\Runner\Exception;
7
use Tests\AbstractUnitTestCase;
8
9
class CalculatorTest extends AbstractUnitTestCase
10
{
11
    const DATA_DIRECTORY = "/../../data/";
12
    
13
    protected $calculator;
14
    
15
    protected function setUp()
16
    {
17
        $this->calculator = new Calculator(__DIR__ . self::DATA_DIRECTORY);
18
    }
19
    
20
    public function getDataLocalDate()
21
    {
22
        return array(
23
            'Testing Lisbon' => array(
24
                'latitude' => 41.142700,
25
                'longitude' => -8.612150,
26
                'timestamp' => 1458844434,
27
                'expectedTimeZone' => 'Europe/Lisbon',
28
                '$expectedOffset' => 0
29
            ),
30
            'Testing Madrid' => array(
31
                'latitude' => 39.452800,
32
                'longitude' => -0.347038,
33
                'timestamp' => 1469387760,
34
                'expectedTimeZone' => 'Europe/Madrid',
35
                '$expectedOffset' => 7200
36
            )
37
        );
38
    }
39
    
40
    public function getDataCorrectTimestamp()
41
    {
42
        return array(
43
            'Testing Lisbon' => array(
44
                'latitude' => 41.142700,
45
                'longitude' => -8.612150,
46
                'timestamp' => 1458844434,
47
                'expectedTimestamp' => 1458844434,
48
            ),
49
            'Testing Madrid' => array(
50
                'latitude' => 39.452800,
51
                'longitude' => -0.347038,
52
                'timestamp' => 1469387760,
53
                'expectedTimestamp' => 1469380560,
54
            )
55
        );
56
    }
57
    
58
    public function getDataTimeZoneName()
59
    {
60
        return array(
61
            'Testing Lisbon' => array(
62
                'latitude' => 41.142700,
63
                'longitude' => -8.612150,
64
                'expectedTimeZone' => 'Europe/Lisbon',
65
            ),
66
            'Testing Madrid' => array(
67
                'latitude' => 39.452800,
68
                'longitude' => -0.347038,
69
                'expectedTimeZone' => 'Europe/Madrid',
70
            )
71
        );
72
    }
73
    
74
    public function getDataWrongLatitude()
75
    {
76
        return array(
77
            'Testing Wrong Latitude' => array(
78
                'latitude' => 10000000,
79
                'longitude' => -8.612150
80
            ),
81
            'Testing Null Latitude' => array(
82
                'latitude' => null,
83
                'longitude' => -8.612150
84
            )
85
        );
86
    }
87
    
88
    public function getDataWrongLongitude()
89
    {
90
        return array(
91
            'Testing Wrong Longitude' => array(
92
                'latitude' => 41.142700,
93
                'longitude' => 10000000,
94
            
95
            ),
96
            'Testing Null Longitude' => array(
97
                'latitude' => 41.142700,
98
                'longitude' => null,
99
            )
100
        );
101
    }
102
    
103
    public function getDataMaxLatitude()
104
    {
105
        return array(
106
            'Testing Positive Max Latitude' => array(
107
                'latitude' => 90.0,
108
                'longitude' => -8.612150,
109
                'adjustedLatitude' => 89.9999
110
            ),
111
            'Testing Negative Max Latitude' => array(
112
                'latitude' => -90.0,
113
                'longitude' => -8.612150,
114
                'adjustedLatitude' => -89.9999
115
            )
116
        );
117
    }
118
    
119
    public function getDataMaxLongitude()
120
    {
121
        return array(
122
            'Testing Positive Max Longitude' => array(
123
                'latitude' => -8.612150,
124
                'longitude' => 180.0,
125
                'adjustedLongitude' => 179.9999
126
            ),
127
            'Testing Negative Max Longitude' => array(
128
                'latitude' => -8.612150,
129
                'longitude' => -180.0,
130
                'adjustedLongitude' => -179.9999
131
            )
132
        );
133
    }
134
    
135
    /**
136
     * @dataProvider getDataWrongLatitude
137
     * @param $latitude
138
     * @param $longitude
139
     */
140
    public function testGetTimeZoneNameWithWrongLatitude($latitude, $longitude)
141
    {
142
        try {
143
            $timeZone = $this->calculator->getTimeZoneName($latitude, $longitude);
144
            $this->assertEquals($timeZone, "none");
145
        } catch (Exception $error) {
146
            $this->expectException(\ErrorException::class);
147
            $this->expectExceptionMessage("Invalid latitude: {$latitude}");
148
        }
149
    }
150
    
151
    /**
152
     * @dataProvider getDataWrongLongitude
153
     * @param $latitude
154
     * @param $longitude
155
     */
156
    public function testGetTimeZoneNameWithWrongLongitude($latitude, $longitude)
157
    {
158
        try {
159
            $timeZone = $this->calculator->getTimeZoneName($latitude, $longitude);
160
            $this->assertEquals($timeZone, "none");
161
        } catch (Exception $error) {
162
            $this->expectException(\ErrorException::class);
163
            $this->expectExceptionMessage("Invalid longitude: {$longitude}");
164
        }
165
    }
166
    
167
    /**
168
     * @dataProvider getDataMaxLatitude
169
     * @param $latitude
170
     * @param $longitude
171
     */
172
    public function testGetTimeZoneNameWithMaxLatitude($latitude, $longitude)
173
    {
174
        $timeZone = $this->calculator->getTimeZoneName($latitude, $longitude);
175
        $this->assertTrue(is_string($timeZone));
176
    }
177
    
178
    /**
179
     * @dataProvider getDataMaxLongitude
180
     * @param $latitude
181
     * @param $longitude
182
     */
183
    public function testGetTimeZoneNameWithMaxLongitude($latitude, $longitude)
184
    {
185
        $timeZone = $this->calculator->getTimeZoneName($latitude, $longitude);
186
        $this->assertTrue(is_string($timeZone));
187
    }
188
    
189
    /**
190
     * @dataProvider getDataMaxLatitude
191
     * @param $latitude
192
     * @param $longitude
193
     * @param $adjustedLatitude
194
     */
195
    public function testAdjustLatitudeWithMaxLatitude($latitude, $longitude, $adjustedLatitude)
0 ignored issues
show
Unused Code introduced by
The parameter $longitude is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
196
    {
197
        $method = $this->getPrivateMethod(get_class($this->calculator), 'adjustLatitude');
198
        $latitudeToTest = $method->invokeArgs($this->calculator, array($latitude));
199
        $this->assertEquals($adjustedLatitude, $latitudeToTest);
200
    }
201
    
202
    /**
203
     * @dataProvider getDataMaxLongitude
204
     * @param $latitude
205
     * @param $longitude
206
     * @param $adjustedLongitude
207
     */
208
    public function testAdjustMaxLongitudeWithMaxLongitude($latitude, $longitude, $adjustedLongitude)
0 ignored issues
show
Unused Code introduced by
The parameter $latitude is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
209
    {
210
        $method = $this->getPrivateMethod(get_class($this->calculator), 'adjustLongitude');
211
        $longitudeToTest = $method->invokeArgs($this->calculator, array($longitude));
212
        $this->assertEquals($adjustedLongitude, $longitudeToTest);
213
    }
214
    
215
    /**
216
     * @dataProvider getDataLocalDate
217
     * @param $latitude
218
     * @param $longitude
219
     * @param $timestamp
220
     * @param $expectedTimeZone
221
     * @param $expectedOffset
222
     */
223
    public function testGetLocalDate($latitude, $longitude, $timestamp, $expectedTimeZone, $expectedOffset)
224
    {
225
        $localDate = $this->calculator->getLocalDate($latitude, $longitude, $timestamp);
226
        
227
        $this->assertInstanceOf('DateTime', $localDate);
228
        $this->assertEquals(
229
            $localDate->getTimezone()->getName(),
230
            $expectedTimeZone
231
        );
232
        $this->assertEquals(
233
            $localDate->getOffset(),
234
            $expectedOffset
235
        );
236
    }
237
    
238
    /**
239
     * @dataProvider getDataCorrectTimestamp
240
     * @param $latitude
241
     * @param $longitude
242
     * @param $timestamp
243
     * @param $expectedTimestamp
244
     */
245
    public function testGetCorrectTimestamp($latitude, $longitude, $timestamp, $expectedTimestamp)
246
    {
247
        $correctTimestamp = $this->calculator->getCorrectTimestamp($latitude, $longitude, $timestamp);
248
        $this->assertEquals($correctTimestamp, $expectedTimestamp);
249
    }
250
    
251
    /**
252
     * @dataProvider getDataTimeZoneName
253
     * @param $latitude
254
     * @param $longitude
255
     * @param $expectedTimeZone
256
     */
257
    public function testGetTimeZoneName($latitude, $longitude, $expectedTimeZone)
258
    {
259
        $timeZoneName = $this->calculator->getTimeZoneName($latitude, $longitude);
260
        $this->assertEquals($timeZoneName, $expectedTimeZone);
261
    }
262
}
263