Skip to content

Commit e35e1e2

Browse files
committed
tests: added air pollution entities tests
1 parent e8a6665 commit e35e1e2

9 files changed

+162
-14
lines changed

src/Resource/AirPollutionResource.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
use ProgrammatorDev\Api\Method;
66
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollution;
77
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionCollection;
8-
use ProgrammatorDev\OpenWeatherMap\Resource\Util\ValidationTrait;
98
use ProgrammatorDev\Validator\Exception\ValidationException;
109
use Psr\Http\Client\ClientExceptionInterface;
1110

1211
class AirPollutionResource extends Resource
1312
{
14-
use ValidationTrait;
15-
1613
/**
1714
* @throws ValidationException
1815
* @throws ClientExceptionInterface

src/Resource/GeocodingResource.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
use ProgrammatorDev\Api\Method;
66
use ProgrammatorDev\OpenWeatherMap\Entity\Geocoding\ZipLocation;
77
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
8-
use ProgrammatorDev\OpenWeatherMap\Resource\Util\ValidationTrait;
98
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
109
use ProgrammatorDev\Validator\Exception\ValidationException;
1110
use Psr\Http\Client\ClientExceptionInterface;
1211

1312
class GeocodingResource extends Resource
1413
{
1514
use EntityTrait;
16-
use ValidationTrait;
1715

1816
private const NUM_RESULTS = 5;
1917

src/Resource/Resource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
66
use ProgrammatorDev\OpenWeatherMap\Resource\Util\CacheTrait;
7+
use ProgrammatorDev\OpenWeatherMap\Resource\Util\ValidationTrait;
78

89
class Resource
910
{
1011
use CacheTrait;
12+
use ValidationTrait;
1113

1214
public function __construct(protected OpenWeatherMap $api) {}
1315
}

src/Resource/Util/ValidationTrait.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ trait ValidationTrait
1212
/**
1313
* @throws ValidationException
1414
*/
15-
private function validateQuery(string $query, string $name): void
15+
protected function validateQuery(string $query, string $name): void
1616
{
1717
Validator::notBlank()->assert($query, $name);
1818
}
1919

2020
/**
2121
* @throws ValidationException
2222
*/
23-
private function validatePositive(int $number, string $name): void
23+
protected function validatePositive(int $number, string $name): void
2424
{
2525
Validator::greaterThan(0)->assert($number, $name);
2626
}
2727

2828
/**
2929
* @throws ValidationException
3030
*/
31-
private function validateCoordinate(float $latitude, float $longitude): void
31+
protected function validateCoordinate(float $latitude, float $longitude): void
3232
{
3333
Validator::range(-90, 90)->assert($latitude, 'latitude');
3434
Validator::range(-180, 180)->assert($longitude, 'longitude');
@@ -37,31 +37,31 @@ private function validateCoordinate(float $latitude, float $longitude): void
3737
/**
3838
* @throws ValidationException
3939
*/
40-
private function validateCountryCode(string $countryCode): void
40+
protected function validateCountryCode(string $countryCode): void
4141
{
4242
Validator::country()->assert($countryCode, 'countryCode');
4343
}
4444

4545
/**
4646
* @throws ValidationException
4747
*/
48-
private function validateLanguage(string $language): void
48+
protected function validateLanguage(string $language): void
4949
{
5050
Validator::choice(Language::getOptions())->assert($language, 'language');
5151
}
5252

5353
/**
5454
* @throws ValidationException
5555
*/
56-
private function validateUnitSystem(string $unitSystem): void
56+
protected function validateUnitSystem(string $unitSystem): void
5757
{
5858
Validator::choice(UnitSystem::getOptions())->assert($unitSystem, 'unitSystem');
5959
}
6060

6161
/**
6262
* @throws ValidationException
6363
*/
64-
private function validateDateOrder(\DateTimeInterface $startDate, \DateTimeInterface $endDate): void
64+
protected function validateDateOrder(\DateTimeInterface $startDate, \DateTimeInterface $endDate): void
6565
{
6666
Validator::greaterThan(
6767
constraint: $startDate,

src/Resource/WeatherResource.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
use ProgrammatorDev\OpenWeatherMap\Entity\Weather\WeatherCollection;
88
use ProgrammatorDev\OpenWeatherMap\Resource\Util\LanguageTrait;
99
use ProgrammatorDev\OpenWeatherMap\Resource\Util\UnitSystemTrait;
10-
use ProgrammatorDev\OpenWeatherMap\Resource\Util\ValidationTrait;
1110
use ProgrammatorDev\Validator\Exception\ValidationException;
1211
use Psr\Http\Client\ClientExceptionInterface;
1312

1413
class WeatherResource extends Resource
1514
{
1615
use LanguageTrait;
1716
use UnitSystemTrait;
18-
use ValidationTrait;
1917

2018
private const NUM_RESULTS = 40;
2119

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Unit\AirPollution;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionCollection;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionData;
7+
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
8+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
9+
10+
class AirPollutionCollectionTest extends AbstractTest
11+
{
12+
public function testMethods()
13+
{
14+
$entity = new AirPollutionCollection([
15+
'coord' => [
16+
'lat' => 50,
17+
'lon' => 50
18+
],
19+
'list' => [
20+
[
21+
'dt' => 1715279409,
22+
'main' => [
23+
'aqi' => 1
24+
],
25+
'components' => [
26+
'co' => 100,
27+
'no' => 0,
28+
'no2' => 1,
29+
'o3' => 100,
30+
'so2' => 1,
31+
'pm2_5' => 1,
32+
'pm10' => 1,
33+
'nh3' => 1
34+
]
35+
]
36+
]
37+
]);
38+
39+
$this->assertInstanceOf(Coordinate::class, $entity->getCoordinate());
40+
$this->assertContainsOnlyInstancesOf(AirPollutionData::class, $entity->getData());
41+
}
42+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Unit\AirPollution;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionData;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirQuality;
7+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
8+
9+
class AirPollutionDataTest extends AbstractTest
10+
{
11+
public function testMethods()
12+
{
13+
$entity = new AirPollutionData([
14+
'dt' => 1715279409,
15+
'main' => [
16+
'aqi' => 1
17+
],
18+
'components' => [
19+
'co' => 100,
20+
'no' => 0,
21+
'no2' => 1,
22+
'o3' => 100,
23+
'so2' => 1,
24+
'pm2_5' => 1,
25+
'pm10' => 1,
26+
'nh3' => 1
27+
]
28+
]);
29+
30+
$this->assertInstanceOf(\DateTimeImmutable::class, $entity->getDateTime());
31+
$this->assertInstanceOf(AirQuality::class, $entity->getAirQuality());
32+
$this->assertSame(100.0, $entity->getCarbonMonoxide());
33+
$this->assertSame(0.0, $entity->getNitrogenMonoxide());
34+
$this->assertSame(1.0, $entity->getNitrogenDioxide());
35+
$this->assertSame(100.0, $entity->getOzone());
36+
$this->assertSame(1.0, $entity->getSulphurDioxide());
37+
$this->assertSame(1.0, $entity->getFineParticulateMatter());
38+
$this->assertSame(1.0, $entity->getCoarseParticulateMatter());
39+
$this->assertSame(1.0, $entity->getAmmonia());
40+
}
41+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Unit\AirPollution;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollution;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirQuality;
7+
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
8+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
9+
10+
class AirPollutionTest extends AbstractTest
11+
{
12+
public function testMethods()
13+
{
14+
$entity = new AirPollution([
15+
'coord' => [
16+
'lat' => 50,
17+
'lon' => 50
18+
],
19+
'list' => [
20+
[
21+
'dt' => 1715279409,
22+
'main' => [
23+
'aqi' => 1
24+
],
25+
'components' => [
26+
'co' => 100,
27+
'no' => 0,
28+
'no2' => 1,
29+
'o3' => 100,
30+
'so2' => 1,
31+
'pm2_5' => 1,
32+
'pm10' => 1,
33+
'nh3' => 1
34+
]
35+
]
36+
]
37+
]);
38+
39+
$this->assertInstanceOf(Coordinate::class, $entity->getCoordinate());
40+
$this->assertInstanceOf(\DateTimeImmutable::class, $entity->getDateTime());
41+
$this->assertInstanceOf(AirQuality::class, $entity->getAirQuality());
42+
$this->assertSame(100.0, $entity->getCarbonMonoxide());
43+
$this->assertSame(0.0, $entity->getNitrogenMonoxide());
44+
$this->assertSame(1.0, $entity->getNitrogenDioxide());
45+
$this->assertSame(100.0, $entity->getOzone());
46+
$this->assertSame(1.0, $entity->getSulphurDioxide());
47+
$this->assertSame(1.0, $entity->getFineParticulateMatter());
48+
$this->assertSame(1.0, $entity->getCoarseParticulateMatter());
49+
$this->assertSame(1.0, $entity->getAmmonia());
50+
}
51+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Unit\AirPollution;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirQuality;
6+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
7+
8+
class AirQualityTest extends AbstractTest
9+
{
10+
public function testMethods()
11+
{
12+
$entity = new AirQuality([
13+
'aqi' => 1
14+
]);
15+
16+
$this->assertSame(1, $entity->getIndex());
17+
$this->assertSame('Good', $entity->getQualitativeName());
18+
}
19+
}

0 commit comments

Comments
 (0)