Completed
Push — release-2.1 ( fef2e0...c32e0e )
by Christian
03:39
created

ForecastDailyTest::testTemperatureImperial()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 29

Duplication

Lines 38
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 38
loc 38
rs 8.8571
cc 1
eloc 29
nc 1
nop 0
1
<?php
2
/**
3
 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
4
 *
5
 * @license MIT
6
 *
7
 * Please see the LICENSE file distributed with this source code for further
8
 * information regarding copyright and licensing.
9
 *
10
 * Please visit the following links to read about the usage policies and the license of
11
 * OpenWeatherMap before using this class:
12
 *
13
 * @see http://www.OpenWeatherMap.org
14
 * @see http://www.OpenWeatherMap.org/terms
15
 * @see http://openweathermap.org/appid
16
 */
17
18
namespace Cmfcmf\OpenWeatherMap\IntegTests;
19
20
use Cmfcmf\OpenWeatherMap;
21
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
22
23
class ForecastDailyTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var \OpenWeatherMap
27
     */
28
    protected $owm;
29
30 View Code Duplication
    protected function setUp()
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...
31
    {
32
        $ini = parse_ini_file(__DIR__ . '/ApiKey.ini');
33
        $apiKey = $ini['api_key'];
34
35
        $this->owm = new OpenWeatherMap();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Cmfcmf\OpenWeatherMap() of type object<Cmfcmf\OpenWeatherMap> is incompatible with the declared type object<OpenWeatherMap> of property $owm.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
        $this->owm->setApiKey($apiKey);
37
    }
38
39 View Code Duplication
    public function testTemperatureMetric()
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...
40
    {
41
        $forecast = $this->owm->getWeatherForecast('Berlin', 'metric', 'de', '', 10);
42
43
        $now = new \DateTime();
44
        $this->assertEquals($now->format('d.m.Y H:i'), $forecast->lastUpdate->format('d.m.Y H:i'));
45
46
        $this->assertEquals('Berlin', $forecast->city->name);
47
        $this->assertEquals('05:00:53', $forecast->sun->rise->format("H:i:s"));
48
        $this->assertEquals('17:25:40', $forecast->sun->set->format("H:i:s"));
49
50
        $this->assertEquals(10, iterator_count($forecast));
51
52
        $forecast_arr = iterator_to_array($forecast);
53
54
        $this->assertEquals('4.59 &deg;C', $forecast_arr[0]->temperature);
55
        $this->assertEquals('7.34 &deg;C', $forecast_arr[1]->temperature);
56
        $this->assertEquals('5.58 &deg;C', $forecast_arr[2]->temperature->now);
57
        $this->assertEquals('6.14 &deg;C', $forecast_arr[3]->temperature);
58
        $this->assertEquals('7.56 &deg;C', $forecast_arr[4]->temperature);
59
        $this->assertEquals('10.24 &deg;C', $forecast_arr[5]->temperature);
60
        $this->assertEquals('9.34 &deg;C', $forecast_arr[6]->temperature);
61
        $this->assertEquals('10.93 &deg;C', $forecast_arr[7]->temperature->now);
62
        $this->assertEquals('8.8 &deg;C', $forecast_arr[8]->temperature);
63
        $this->assertEquals('8.02 &deg;C', $forecast_arr[9]->temperature);
64
65
        $this->assertEquals('2.71 &deg;C', $forecast_arr[0]->temperature->min);
66
        $this->assertEquals('9.07 &deg;C', $forecast_arr[1]->temperature->max);
67
        $this->assertEquals('8.31 &deg;C', $forecast_arr[2]->temperature->day);
68
        $this->assertEquals('2.93 &deg;C', $forecast_arr[3]->temperature->morning);
69
        $this->assertEquals('8.99 &deg;C', $forecast_arr[4]->temperature->evening);
70
        $this->assertEquals('8.91 &deg;C', $forecast_arr[5]->temperature->night);
71
72
        $this->assertEquals('&deg;C', $forecast_arr[6]->temperature->getUnit());
73
        $this->assertEquals('10.93', $forecast_arr[7]->temperature->getValue());
74
        $this->assertEmpty($forecast_arr[8]->temperature->getDescription());
75
        $this->assertEquals('8.02 &deg;C', $forecast_arr[9]->temperature->getFormatted());
76
    }
77
78 View Code Duplication
    public function testTemperatureImperial()
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...
79
    {
80
        $forecast = $this->owm->getWeatherForecast('New York', 'imperial', 'en', '', 10);
81
82
        $now = new \DateTime();
83
        $this->assertEquals($now->format('m-d-Y H:i'), $forecast->lastUpdate->format('m-d-Y H:i'));
84
85
        $this->assertEquals('New York', $forecast->city->name);
86
        $this->assertEquals('10:53:25', $forecast->sun->rise->format("H:i:s"));
87
        $this->assertEquals('23:11:57', $forecast->sun->set->format("H:i:s"));
88
89
        $this->assertEquals(10, iterator_count($forecast));
90
91
        $forecast_arr = iterator_to_array($forecast);
92
93
        $this->assertEquals('48.88 F', $forecast_arr[0]->temperature);
94
        $this->assertEquals('55.56 F', $forecast_arr[1]->temperature);
95
        $this->assertEquals('57.08 F', $forecast_arr[2]->temperature->now);
96
        $this->assertEquals('50.85 F', $forecast_arr[3]->temperature);
97
        $this->assertEquals('47.79 F', $forecast_arr[4]->temperature);
98
        $this->assertEquals('46.21 F', $forecast_arr[5]->temperature);
99
        $this->assertEquals('47.73 F', $forecast_arr[6]->temperature);
100
        $this->assertEquals('43.52 F', $forecast_arr[7]->temperature->now);
101
        $this->assertEquals('34.79 F', $forecast_arr[8]->temperature);
102
        $this->assertEquals('30.35 F', $forecast_arr[9]->temperature);
103
104
        $this->assertEquals('47.75 F', $forecast_arr[0]->temperature->min);
105
        $this->assertEquals('64.53 F', $forecast_arr[1]->temperature->max);
106
        $this->assertEquals('69.4 F', $forecast_arr[2]->temperature->day);
107
        $this->assertEquals('58.71 F', $forecast_arr[3]->temperature->morning);
108
        $this->assertEquals('49.5 F', $forecast_arr[4]->temperature->evening);
109
        $this->assertEquals('43.63 F', $forecast_arr[5]->temperature->night);
110
111
        $this->assertEquals('F', $forecast_arr[6]->temperature->getUnit());
112
        $this->assertEquals('43.52', $forecast_arr[7]->temperature->getValue());
113
        $this->assertEmpty($forecast_arr[8]->temperature->getDescription());
114
        $this->assertEquals('30.35 F', $forecast_arr[9]->temperature->getFormatted());
115
    }
116
117
    public function testWindMetric()
118
    {
119
        $forecast = $this->owm->getWeatherForecast('Moscow', 'metric', 'ru', '', 9);
120
121
        $this->assertEquals('Moscow', $forecast->city->name);
122
        $this->assertEquals('RU', $forecast->city->country);
123
        $this->assertEquals(524901, $forecast->city->id);
124
        $this->assertEquals('37.615555', $forecast->city->lon);
125
        $this->assertEquals('55.75222', $forecast->city->lat);
126
127
        $this->assertEquals('03:22:56', $forecast->sun->rise->format("H:i:s"));
128
        $this->assertEquals('15:50:08', $forecast->sun->set->format("H:i:s"));
129
130
        $this->assertEquals(9, iterator_count($forecast));
131
132
        $forecast_arr = iterator_to_array($forecast);
133
134
        $this->assertEquals('5.41 m/s', $forecast_arr[0]->wind->speed);
135
        $this->assertEquals('61 ENE', $forecast_arr[1]->wind->direction);
136
    }
137
}
138