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

Commit

Permalink
Merge pull request #15 from peter279k/test_enhancement
Browse files Browse the repository at this point in the history
Test enhancement
  • Loading branch information
iranianpep authored Jan 5, 2019
2 parents 8f83104 + 2b6517c commit f9e9007
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ matrix:
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3

sudo: false

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

script:
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml --configuration phpunit.xml
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
47 changes: 22 additions & 25 deletions tests/Darksky/DarkskyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public function testForecastEmptyExcludeAndHourly()
$baseURL = 'https://api.darksky.net/forecast/12345/42.3601,-71.0589';
$queryString = 'lang=en&units=auto&extend=hourly';

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

$darksky->forecast(self::LAT, self::LONG, [], true);
}

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

try {
$darksky->forecast(self::LAT, self::LONG, self::EXCLUDES, true);
} catch (\Exception $e) {
$this->assertEquals("Failed reading: '{$baseURL}?{$queryString}'", $e->getMessage());
}
$this->expectException(\Exception::class);
$this->expectExceptionMessage("Failed reading: '{$baseURL}?{$queryString}'");

$darksky->forecast(self::LAT, self::LONG, self::EXCLUDES, true);
}

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

$this->assertTrue(isset($result['currently']));
$this->assertFalse(isset($result[self::MINUTELY]));
$this->assertFalse(isset($result[self::HOURLY]));
$this->assertFalse(isset($result[self::MINUTELY]));
$this->assertFalse(isset($result[self::ALERTS]));
$this->assertTrue(isset($result['flags']));
$this->assertArrayHasKey('currently', $result);
$this->assertArrayNotHasKey(self::MINUTELY, $result);
$this->assertArrayNotHasKey(self::HOURLY, $result);
$this->assertArrayNotHasKey(self::MINUTELY, $result);
$this->assertArrayNotHasKey(self::ALERTS, $result);
$this->assertArrayHasKey('flags', $result);

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

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

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

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

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

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

try {
$darksky->timeMachine(self::LAT, self::LONG, '409467600');
} catch (\Exception $e) {
$this->assertEquals("Failed reading: '{$baseURL}?{$queryString}'", $e->getMessage());
}
$this->expectException(\Exception::class);
$this->expectExceptionMessage("Failed reading: '{$baseURL}?{$queryString}'");

$darksky->timeMachine(self::LAT, self::LONG, '409467600');
}

public function testSetUnits()
Expand All @@ -154,7 +151,7 @@ public function testSetUnits()
$darksky->setUnits('si');
$this->assertEquals('si', $darksky->getUnits());

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

Expand Down

0 comments on commit f9e9007

Please sign in to comment.