Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Commit f9e9007

Browse files
authored
Merge pull request #15 from peter279k/test_enhancement
Test enhancement
2 parents 8f83104 + 2b6517c commit f9e9007

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ matrix:
99
- php: 7.0
1010
- php: 7.1
1111
- php: 7.2
12+
- php: 7.3
1213

1314
sudo: false
1415

@@ -25,7 +26,7 @@ before_script:
2526
- ./cc-test-reporter before-build
2627

2728
script:
28-
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml --configuration phpunit.xml
29+
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
2930

3031
after_script:
3132
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

tests/Darksky/DarkskyTest.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ public function testForecastEmptyExcludeAndHourly()
4141
$baseURL = 'https://api.darksky.net/forecast/12345/42.3601,-71.0589';
4242
$queryString = 'lang=en&units=auto&extend=hourly';
4343

44-
try {
45-
$darksky->forecast(self::LAT, self::LONG, [], true);
46-
} catch (\Exception $e) {
47-
$this->assertEquals("Failed reading: '{$baseURL}?{$queryString}'", $e->getMessage());
48-
}
44+
$this->expectException(\Exception::class);
45+
$this->expectExceptionMessage("Failed reading: '{$baseURL}?{$queryString}'");
46+
47+
$darksky->forecast(self::LAT, self::LONG, [], true);
4948
}
5049

5150
public function testForecastWithExcludeAndHourly()
@@ -54,11 +53,10 @@ public function testForecastWithExcludeAndHourly()
5453
$baseURL = 'https://api.darksky.net/forecast/12345/42.3601,-71.0589';
5554
$queryString = 'lang=en&units=auto&exclude=minutely%2Chourly%2Cdaily%2Calerts&extend=hourly';
5655

57-
try {
58-
$darksky->forecast(self::LAT, self::LONG, self::EXCLUDES, true);
59-
} catch (\Exception $e) {
60-
$this->assertEquals("Failed reading: '{$baseURL}?{$queryString}'", $e->getMessage());
61-
}
56+
$this->expectException(\Exception::class);
57+
$this->expectExceptionMessage("Failed reading: '{$baseURL}?{$queryString}'");
58+
59+
$darksky->forecast(self::LAT, self::LONG, self::EXCLUDES, true);
6260
}
6361

6462
public function testForecastWithExclude()
@@ -74,14 +72,14 @@ public function testForecastWithExclude()
7472
$result = $stub->forecast(self::EXCLUDES, true);
7573
$result = json_decode($result, true);
7674

77-
$this->assertTrue(isset($result['currently']));
78-
$this->assertFalse(isset($result[self::MINUTELY]));
79-
$this->assertFalse(isset($result[self::HOURLY]));
80-
$this->assertFalse(isset($result[self::MINUTELY]));
81-
$this->assertFalse(isset($result[self::ALERTS]));
82-
$this->assertTrue(isset($result['flags']));
75+
$this->assertArrayHasKey('currently', $result);
76+
$this->assertArrayNotHasKey(self::MINUTELY, $result);
77+
$this->assertArrayNotHasKey(self::HOURLY, $result);
78+
$this->assertArrayNotHasKey(self::MINUTELY, $result);
79+
$this->assertArrayNotHasKey(self::ALERTS, $result);
80+
$this->assertArrayHasKey('flags', $result);
8381

84-
$this->expectException('\Exception');
82+
$this->expectException(\Exception::class);
8583
$validExcludes = implode(',', Darksky::VALID_EXCLUDE);
8684
$this->expectExceptionMessage("Invalid excludes. Provide valid excludes: {$validExcludes}");
8785

@@ -104,7 +102,7 @@ public function testForecastHourly()
104102
$result = json_decode($result, true);
105103

106104
// next 48 hours
107-
$this->assertEquals(49, count($result[self::HOURLY]['data']));
105+
$this->assertCount(49, $result[self::HOURLY]['data']);
108106

109107
// Configure the stub.
110108
$stub = $this->createMock(Darksky::class);
@@ -115,7 +113,7 @@ public function testForecastHourly()
115113
$result = json_decode($result, true);
116114

117115
// next 168 hours
118-
$this->assertEquals(169, count($result[self::HOURLY]['data']));
116+
$this->assertCount(169, $result[self::HOURLY]['data']);
119117
}
120118

121119
public function testTimeMachine()
@@ -139,11 +137,10 @@ public function testTimeMachineWithException()
139137
$baseURL = 'https://api.darksky.net/forecast/12345/42.3601,-71.0589,409467600';
140138
$queryString = 'lang=en&units=auto';
141139

142-
try {
143-
$darksky->timeMachine(self::LAT, self::LONG, '409467600');
144-
} catch (\Exception $e) {
145-
$this->assertEquals("Failed reading: '{$baseURL}?{$queryString}'", $e->getMessage());
146-
}
140+
$this->expectException(\Exception::class);
141+
$this->expectExceptionMessage("Failed reading: '{$baseURL}?{$queryString}'");
142+
143+
$darksky->timeMachine(self::LAT, self::LONG, '409467600');
147144
}
148145

149146
public function testSetUnits()
@@ -154,7 +151,7 @@ public function testSetUnits()
154151
$darksky->setUnits('si');
155152
$this->assertEquals('si', $darksky->getUnits());
156153

157-
$this->expectException('\Exception');
154+
$this->expectException(\Exception::class);
158155
$validUnits = implode(',', Darksky::VALID_UNITS);
159156
$this->expectExceptionMessage("'invalid-units' is not a valid unit. Valid units: {$validUnits}");
160157

0 commit comments

Comments
 (0)