Completed
Pull Request — master (#93)
by lee
12:27
created

WeatherForecastTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 90
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 45 1
A testRewind() 0 9 1
A testCurrent() 0 8 1
A testNext() 0 9 1
A testValid() 0 9 1
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\WeatherForecast;
18
19
class WeatherForecastTest extends \PHPUnit_Framework_TestCase
20
{
21
    protected $fakeXml;
22
    protected $forecast;
23
24
    protected function setUp()
25
    {
26
        $fakeXml =
27
        '<weatherdata>
28
        <location>
29
            <name>Berlin</name>
30
            <type></type>
31
            <country>DE</country>
32
            <timezone></timezone>
33
            <location altitude="0" latitude="52.524368" longitude="13.41053" geobase="geonames" geobaseid="2950159"></location>
34
        </location>
35
        <credit></credit>
36
        <meta>
37
            <lastupdate></lastupdate>
38
            <calctime>0.0215</calctime>
39
            <nextupdate>
40
            </nextupdate>
41
        </meta>
42
        <sun rise="2016-12-28T07:17:18" set="2016-12-28T14:59:55"></sun>
43
        <forecast>
44
            <time day="2016-12-20">
45
                <symbol number="500" name="light rain" var="10d"></symbol>
46
                <precipitation value="0.25" type="rain"></precipitation>
47
                <windDirection deg="315" code="NW" name="Northwest"></windDirection>
48
                <windSpeed mps=" 4.38" name="Gentle Breeze"></windSpeed>
49
                <temperature day="41" min="40.59" max="41" night="40.59" eve="41" morn="41"></temperature>
50
                <pressure unit="hPa" value="1048.25"></pressure>
51
                <humidity value="97" unit="%"></humidity>
52
                <clouds value="overcast clouds" all="92" unit="%"></clouds>
53
            </time>
54
            <time day="' . date('Y-m-d') . '">
55
                <symbol number="500" name="light rain" var="10d"></symbol>
56
                <precipitation value="0.24" type="rain"></precipitation>
57
                <windDirection deg="253" code="WSW" name="West-southwest"></windDirection>
58
                <windSpeed mps="6.2" name="Moderate breeze"></windSpeed>
59
                <temperature day="40.14" min="28.96" max="40.14" night="28.96" eve="32.11" morn="39.06"></temperature>
60
                    <pressure unit="hPa" value="1048.09"></pressure>
61
                    <humidity value="97" unit="%"></humidity>
62
                    <clouds value="clear sky" all="0" unit="%"></clouds>
63
            </time>
64
        </forecast>
65
        </weatherdata>';
66
        $this->fakeXml = new \SimpleXMLElement($fakeXml);
67
        $this->forecast = new WeatherForecast($this->fakeXml, 'Berlin', 2);
68
    }
69
70
    public function testRewind()
71
    {
72
        $forecast = new WeatherForecast($this->fakeXml, 'metric', 2);
73
        $expectIndex = 0;
74
        $forecast->rewind();
75
        $position = $forecast->key();
76
77
        $this->assertSame($expectIndex, $position);
78
    }
79
80
    public function testCurrent()
81
    {
82
        $forecast = $this->forecast;
83
        $forecast->rewind();
84
        $current = $forecast->current();
85
86
        $this->assertInternalType('object', $current);
87
    }
88
89
    public function testNext()
90
    {
91
        $forecast = $this->forecast;
92
        $forecast->rewind();
93
        $forecast->next();
94
        $result = $forecast->valid();
95
96
        $this->assertFalse($result);
97
    }
98
99
    public function testValid()
100
    {
101
        $forecast = $this->forecast;
102
        $forecast->rewind();
103
        $forecast->next();
104
        $result = $forecast->valid();
105
106
        $this->assertFalse($result);
107
    }
108
}
109