1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright Zikula Foundation 2014 - Zikula Application Framework |
4
|
|
|
* |
5
|
|
|
* This work is contributed to the Zikula Foundation under one or more |
6
|
|
|
* Contributor Agreements and licensed to You under the following license: |
7
|
|
|
* |
8
|
|
|
* @license GNU/LGPv3 (or at your option any later version). |
9
|
|
|
* @package OpenWeatherMap-PHP-Api |
10
|
|
|
* |
11
|
|
|
* Please see the NOTICE file distributed with this source code for further |
12
|
|
|
* information regarding copyright and licensing. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Cmfcmf\OpenWeatherMap\Tests\OpenWeatherMap; |
16
|
|
|
|
17
|
|
|
use Cmfcmf\OpenWeatherMap\Tests\FakeData; |
18
|
|
|
use \Cmfcmf\OpenWeatherMap\WeatherHistory; |
19
|
|
|
|
20
|
|
|
class WeatherHistoryTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
protected $fakeJson; |
23
|
|
|
protected $history; |
24
|
|
|
|
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->fakeJson = json_decode(FakeData::WEATHER_HISTORY_JSON, true); |
28
|
|
|
$this->history = new WeatherHistory($this->fakeJson, 'Berlin'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testRewind() |
32
|
|
|
{ |
33
|
|
|
$expectIndex = 0; |
34
|
|
|
$this->history->rewind(); |
35
|
|
|
$position = $this->history->key(); |
36
|
|
|
|
37
|
|
|
$this->assertSame($expectIndex, $position); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testCurrent() |
41
|
|
|
{ |
42
|
|
|
$this->history->rewind(); |
43
|
|
|
$current = $this->history->current(); |
44
|
|
|
|
45
|
|
|
$this->assertInternalType('object', $current); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testNext() |
49
|
|
|
{ |
50
|
|
|
$expectIndex = 1; |
51
|
|
|
$this->history->next(); |
52
|
|
|
$position = $this->history->key(); |
53
|
|
|
|
54
|
|
|
$this->assertSame($expectIndex, $position); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testValid() |
58
|
|
|
{ |
59
|
|
|
$this->history->rewind(); |
60
|
|
|
$this->history->next(); |
61
|
|
|
$this->assertTrue($this->history->valid()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function testJsonHasCountryAndPopulation() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$fakeJson = json_decode(FakeData::WEATHER_HISTORY_WITH_COUNTRY_JSON, true); |
67
|
|
|
$history = new WeatherHistory($fakeJson, 'Berlin'); |
68
|
|
|
|
69
|
|
|
$history->rewind(); |
70
|
|
|
$this->assertTrue($history->valid()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
public function testJsonWithRainKey() |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$fakeJson = json_decode(FakeData::WEATHER_HISTORY_WITH_RAIN_JSON, true); |
76
|
|
|
$history = new WeatherHistory($fakeJson, 'Berlin'); |
77
|
|
|
|
78
|
|
|
$history->rewind(); |
79
|
|
|
$this->assertTrue($history->valid()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.