Completed
Push — peter279k-master ( fcaf21...a307a7 )
by Christian
43:15 queued 28:09
created

WeatherHistoryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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 View Code Duplication
    public function testRewind()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
32
    {
33
        $expectIndex = 0;
34
        $history = $this->history;
35
        $history->rewind();
36
        $position = $history->key();
37
38
        $this->assertSame($expectIndex, $position);
39
    }
40
41
    public function testCurrent()
42
    {
43
        $history = $this->history;
44
        $history->rewind();
45
        $current = $history->current();
46
47
        $this->assertInternalType('object', $current);
48
    }
49
50 View Code Duplication
    public function testNext()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
51
    {
52
        $expectIndex = 1;
53
        $history = $this->history;
54
        $history->next();
55
        $position = $history->key();
56
57
        $this->assertSame($expectIndex, $position);
58
    }
59
60
    public function testValid()
61
    {
62
        $history = $this->history;
63
        $history->rewind();
64
        $history->next();
65
        $result = $history->valid();
66
67
        $this->assertTrue($result);
68
    }
69
70 View Code Duplication
    public function testJsonHasCountryAndPopulation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
71
    {
72
        $fakeJson = '{
73
            "cod":"200","calctime":"123456789","message":0.0032,"city_id":{"id":1851632,"name":"Shuzenji","coord":{"lon":138.933334,"lat":34.966671},"country":"JP"},
74
            "cnt":10,
75
            "list":[{
76
                "city":{
77
                    "country": "Berlin", 
78
                    "population": "10,000"
79
                }
80
                },{
81
                    "dt":1406080800,
82
                    "temp":{
83
                        "day":297.77,
84
                        "min":293.52,
85
                        "max":297.77,
86
                        "night":293.52,
87
                        "eve":297.77,
88
                        "morn":297.77
89
                    },
90
                    "pressure":925.04,
91
                    "humidity":76,
92
                    "weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],
93
                    "main":{"temp":306.15,"pressure":1013,"humidity":44,"temp_min":306,"temp_max":306},
94
                    "clouds":{"all":90},
95
                    "wind":{"speed":5.71,"deg":229.501}
96
            }]
97
        }';
98
        $fakeJson = json_decode($fakeJson, true);
99
        $history = new WeatherHistory($fakeJson, 'Berlin');
100
101
        $history->rewind();
102
        $result = $history->valid();
103
104
        $this->assertTrue($result);
105
    }
106
107 View Code Duplication
    public function testJsonWithRainKey()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
108
    {
109
        $fakeJson = '{
110
            "cod":"200","calctime":"123456789","message":0.0032,"city_id":{"id":1851632,"name":"Shuzenji","coord":{"lon":138.933334,"lat":34.966671},"country":"JP"},
111
            "cnt":10,
112
            "list":[{
113
                "city":{
114
                    "country": "Berlin", 
115
                    "population": "10,000"
116
                }
117
                },{
118
                    "dt":1406080800,
119
                    "temp":{
120
                        "day":297.77,
121
                        "min":293.52,
122
                        "max":297.77,
123
                        "night":293.52,
124
                        "eve":297.77,
125
                        "morn":297.77
126
                    },
127
                    "pressure":925.04,
128
                    "humidity":76,
129
                    "weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],
130
                    "main":{"temp":306.15,"pressure":1013,"humidity":44,"temp_min":306,"temp_max":306},
131
                    "clouds":{"all":90},
132
                    "wind":{"speed":5.71,"deg":229.501},
133
                    "rain":{"3h":3}
134
            }]
135
        }';
136
        $fakeJson = json_decode($fakeJson, true);
137
        $history = new WeatherHistory($fakeJson, 'Berlin');
138
        
139
        $history->rewind();
140
        $result = $history->valid();
141
142
        $this->assertTrue($result);
143
    }
144
}
145