1 | <?php |
||
23 | class CurrentWeatherTest extends \PHPUnit_Framework_TestCase |
||
24 | { |
||
25 | /** |
||
26 | * @var OpenWeatherMap |
||
27 | */ |
||
28 | protected $apiKey; |
||
29 | protected $owm; |
||
30 | |||
31 | protected function setUp() |
||
32 | { |
||
33 | // Load the app configuration |
||
34 | $ini = parse_ini_file(__DIR__ . '/ApiKey.ini'); |
||
35 | $this->apiKey = $ini['api_key']; |
||
36 | |||
37 | $this->owm = new OpenWeatherMap(); |
||
38 | $this->owm->setApiKey($this->apiKey); |
||
39 | } |
||
40 | |||
41 | public function testByCity() |
||
42 | { |
||
43 | // Default units (imperial) and language (English) |
||
|
|||
44 | $weather = $this->owm->getWeather('Paris'); |
||
45 | $this->assertEquals('49.39 F', $weather->temperature); |
||
46 | |||
47 | // Default language (English) |
||
48 | $weather = $this->owm->getWeather('Atlanta', 'imperial'); |
||
49 | $this->assertEquals(38.18, $weather->temperature->getValue()); |
||
50 | $weather = $this->owm->getWeather('London', 'metric'); |
||
51 | $this->assertEquals(4.66, $weather->temperature->getValue()); |
||
52 | $this->assertEquals('°C', $weather->temperature->getUnit()); |
||
53 | |||
54 | // No defaults |
||
55 | $weather = $this->owm->getWeather('Chicago', 'imperial', 'en'); |
||
56 | $this->assertEquals('13.88 F', $weather->temperature->getFormatted()); |
||
57 | $weather = $this->owm->getWeather('Prague', 'metric', 'en'); |
||
58 | $this->assertEquals(3.58, $weather->temperature->now->getValue()); |
||
59 | $this->assertEmpty($weather->temperature->min->getDescription()); |
||
60 | $this->assertEquals('3.58 °C', $weather->temperature->max->getFormatted()); |
||
61 | } |
||
62 | |||
63 | public function testCityNotFound() |
||
64 | { |
||
65 | // City doesn't exist |
||
66 | try { |
||
67 | $this->owm->getWeather('InvalidCity'); |
||
68 | } catch (OWMException $e) { |
||
69 | $this->assertEquals(404, $e->getCode()); |
||
70 | $this->assertEquals('Error: Not found city', $e->getMessage()); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | public function testByCityCountry() |
||
75 | { |
||
76 | $weather = $this->owm->getWeather('London,CA'); |
||
77 | |||
78 | // Geo coordinates |
||
79 | $this->assertEquals('-81.23', $weather->city->lon); |
||
80 | $this->assertEquals('42.98', $weather->city->lat); |
||
81 | |||
82 | // Country |
||
83 | $this->assertEquals('CA', $weather->city->country); |
||
84 | } |
||
85 | |||
86 | public function testByCityID() |
||
91 | |||
92 | public function testByCoordinates() |
||
97 | |||
98 | public function testCurrentBulkCheck() |
||
99 | { |
||
100 | // Download the test data set |
||
101 | $testDataUrl = |
||
119 | } |
||
120 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.