4
4
5
5
use Nyholm \Psr7 \Response ;
6
6
use PHPUnit \Framework \Attributes \DataProviderExternal ;
7
+ use ProgrammatorDev \OpenWeatherMap \Endpoint \AirPollutionEndpoint ;
7
8
use ProgrammatorDev \OpenWeatherMap \Entity \AirPollution \AirPollution ;
8
9
use ProgrammatorDev \OpenWeatherMap \Entity \AirPollution \AirPollutionLocationList ;
9
10
use ProgrammatorDev \OpenWeatherMap \Entity \AirPollution \AirQuality ;
10
11
use ProgrammatorDev \OpenWeatherMap \Entity \AirPollution \AirPollutionLocation ;
11
12
use ProgrammatorDev \OpenWeatherMap \Entity \Coordinate ;
12
- use ProgrammatorDev \OpenWeatherMap \Entity \Location ;
13
13
use ProgrammatorDev \OpenWeatherMap \Test \DataProvider \InvalidParamDataProvider ;
14
14
15
15
class AirPollutionEndpointTest extends AbstractTest
16
16
{
17
+ // --- CURRENT ---
18
+
17
19
public function testAirPollutionGetCurrent ()
18
20
{
19
21
$ this ->mockHttpClient ->addResponse (
@@ -23,17 +25,19 @@ public function testAirPollutionGetCurrent()
23
25
)
24
26
);
25
27
26
- $ response = $ this ->getApi ()->getAirPollution ()->getCurrent (38.7077507 , - 9.1365919 );
28
+ $ response = $ this ->givenApi ()->getAirPollution ()->getCurrent (50 , 50 );
27
29
$ this ->assertCurrentResponse ($ response );
28
30
}
29
31
30
32
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidCoordinateData ' )]
31
33
public function testAirPollutionGetCurrentWithInvalidCoordinate (float $ latitude , float $ longitude , string $ expectedException )
32
34
{
33
35
$ this ->expectException ($ expectedException );
34
- $ this ->getApi ()->getAirPollution ()->getCurrent ($ latitude , $ longitude );
36
+ $ this ->givenApi ()->getAirPollution ()->getCurrent ($ latitude , $ longitude );
35
37
}
36
38
39
+ // --- FORECAST ---
40
+
37
41
public function testAirPollutionGetForecast ()
38
42
{
39
43
$ this ->mockHttpClient ->addResponse (
@@ -43,17 +47,19 @@ public function testAirPollutionGetForecast()
43
47
)
44
48
);
45
49
46
- $ response = $ this ->getApi ()->getAirPollution ()->getForecast (38.7077507 , - 9.1365919 );
50
+ $ response = $ this ->givenApi ()->getAirPollution ()->getForecast (50 , 50 );
47
51
$ this ->assertForecastResponse ($ response );
48
52
}
49
53
50
54
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidCoordinateData ' )]
51
55
public function testAirPollutionGetForecastWithInvalidCoordinate (float $ latitude , float $ longitude , string $ expectedException )
52
56
{
53
57
$ this ->expectException ($ expectedException );
54
- $ this ->getApi ()->getAirPollution ()->getForecast ($ latitude , $ longitude );
58
+ $ this ->givenApi ()->getAirPollution ()->getForecast ($ latitude , $ longitude );
55
59
}
56
60
61
+ // --- HISTORY ---
62
+
57
63
public function testAirPollutionGetHistory ()
58
64
{
59
65
$ this ->mockHttpClient ->addResponse (
@@ -65,9 +71,9 @@ public function testAirPollutionGetHistory()
65
71
66
72
$ utcTimezone = new \DateTimeZone ('UTC ' );
67
73
68
- $ response = $ this ->getApi ()->getAirPollution ()->getHistory (
69
- 38.7077507 ,
70
- - 9.1365919 ,
74
+ $ response = $ this ->givenApi ()->getAirPollution ()->getHistory (
75
+ 50 ,
76
+ 50 ,
71
77
new \DateTimeImmutable ('-5 days ' , $ utcTimezone ),
72
78
new \DateTimeImmutable ('-4 days ' , $ utcTimezone )
73
79
);
@@ -82,7 +88,7 @@ public function testAirPollutionGetHistoryWithInvalidCoordinate(float $latitude,
82
88
$ startDate = new \DateTimeImmutable ('-5 days ' );
83
89
$ endDate = new \DateTimeImmutable ('-4 days ' );
84
90
85
- $ this ->getApi ()->getAirPollution ()->getHistory ($ latitude , $ longitude , $ startDate , $ endDate );
91
+ $ this ->givenApi ()->getAirPollution ()->getHistory ($ latitude , $ longitude , $ startDate , $ endDate );
86
92
}
87
93
88
94
#[DataProviderExternal(InvalidParamDataProvider::class, 'provideInvalidPastDateData ' )]
@@ -92,9 +98,9 @@ public function testAirPollutionGetHistoryWithInvalidPastStartDate(
92
98
)
93
99
{
94
100
$ this ->expectException ($ expectedException );
95
- $ this ->getApi ()->getAirPollution ()->getHistory (
96
- 38.7077507 ,
97
- - 9.1365919 ,
101
+ $ this ->givenApi ()->getAirPollution ()->getHistory (
102
+ 50 ,
103
+ 50 ,
98
104
$ startDate ,
99
105
new \DateTimeImmutable ('-5 days ' , new \DateTimeZone ('UTC ' ))
100
106
);
@@ -107,9 +113,9 @@ public function testAirPollutionGetHistoryWithInvalidPastEndDate(
107
113
)
108
114
{
109
115
$ this ->expectException ($ expectedException );
110
- $ this ->getApi ()->getAirPollution ()->getHistory (
111
- 38.7077507 ,
112
- - 9.1365919 ,
116
+ $ this ->givenApi ()->getAirPollution ()->getHistory (
117
+ 50 ,
118
+ 50 ,
113
119
new \DateTimeImmutable ('-5 days ' , new \DateTimeZone ('UTC ' )),
114
120
$ endDate
115
121
);
@@ -123,9 +129,20 @@ public function testAirPollutionGetHistoryWithInvalidDateRange(
123
129
)
124
130
{
125
131
$ this ->expectException ($ expectedException );
126
- $ this ->getApi ()->getAirPollution ()->getHistory (38.7077507 , -9.1365919 , $ startDate , $ endDate );
132
+ $ this ->givenApi ()->getAirPollution ()->getHistory (50 , 50 , $ startDate , $ endDate );
133
+ }
134
+
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 ' ));
127
142
}
128
143
144
+ // --- ASSERT RESPONSES ---
145
+
129
146
private function assertCurrentResponse (AirPollutionLocation $ response ): void
130
147
{
131
148
$ this ->assertInstanceOf (AirPollutionLocation::class, $ response );
0 commit comments