1010
1111namespace Geocoder \IntegrationTest ;
1212
13+ use Exception ;
1314use Geocoder \Collection ;
1415use Geocoder \Exception \InvalidCredentials ;
1516use Geocoder \Exception \InvalidServerResponse ;
2425use Geocoder \Query \ReverseQuery ;
2526use Http \Discovery \Psr18ClientDiscovery ;
2627use Nyholm \Psr7 \Response ;
28+ use PHPUnit \Framework \MockObject \MockObject ;
2729use PHPUnit \Framework \TestCase ;
2830use Psr \Http \Client \ClientInterface ;
2931use Psr \Http \Message \ResponseInterface ;
3436abstract class ProviderIntegrationTest extends TestCase
3537{
3638 /**
37- * @var array with functionName => reason
39+ * @var array<string,string> with functionName => reason
3840 */
39- protected $ skippedTests = [];
41+ protected array $ skippedTests = [];
4042
41- protected $ testAddress = true ;
42- protected $ testReverse = true ;
43- protected $ testIpv4 = true ;
44- protected $ testIpv6 = true ;
45- protected $ testHttpProvider = true ;
43+ protected bool $ testAddress = true ;
44+ protected bool $ testReverse = true ;
45+ protected bool $ testIpv4 = true ;
46+ protected bool $ testIpv6 = true ;
47+ protected bool $ testHttpProvider = true ;
4648
4749 /**
4850 * @return Provider that is used in the tests.
@@ -52,17 +54,17 @@ abstract protected function createProvider(ClientInterface $httpClient);
5254 /**
5355 * @return string the directory where cached responses are stored
5456 */
55- abstract protected function getCacheDir ();
57+ abstract protected function getCacheDir (): string ;
5658
5759 /**
5860 * @return string the API key or substring to be removed from cache.
5961 */
60- abstract protected function getApiKey ();
62+ abstract protected function getApiKey (): string ;
6163
6264 /**
6365 * @param ResponseInterface $response
6466 *
65- * @return \PHPUnit_Framework_MockObject_MockObject| ClientInterface
67+ * @return ClientInterface&MockObject
6668 */
6769 private function getHttpClient (ResponseInterface $ response )
6870 {
@@ -78,10 +80,8 @@ private function getHttpClient(ResponseInterface $response)
7880
7981 /**
8082 * This client will make real request if cache was not found.
81- *
82- * @return CachedResponseClient
8383 */
84- private function getCachedHttpClient ()
84+ private function getCachedHttpClient (): CachedResponseClient
8585 {
8686 try {
8787 $ client = Psr18ClientDiscovery::find ();
@@ -97,7 +97,7 @@ private function getCachedHttpClient()
9797 return new CachedResponseClient ($ client , $ this ->getCacheDir (), $ this ->getApiKey ());
9898 }
9999
100- public function testGeocodeQuery ()
100+ public function testGeocodeQuery (): void
101101 {
102102 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
103103 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
@@ -111,18 +111,20 @@ public function testGeocodeQuery()
111111 $ result = $ provider ->geocodeQuery ($ query );
112112 $ this ->assertWellFormattedResult ($ result );
113113
114- // Check Downing Street
114+ /** @var Location $location */
115115 $ location = $ result ->first ();
116- $ this ->assertEqualsWithDelta (51.5033 , $ location ->getCoordinates ()->getLatitude (), 0.1 , 'Latitude should be in London ' );
117- $ this ->assertEqualsWithDelta (-0.1276 , $ location ->getCoordinates ()->getLongitude (), 0.1 , 'Longitude should be in London ' );
116+ /** @var Coordinates|null $coordinates */
117+ $ coordinates = $ location ->getCoordinates ();
118+ $ this ->assertNotNull ($ coordinates , 'Coordinates should not be null ' );
119+ $ this ->assertEqualsWithDelta (51.5033 , $ coordinates ->getLatitude (), 0.1 , 'Latitude should be in London ' );
120+ $ this ->assertEqualsWithDelta (-0.1276 , $ coordinates ->getLongitude (), 0.1 , 'Longitude should be in London ' );
121+ $ this ->assertNotNull ($ location ->getStreetName (), 'Street name should not be null ' );
118122 $ this ->assertStringContainsString ('Downing ' , $ location ->getStreetName (), 'Street name should contain "Downing St" ' );
119-
120- if (null !== $ streetNumber = $ location ->getStreetNumber ()) {
121- $ this ->assertStringContainsString ('10 ' , $ streetNumber , 'Street number should contain "10" ' );
122- }
123+ $ this ->assertNotNull ($ location ->getStreetNumber (), 'Street number should not be null ' );
124+ $ this ->assertStringContainsString ('10 ' , (string ) $ location ->getStreetNumber (), 'Street number should contain "10" ' );
123125 }
124126
125- public function testGeocodeQueryWithNoResults ()
127+ public function testGeocodeQueryWithNoResults (): void
126128 {
127129 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
128130 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
@@ -138,7 +140,7 @@ public function testGeocodeQueryWithNoResults()
138140 $ this ->assertEquals (0 , $ result ->count ());
139141 }
140142
141- public function testReverseQuery ()
143+ public function testReverseQuery (): void
142144 {
143145 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
144146 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
@@ -154,7 +156,7 @@ public function testReverseQuery()
154156 $ this ->assertWellFormattedResult ($ result );
155157 }
156158
157- public function testReverseQueryWithNoResults ()
159+ public function testReverseQueryWithNoResults (): void
158160 {
159161 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
160162 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
@@ -170,7 +172,7 @@ public function testReverseQueryWithNoResults()
170172 $ this ->assertEquals (1 , $ result ->count ());
171173 }
172174
173- public function testGeocodeIpv4 ()
175+ public function testGeocodeIpv4 (): void
174176 {
175177 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
176178 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
@@ -185,7 +187,7 @@ public function testGeocodeIpv4()
185187 $ this ->assertWellFormattedResult ($ result );
186188 }
187189
188- public function testGeocodeIpv6 ()
190+ public function testGeocodeIpv6 (): void
189191 {
190192 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
191193 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
@@ -204,11 +206,11 @@ public function testGeocodeIpv6()
204206 * @dataProvider exceptionDataProvider
205207 *
206208 * @param GeocodeQuery|ReverseQuery $query
207- * @param string $exceptionClass
209+ * @param class- string<Exception> $exceptionClass
208210 * @param ResponseInterface|null $response
209211 * @param string $message
210212 */
211- public function testExceptions ($ query , string $ exceptionClass , ResponseInterface $ response = null , string $ message = '' )
213+ public function testExceptions ($ query , string $ exceptionClass , ResponseInterface $ response = null , string $ message = '' ): void
212214 {
213215 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
214216 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
@@ -228,7 +230,10 @@ public function testExceptions($query, string $exceptionClass, ResponseInterface
228230 }
229231 }
230232
231- public function exceptionDataProvider ()
233+ /**
234+ * @return array<array{GeocodeQuery|ReverseQuery, class-string<Exception>, Response, string}>
235+ */
236+ public function exceptionDataProvider (): array
232237 {
233238 $ testData = [];
234239
@@ -281,7 +286,7 @@ public function exceptionDataProvider()
281286 *
282287 * @param $result
283288 */
284- private function assertWellFormattedResult (Collection $ result )
289+ private function assertWellFormattedResult (Collection $ result ): void
285290 {
286291 $ this ->assertInstanceOf (
287292 Collection::class,
@@ -335,7 +340,7 @@ private function assertWellFormattedResult(Collection $result)
335340 }
336341
337342 // Check country
338- if (null !== $ country = $ location ->getCountry ()) {
343+ if (null !== ( $ country = $ location ->getCountry () )) {
339344 $ this ->assertInstanceOf (
340345 Country::class,
341346 $ country ,
@@ -345,14 +350,14 @@ private function assertWellFormattedResult(Collection $result)
345350
346351 if (null !== $ country ->getCode ()) {
347352 $ this ->assertNotEmpty (
348- $ location -> getCountry () ->getCode (),
353+ $ country ->getCode (),
349354 'The Country should not have an empty code. '
350355 );
351356 }
352357
353358 if (null !== $ country ->getName ()) {
354359 $ this ->assertNotEmpty (
355- $ location -> getCountry () ->getName (),
360+ $ country ->getName (),
356361 'The Country should not have an empty name. '
357362 );
358363 }
0 commit comments