Skip to content

Commit 5bb8341

Browse files
authored
Merge pull request #374 from norkunas/drop-dep
Drop `php-http/curl-client` dependency
2 parents 5852b70 + cf587a3 commit 5bb8341

File tree

12 files changed

+117
-225
lines changed

12 files changed

+117
-225
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"require": {
1717
"php": "^7.4 || ^8.0",
1818
"geocoder-php/plugin": "^1.5",
19-
"php-http/curl-client": "^2.3",
2019
"php-http/discovery": "^1.14",
2120
"symfony/console": "^5.4 || ^6.4 || ^7.0",
2221
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0",
@@ -62,13 +61,12 @@
6261
"nyholm/nsa": "^1.3",
6362
"nyholm/psr7": "^1.5",
6463
"nyholm/symfony-bundle-test": "^2.0 || ^3.0",
65-
"php-http/message": "^1.13",
66-
"php-http/mock-client": "^1.6",
6764
"phpstan/phpstan": "^1.9.2",
6865
"psr/http-client": "^1.0",
6966
"psr/simple-cache": "^1.0 || ^2.0",
7067
"symfony/cache": "^5.4 || ^6.4 || ^7.0",
7168
"symfony/config": "^5.4 || ^6.4 || ^7.0",
69+
"symfony/http-client": "^5.4 || ^6.4 || ^7.0",
7270
"symfony/phpunit-bridge": "^5.4 || ^6.4 || ^7.0",
7371
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
7472
"symfony/var-exporter": "^5.4 || ^6.4 || ^7.0",

tests/DependencyInjection/Compiler/AddProvidersPassTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
use Bazinga\GeocoderBundle\DependencyInjection\Compiler\AddProvidersPass;
1616
use Geocoder\Provider\BingMaps\BingMaps;
1717
use Geocoder\ProviderAggregator;
18-
use Http\Mock\Client;
1918
use PHPUnit\Framework\TestCase;
2019
use Symfony\Component\DependencyInjection\ContainerBuilder;
2120
use Symfony\Component\DependencyInjection\Definition;
21+
use Symfony\Component\HttpClient\MockHttpClient;
22+
use Symfony\Component\HttpClient\Psr18Client;
2223

2324
final class AddProvidersPassTest extends TestCase
2425
{
@@ -34,7 +35,7 @@ public function testRegistersProviders(): void
3435
$containerBuilder = new ContainerBuilder();
3536
$containerBuilder->setDefinition(ProviderAggregator::class, new Definition(ProviderAggregator::class));
3637

37-
$bing = $containerBuilder->setDefinition('bing_maps', new Definition(BingMaps::class, [new Client(), 'apikey']));
38+
$bing = $containerBuilder->setDefinition('bing_maps', new Definition(BingMaps::class, [new Psr18Client(new MockHttpClient()), 'apikey']));
3839
$bing->addTag('bazinga_geocoder.provider');
3940

4041
$this->compilerPass->process($containerBuilder);

tests/Functional/CustomTestKernel.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
use Nyholm\BundleTest\TestKernel;
1616
use Symfony\Component\Config\ConfigCache;
17+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1719
use Symfony\Component\DependencyInjection\Dumper\Preloader;
1820
use Symfony\Component\ErrorHandler\DebugClassLoader;
1921
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
@@ -26,7 +28,7 @@
2628
* the methods using it (reboot() and getKernelParameters() and setAnnotatedClassCache() ) therefore needed to be redeclared, in order
2729
* for them to have a correct value in it.
2830
*/
29-
class CustomTestKernel extends TestKernel
31+
class CustomTestKernel extends TestKernel implements CompilerPassInterface
3032
{
3133
private $warmupDir;
3234

@@ -93,6 +95,21 @@ public function setAnnotatedClassCache(array $annotatedClasses): void
9395
file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map', sprintf('<?php return %s;', var_export($annotatedClasses, true)));
9496
}
9597

98+
// Can be removed after dropping Symfony 5.4
99+
public function process(ContainerBuilder $container): void
100+
{
101+
$container
102+
->getDefinition('http_client')
103+
->setPublic(true);
104+
}
105+
106+
protected function build(ContainerBuilder $container): void
107+
{
108+
parent::build($container);
109+
110+
$container->addCompilerPass($this);
111+
}
112+
96113
/**
97114
* Initializes the service container.
98115
*

tests/Functional/GeocoderListenerTest.php

Lines changed: 55 additions & 115 deletions
Large diffs are not rendered by default.

tests/Functional/PluginInteractionTest.php

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

1515
use Bazinga\GeocoderBundle\BazingaGeocoderBundle;
1616
use Geocoder\Query\GeocodeQuery;
17-
use Http\Message\RequestMatcher\RequestMatcher;
18-
use Http\Mock\Client;
1917
use Nyholm\BundleTest\TestKernel;
20-
use Psr\Http\Message\RequestInterface;
21-
use Psr\Http\Message\ResponseInterface;
22-
use Psr\Http\Message\StreamInterface;
2318
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2419
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
20+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
21+
use Symfony\Component\DependencyInjection\ContainerBuilder;
22+
use Symfony\Component\HttpClient\MockHttpClient;
23+
use Symfony\Component\HttpClient\Response\MockResponse;
2524
use Symfony\Component\HttpKernel\KernelInterface;
2625

2726
final class PluginInteractionTest extends KernelTestCase
@@ -40,6 +39,14 @@ protected static function createKernel(array $options = []): KernelInterface
4039
*/
4140
$kernel = parent::createKernel($options);
4241
$kernel->addTestBundle(BazingaGeocoderBundle::class);
42+
$kernel->addTestCompilerPass(new class implements CompilerPassInterface {
43+
public function process(ContainerBuilder $container): void
44+
{
45+
$container
46+
->getDefinition('http_client')
47+
->setPublic(true);
48+
}
49+
});
4350
$kernel->handleOptions($options);
4451

4552
return $kernel;
@@ -61,27 +68,12 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
6168
$kernel->setClearCacheAfterShutdown(false);
6269
$container = self::getContainer();
6370

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-
}
71+
$container->set('http_client', new MockHttpClient(static function (string $method, string $url): MockResponse {
72+
self::assertSame('GET', $method);
73+
self::assertSame('https://freegeoip.app/json/123.123.123.128', $url);
8274

83-
self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri()));
84-
});
75+
return new MockResponse('{"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}', ['response_headers' => ['content-type' => 'application-json']]);
76+
}));
8577

8678
$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
8779
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));
@@ -102,27 +94,12 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
10294
$kernel->setClearCacheAfterShutdown(false);
10395
$container = self::getContainer();
10496

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-
}
97+
$container->set('http_client', new MockHttpClient(static function (string $method, string $url): MockResponse {
98+
self::assertSame('GET', $method);
99+
self::assertSame('https://freegeoip.app/json/87.98.128.10', $url);
123100

124-
self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri()));
125-
});
101+
return new MockResponse('{"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}', ['response_headers' => ['content-type' => 'application-json']]);
102+
}));
126103

127104
$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
128105
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));

tests/Functional/config/fakeip_with_cache_cn.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ 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: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ 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/framework.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ framework:
88
storage_factory_id: session.storage.factory.native
99
router:
1010
utf8: true
11+
http_client:
12+
enabled: true

tests/Functional/config/listener.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,3 @@ bazinga_geocoder:
1818
providers:
1919
acme:
2020
factory: Bazinga\GeocoderBundle\ProviderFactory\NominatimFactory
21-
options:
22-
http_client: '@Http\Mock\Client'
23-
24-
services:
25-
Http\Mock\Client: ~

tests/Functional/config/listener_php7.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ bazinga_geocoder:
1515
acme:
1616
factory: Bazinga\GeocoderBundle\ProviderFactory\NominatimFactory
1717
options:
18-
http_client: '@Http\Mock\Client'
1918
root_url: 'https://nominatim.openstreetmap.org'
2019
user_agent: 'geocoder-php test_suite'
2120

0 commit comments

Comments
 (0)