Completed
Push — main ( 8b9660...a53349 )
by Christian
83:53 queued 68:57
created

testGetRawUVIndexWithQueryErrorException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 6
1
<?php
2
3
/*
4
 * OpenWeatherMap-PHP-API — A PHP API to parse weather data from https://OpenWeatherMap.org.
5
 *
6
 * @license MIT
7
 *
8
 * Please see the LICENSE file distributed with this source code for further
9
 * information regarding copyright and licensing.
10
 *
11
 * Please visit the following links to read about the usage policies and the license of
12
 * OpenWeatherMap data before using this library:
13
 *
14
 * @see https://OpenWeatherMap.org/price
15
 * @see https://OpenWeatherMap.org/terms
16
 * @see https://OpenWeatherMap.org/appid
17
 */
18
19
namespace Cmfcmf\OpenWeatherMap\Tests\Exceptions;
20
21
use Cmfcmf\OpenWeatherMap;
22
use Cmfcmf\OpenWeatherMap\Tests\TestHttpClient;
23
use Http\Factory\Guzzle\RequestFactory;
24
25
class OpenWeatherMapExceptionTest extends \PHPUnit_Framework_TestCase
26
{
27
    /**
28
     * @var string
29
     */
30
    protected $apiKey;
31
32
    /**
33
     * @var OpenWeatherMap
34
     */
35
    protected $owm;
36
37
    protected function setUp()
38
    {
39
        $this->apiKey = 'unicorn-rainbow';
40
        $this->owm = new OpenWeatherMap($this->apiKey, new TestHttpClient(), new RequestFactory());
41
    }
42
43
    /**
44
     * @expectedException \InvalidArgumentException
45
     */
46
    public function testGetWeatherForecastException()
47
    {
48
        $days = 20;
49
        $this->owm->getWeatherForecast('Berlin', 'imperial', 'en', '', $days);
50
    }
51
52
    /**
53
     * @expectedException \InvalidArgumentException
54
     */
55
    public function testGetDailyWeatherForecastException()
56
    {
57
        $days = 20;
58
        $this->owm->getDailyWeatherForecast('Berlin', 'imperial', 'en', '', $days);
59
    }
60
61
    /**
62
     * @expectedException \InvalidArgumentException
63
     */
64
    public function testGetRawDailyForecastDataInvalidArgumentException()
65
    {
66
        $this->owm->getRawDailyForecastData('Berlin', 'imperial', 'en', '', 'xml', 20);
67
    }
68
69
    /**
70
     * @expectedException \InvalidArgumentException
71
     * @dataProvider      uvIndexExceptionDataProvider
72
     */
73
    public function testGetRawUVIndexWithQueryErrorException($mode, $lat, $lon, $cnt, $start, $end)
74
    {
75
        $this->owm->getRawUVIndexData($mode, $lat, $lon, $cnt, $start, $end);
76
    }
77
78
    /**
79
     * @expectedException \InvalidArgumentException
80
     */
81
    public function testBuildQueryUrlParameterException()
82
    {
83
        $this->owm->getWeather(true, 'imperial', 'en', '');
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array|integer|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
    }
85
86
    /**
87
     * @expectedException \Cmfcmf\OpenWeatherMap\Exception
88
     */
89
    public function testParseXMLException()
90
    {
91
        $answer = 'I am not XML formatted data';
92
        $method = new \ReflectionMethod($this->owm, 'parseXML');
93
        $method->setAccessible(true);
94
95
        $method->invoke($this->owm, $answer);
96
    }
97
98
    /**
99
     * @expectedException \Cmfcmf\OpenWeatherMap\Exception
100
     */
101
    public function testParseXMLWithIsJsonException()
102
    {
103
        $answer = array('message' => 'simple json data');
104
        $answer = json_encode($answer);
105
        $method = new \ReflectionMethod($this->owm, 'parseXML');
106
        $method->setAccessible(true);
107
108
        $method->invoke($this->owm, $answer);
109
    }
110
111
    /**
112
     * @expectedException \Cmfcmf\OpenWeatherMap\Exception
113
     */
114
    public function testParseJsonException()
115
    {
116
        $answer = 'I am not a json format data';
117
        $method = new \ReflectionMethod($this->owm, 'parseJson');
118
        $method->setAccessible(true);
119
120
        $method->invoke($this->owm, $answer);
121
    }
122
123
    /**
124
     * @expectedException \Cmfcmf\OpenWeatherMap\Exception
125
     */
126
    public function uvIndexExceptionDataProvider()
127
    {
128
        return array(
129
            array('current', 5.4, 1, 5, null, null),
130
            array('forecast', 5.4, 1.2, '5', null, null),
131
            array('forecast', 5.4, 1.2, 0, null, null),
132
            array('forecast', 5.4, 1.2, 9, null, null),
133
            array('forecast', 5.4, 1.2, 5, new \DateTime(), new \DateTime()),
134
            array('forecast', 5.4, 12.0, null, '2000-1-1', null),
135
            array('historic', 5.4, 1.2, null, new \DateTime(), '2000-1-1'),
136
            array('historic', 5.4, 1.2, 5, new \DateTime(), new \DateTime()),
137
        );
138
    }
139
}
140