Completed
Pull Request — master (#71)
by Christian
06:10 queued 03:55
created

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