Skip to content

Commit 1fa783e

Browse files
committed
Remove deprecated provider factories
1 parent f92ad63 commit 1fa783e

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

tests/Functional/PluginInteractionTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
use Bazinga\GeocoderBundle\BazingaGeocoderBundle;
1616
use Geocoder\Query\GeocodeQuery;
17+
use Http\Message\RequestMatcher\RequestMatcher;
18+
use Http\Mock\Client;
1719
use Nyholm\BundleTest\TestKernel;
20+
use Psr\Http\Message\RequestInterface;
21+
use Psr\Http\Message\ResponseInterface;
22+
use Psr\Http\Message\StreamInterface;
1823
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1924
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2025
use Symfony\Component\HttpKernel\KernelInterface;
@@ -56,6 +61,28 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
5661
$kernel->setClearCacheAfterShutdown(false);
5762
$container = self::getContainer();
5863

64+
$httpClient = $container->get(Client::class);
65+
$httpClient->on(new RequestMatcher(), function (RequestInterface $request) {
66+
if ('https://freegeoip.app/json/123.123.123.128' === (string) $request->getUri()) {
67+
$stream = $this->createMock(StreamInterface::class);
68+
$stream->expects(self::once())
69+
->method('__toString')
70+
->willReturn('{"ip":"123.123.123.128","country_code":"CN","country_name":"China","region_code":"CN-BJ","region_name":"Beijing","city":"Beijing","zip_code":"100006","time_zone":"Asia\/Shanghai","latitude":39.907501220703125,"longitude":116.39710235595703,"metro_code":0}');
71+
72+
$response = $this->createMock(ResponseInterface::class);
73+
$response->expects(self::once())
74+
->method('getStatusCode')
75+
->willReturn(200);
76+
$response->expects(self::once())
77+
->method('getBody')
78+
->willReturn($stream);
79+
80+
return $response;
81+
}
82+
83+
self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri()));
84+
});
85+
5986
$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
6087
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));
6188
$country = $result->first()->getCountry()->getCode();
@@ -75,6 +102,28 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
75102
$kernel->setClearCacheAfterShutdown(false);
76103
$container = self::getContainer();
77104

105+
$httpClient = $container->get(Client::class);
106+
$httpClient->on(new RequestMatcher(), function (RequestInterface $request) {
107+
if ('https://freegeoip.app/json/87.98.128.10' === (string) $request->getUri()) {
108+
$stream = $this->createMock(StreamInterface::class);
109+
$stream->expects(self::once())
110+
->method('__toString')
111+
->willReturn('{"ip":"87.98.128.10","country_code":"FR","country_name":"France","region_code":null,"region_name":"Nord","city":"Roubaix","zip_code":"59100","time_zone":"Europe\/Paris","latitude":50.69371032714844,"longitude":3.174438953399658,"metro_code":0}');
112+
113+
$response = $this->createMock(ResponseInterface::class);
114+
$response->expects(self::once())
115+
->method('getStatusCode')
116+
->willReturn(200);
117+
$response->expects(self::once())
118+
->method('getBody')
119+
->willReturn($stream);
120+
121+
return $response;
122+
}
123+
124+
self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri()));
125+
});
126+
78127
$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
79128
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));
80129
$country = $result->first()->getCountry()->getCode();

tests/Functional/config/fakeip_with_cache_cn.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ bazinga_geocoder:
1212
cache: 'app.simple_cache'
1313
cache_lifetime: 42
1414
cache_precision: ~
15+
options:
16+
http_client: '@Http\Mock\Client'
17+
18+
services:
19+
Http\Mock\Client: ~

tests/Functional/config/fakeip_with_cache_fr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ bazinga_geocoder:
1212
cache: 'app.simple_cache'
1313
cache_lifetime: 42
1414
cache_precision: ~
15+
options:
16+
http_client: '@Http\Mock\Client'
17+
18+
services:
19+
Http\Mock\Client: ~

0 commit comments

Comments
 (0)