|
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\OpenWeatherMap; |
|
20
|
|
|
|
|
21
|
|
|
use Cmfcmf\OpenWeatherMap\CurrentWeatherGroup; |
|
22
|
|
|
use Cmfcmf\OpenWeatherMap\Tests\FakeData; |
|
23
|
|
|
|
|
24
|
|
|
class CurrentWeatherGroupTest extends \PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
protected $fakeJson; |
|
27
|
|
|
protected $currentWeatherGroup; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->fakeJson = json_decode(FakeData::WEATHER_GROUP_JSON); |
|
32
|
|
|
$this->currentWeatherGroup = new CurrentWeatherGroup($this->fakeJson, 'metric'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testWindDirection() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->assertSame($this->currentWeatherGroup->current()->wind->direction->getValue(), 229.501); |
|
38
|
|
|
$this->currentWeatherGroup->next(); |
|
39
|
|
|
$this->assertNull($this->currentWeatherGroup->current()->wind->direction); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testRewind() |
|
43
|
|
|
{ |
|
44
|
|
|
$expectIndex = 1851632; |
|
45
|
|
|
$this->currentWeatherGroup->rewind(); |
|
46
|
|
|
$position = $this->currentWeatherGroup->key(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertSame($expectIndex, $position); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testCurrent() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->currentWeatherGroup->rewind(); |
|
54
|
|
|
$current = $this->currentWeatherGroup->current(); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertInternalType('object', $current); |
|
57
|
|
|
} |
|
58
|
|
|
public function testNext() |
|
59
|
|
|
{ |
|
60
|
|
|
$expectIndex = 1851633; |
|
61
|
|
|
$this->currentWeatherGroup->next(); |
|
62
|
|
|
$position = $this->currentWeatherGroup->key(); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertSame($expectIndex, $position); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testValid() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->currentWeatherGroup->rewind(); |
|
70
|
|
|
$this->currentWeatherGroup->next(); |
|
71
|
|
|
$result = $this->currentWeatherGroup->valid(); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertTrue($result); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|