Skip to content

Commit

Permalink
Provider class init now uses the FQCN instead of a string concatenati…
Browse files Browse the repository at this point in the history
…on, update documentation updated as required. Whitelist added to the PHPUnit config since 4.8 upgrade.
  • Loading branch information
allebb committed Mar 14, 2016
1 parent 2de8c99 commit d056b39
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ echo sprintf('The METAR report for Stansted (EGSS) is: %s', $egss);
* Alternatively, Flight simulation enthusiasts may wish to retrieve the current VATSIM reports,
* this can be achieved by changing the default provider like so:
*/
$leib->setProvider('VATSIM');
$leib->setProvider(Ballen\Metar\Providers\Vatsim::class);

/**
* Since version 2.0.1, users can now query the IVAO web service for METARs too by using the 'Ivao' provider method like so:
* Since version 2.1.0, users can now query the IVAO web service for METARs too by using the 'IVAO' provider method like so:
*/
$leib->setProvider('IVAO');
$leib->setProvider(Ballen\Metar\Providers\Ivao::class);
```


Tests and coverage
------------------

Expand All @@ -76,9 +75,8 @@ I use [TravisCI](https://travis-ci.org/) for continuous integration, which trigg
If you wish to run the tests yourself you should run the following:

```shell
# Install the Metar Library with the 'development' packages this then includes PHPUnit!
composer install --dev

# Install the Metar Library (which will include PHPUnit as part of the require-dev dependencies)
composer install

# Now we run the unit tests (from the root of the project) like so:
./vendor/bin/phpunit
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ballen/metar",
"description": "A PHP library to query aerodrome METAR information.",
"type": "library",
"keywords": ["METAR", "weather", "api", "pilots", "flightsim", "ICAO"],
"keywords": ["METAR", "weather", "api", "pilots", "flightsim", "ICAO", "ivao", "noaa", "vatsim"],
"license": "GPLv3",
"authors": [
{
Expand Down
12 changes: 6 additions & 6 deletions lib/Metar.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Metar
/**
* Stores the default namespace for loading new METAR providers from.
*/
const SERVICES_NAMESPACE = 'Ballen\Metar\Providers';
const DEFAULT_PROVIDER = 'Ballen\Metar\Providers\Noaa';

/**
* Stores the requested airfield/port ICAO code.
Expand Down Expand Up @@ -54,7 +54,7 @@ public function __construct($icao)
$this->validateIcao($this->icao);

// Set a default provider, can be overrideen with 'setProvider()' function.
$this->setProvider('Noaa');
$this->setProvider();
}

/**
Expand Down Expand Up @@ -85,11 +85,11 @@ private function validateIcao($icao)
* Changes the default 'NOAA' METAR service provider to another one eg. 'VATSIM'.
* @param string $provider METAR Provider Class/File name.
*/
public function setProvider($provider = 'Noaa')
public function setProvider($provider = self::DEFAULT_PROVIDER)
{
if (!class_exists(self::SERVICES_NAMESPACE . '\\' . $provider)) {
throw new \InvalidArgumentException('The service provider your specified does not exist in the namespace \'' . self::SERVICES_NAMESPACE . '\'');
if (!class_exists($provider)) {
throw new \InvalidArgumentException('The service provider your specified does not exist in the namespace \'' . $provider . '\'');
}
$this->metarProvider = self::SERVICES_NAMESPACE . '\\' . $provider;
$this->metarProvider = $provider;
}
}
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./lib</directory>
</whitelist>
</filter>
</phpunit>
8 changes: 0 additions & 8 deletions tests/MetarHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ class MetarHttpClientTest extends \PHPUnit_Framework_TestCase
*/
private $handler;

/**
* Setup the testcase
*/
public function setUp()
{

}

/**
* Test recieving a METAR report.
*/
Expand Down
10 changes: 5 additions & 5 deletions tests/MetarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSetInvalidIcao()
public function testSetValidProvider()
{
$metar = new Metar('EGSS');
$metar->setProvider('Noaa');
$metar->setProvider(\Ballen\Metar\Providers\Noaa::class);
}

/**
Expand All @@ -48,7 +48,7 @@ public function testSetValidProvider()
public function testSetInvalidProvider()
{
$metar = new Metar('EGSS');
$this->setExpectedException('InvalidArgumentException', 'The service provider your specified does not exist in the namespace \'' . Metar::SERVICES_NAMESPACE . '\'');
$this->setExpectedException('InvalidArgumentException', 'The service provider your specified does not exist in the namespace \'An_Invalid_Provider\'');
$metar->setProvider('An_Invalid_Provider');
}

Expand All @@ -68,18 +68,18 @@ public function testValidNoaaMetarResponse()
public function testValidVatsimMetarResponse()
{
$metar = new Metar('EGSS');
$metar->setProvider('Vatsim');
$metar->setProvider(Ballen\Metar\Providers\Vatsim::class);
$check_valid_metar = strpos($metar, 'EGSS');
$this->assertEquals($check_valid_metar, 0);
}

/**
* Test requesting a METAR report using IVAO as the provider.
*/
public function testValidIvaoMetarResponse()
{
$metar = new Metar('EGSS');
$metar->setProvider('IVAO');
$metar->setProvider(Ballen\Metar\Providers\Ivao::class);
$check_valid_metar = strpos($metar, 'EGSS');
$this->assertEquals($check_valid_metar, 0);
}
Expand Down

0 comments on commit d056b39

Please sign in to comment.