Skip to content

Commit ccd0a73

Browse files
committed
chore: added tests to assert that with methods exist
1 parent 71320be commit ccd0a73

File tree

4 files changed

+63
-11
lines changed

4 files changed

+63
-11
lines changed

tests/AirPollutionEndpointTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
use Nyholm\Psr7\Response;
66
use PHPUnit\Framework\Attributes\DataProviderExternal;
7+
use ProgrammatorDev\OpenWeatherMap\Endpoint\AirPollutionEndpoint;
78
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollution;
89
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionLocationList;
910
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirQuality;
1011
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionLocation;
1112
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
12-
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
1313
use ProgrammatorDev\OpenWeatherMap\Test\DataProvider\InvalidParamDataProvider;
1414

1515
class AirPollutionEndpointTest extends AbstractTest
1616
{
17+
// --- CURRENT ---
18+
1719
public function testAirPollutionGetCurrent()
1820
{
1921
$this->mockHttpClient->addResponse(
@@ -34,6 +36,8 @@ public function testAirPollutionGetCurrentWithInvalidCoordinate(float $latitude,
3436
$this->givenApi()->getAirPollution()->getCurrent($latitude, $longitude);
3537
}
3638

39+
// --- FORECAST ---
40+
3741
public function testAirPollutionGetForecast()
3842
{
3943
$this->mockHttpClient->addResponse(
@@ -54,6 +58,8 @@ public function testAirPollutionGetForecastWithInvalidCoordinate(float $latitude
5458
$this->givenApi()->getAirPollution()->getForecast($latitude, $longitude);
5559
}
5660

61+
// --- HISTORY ---
62+
5763
public function testAirPollutionGetHistory()
5864
{
5965
$this->mockHttpClient->addResponse(
@@ -126,6 +132,17 @@ public function testAirPollutionGetHistoryWithInvalidDateRange(
126132
$this->givenApi()->getAirPollution()->getHistory(50, 50, $startDate, $endDate);
127133
}
128134

135+
// --- ASSERT METHODS EXIST ---
136+
137+
public function testAirPollutionMethodsExist()
138+
{
139+
$this->assertSame(false, method_exists(AirPollutionEndpoint::class, 'withUnitSystem'));
140+
$this->assertSame(false, method_exists(AirPollutionEndpoint::class, 'withLanguage'));
141+
$this->assertSame(true, method_exists(AirPollutionEndpoint::class, 'withCacheTtl'));
142+
}
143+
144+
// --- ASSERT RESPONSES ---
145+
129146
private function assertCurrentResponse(AirPollutionLocation $response): void
130147
{
131148
$this->assertInstanceOf(AirPollutionLocation::class, $response);

tests/GeocodingEndpointTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Nyholm\Psr7\Response;
66
use PHPUnit\Framework\Attributes\DataProvider;
77
use PHPUnit\Framework\Attributes\DataProviderExternal;
8+
use ProgrammatorDev\OpenWeatherMap\Endpoint\GeocodingEndpoint;
89
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
910
use ProgrammatorDev\OpenWeatherMap\Entity\Geocoding\ZipCodeLocation;
1011
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
@@ -13,6 +14,7 @@
1314

1415
class GeocodingEndpointTest extends AbstractTest
1516
{
17+
// --- BY LOCATION NAME ---
1618
public function testGeocodingGetByLocationName()
1719
{
1820
$this->mockHttpClient->addResponse(
@@ -32,6 +34,8 @@ public function testGeocodingGetByLocationNameWithBlankValue()
3234
$this->givenApi()->getGeocoding()->getByLocationName('');
3335
}
3436

37+
// --- BY ZIP CODE ---
38+
3539
public function testGeocodingGetByZipCode()
3640
{
3741
$this->mockHttpClient->addResponse(
@@ -68,6 +72,8 @@ public static function provideGeocodingGetByZipCodeWithInvalidValueData(): \Gene
6872
yield 'invalid country code' => ['1000-100', 'invalid'];
6973
}
7074

75+
// --- BY COORDINATE ---
76+
7177
public function testGeocodingGetByCoordinate()
7278
{
7379
$this->mockHttpClient->addResponse(
@@ -102,6 +108,17 @@ public function testGeocodingGetByCoordinateWithInvalidNumResults(
102108
$this->givenApi()->getGeocoding()->getByCoordinate(50, 50, $numResults);
103109
}
104110

111+
// --- ASSERT METHODS EXIST ---
112+
113+
public function testGeocodingMethodsExist()
114+
{
115+
$this->assertSame(false, method_exists(GeocodingEndpoint::class, 'withUnitSystem'));
116+
$this->assertSame(false, method_exists(GeocodingEndpoint::class, 'withLanguage'));
117+
$this->assertSame(true, method_exists(GeocodingEndpoint::class, 'withCacheTtl'));
118+
}
119+
120+
// --- ASSERT RESPONSES ---
121+
105122
/**
106123
* @param Location[] $response
107124
*/

tests/OneCallEndpointTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Nyholm\Psr7\Response;
66
use PHPUnit\Framework\Attributes\DataProviderExternal;
7+
use ProgrammatorDev\OpenWeatherMap\Endpoint\OneCallEndpoint;
78
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
89
use ProgrammatorDev\OpenWeatherMap\Entity\Icon;
910
use ProgrammatorDev\OpenWeatherMap\Entity\MoonPhase;
@@ -21,6 +22,8 @@
2122

2223
class OneCallEndpointTest extends AbstractTest
2324
{
25+
// --- WEATHER ---
26+
2427
public function testOneCallGetWeather()
2528
{
2629
$this->mockHttpClient->addResponse(
@@ -41,6 +44,8 @@ public function testOneCallGetWeatherWithInvalidCoordinate(float $latitude, floa
4144
$this->givenApi()->getOneCall()->getWeather($latitude, $longitude);
4245
}
4346

47+
// --- HISTORY MOMENT ---
48+
4449
public function testOneCallGetHistoryMoment()
4550
{
4651
$this->mockHttpClient->addResponse(
@@ -76,6 +81,8 @@ public function testOneCallGetHistoryMomentWithInvalidPastDate(\DateTimeImmutabl
7681
$this->givenApi()->getOneCall()->getHistoryMoment(50, 50, $date);
7782
}
7883

84+
// --- HISTORY AGGREGATE ---
85+
7986
public function testOneCallGetHistoryAggregate()
8087
{
8188
$this->mockHttpClient->addResponse(
@@ -111,14 +118,17 @@ public function testOneCallGetHistoryAggregateWithInvalidPastDate(\DateTimeImmut
111118
$this->givenApi()->getOneCall()->getHistoryAggregate(50, 50, $date);
112119
}
113120

114-
public function testOneCallMethodsWithExist()
115-
{
116-
$weatherEndpoint = $this->givenApi()->getWeather();
121+
// --- ASSERT METHODS EXIST ---
117122

118-
$this->assertSame(true, method_exists($weatherEndpoint, 'withLanguage'));
119-
$this->assertSame(true, method_exists($weatherEndpoint, 'withUnitSystem'));
123+
public function testOneCallMethodsExist()
124+
{
125+
$this->assertSame(true, method_exists(OneCallEndpoint::class, 'withUnitSystem'));
126+
$this->assertSame(true, method_exists(OneCallEndpoint::class, 'withLanguage'));
127+
$this->assertSame(true, method_exists(OneCallEndpoint::class, 'withCacheTtl'));
120128
}
121129

130+
// --- ASSERT RESPONSES ---
131+
122132
private function assertWeatherResponse(OneCall $response): void
123133
{
124134
$this->assertInstanceOf(OneCall::class, $response);

tests/WeatherEndpointTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Nyholm\Psr7\Response;
66
use PHPUnit\Framework\Attributes\DataProviderExternal;
7+
use ProgrammatorDev\OpenWeatherMap\Endpoint\WeatherEndpoint;
78
use ProgrammatorDev\OpenWeatherMap\Entity\AtmosphericPressure;
89
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
910
use ProgrammatorDev\OpenWeatherMap\Entity\Icon;
@@ -20,6 +21,8 @@
2021

2122
class WeatherEndpointTest extends AbstractTest
2223
{
24+
// --- CURRENT ---
25+
2326
public function testWeatherGetCurrent()
2427
{
2528
$this->mockHttpClient->addResponse(
@@ -40,6 +43,8 @@ public function testWeatherGetCurrentWithInvalidCoordinate(float $latitude, floa
4043
$this->givenApi()->getWeather()->getCurrent($latitude, $longitude);
4144
}
4245

46+
// --- FORECAST ---
47+
4348
public function testWeatherGetForecast()
4449
{
4550
$this->mockHttpClient->addResponse(
@@ -67,14 +72,17 @@ public function testWeatherGetForecastWithInvalidNumResults(int $numResults, str
6772
$this->givenApi()->getWeather()->getForecast(50, 50, $numResults);
6873
}
6974

70-
public function testWeatherMethodsWithExist()
71-
{
72-
$weatherEndpoint = $this->givenApi()->getWeather();
75+
// --- ASSERT METHODS EXIST ---
7376

74-
$this->assertSame(true, method_exists($weatherEndpoint, 'withLanguage'));
75-
$this->assertSame(true, method_exists($weatherEndpoint, 'withUnitSystem'));
77+
public function testWeatherMethodsExist()
78+
{
79+
$this->assertSame(true, method_exists(WeatherEndpoint::class, 'withUnitSystem'));
80+
$this->assertSame(true, method_exists(WeatherEndpoint::class, 'withLanguage'));
81+
$this->assertSame(true, method_exists(WeatherEndpoint::class, 'withCacheTtl'));
7682
}
7783

84+
// --- ASSERT RESPONSES ---
85+
7886
private function assertCurrentResponse(WeatherLocation $response): void
7987
{
8088
$this->assertInstanceOf(WeatherLocation::class, $response);

0 commit comments

Comments
 (0)