Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"php-http/discovery": "^1.14",
"symfony/console": "^5.4 || ^6.4 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
"symfony/options-resolver": "^5.4 || ^6.4 || ^7.0",
"willdurand/geocoder": "^4.6|^5.0"
},
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ parameters:
count: 1
path: src/DependencyInjection/BazingaGeocoderExtension.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:end\\(\\)\\.$#"
count: 2
path: src/DependencyInjection/Configuration.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:variableNode\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php

-
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Event\\\\OnFlushEventArgs\\:\\:getEntityManager\\(\\)\\.$#"
count: 1
Expand Down
53 changes: 4 additions & 49 deletions tests/Functional/CustomTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Bazinga\GeocoderBundle\Tests\Functional;

use Nyholm\BundleTest\TestKernel;
use Nyholm\NSA;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\DependencyInjection\Dumper\Preloader;
use Symfony\Component\ErrorHandler\DebugClassLoader;
Expand All @@ -28,15 +29,6 @@
*/
class CustomTestKernel extends TestKernel
{
private $warmupDir;

public function reboot(?string $warmupDir)
{
$this->shutdown();
$this->warmupDir = $warmupDir;
$this->boot();
}

/*
* Needed, otherwise the used cache is different on each kernel boot, which is a big issue in PluginInteractionTest
*/
Expand All @@ -45,45 +37,6 @@ public function getCacheDir(): string
return realpath(sys_get_temp_dir()).'/NyholmBundleTest/cachePluginInteractionTest';
}

/**
* Returns the kernel parameters.
*/
protected function getKernelParameters(): array
{
$bundles = [];
$bundlesMetadata = [];

foreach ($this->bundles as $name => $bundle) {
$bundles[$name] = \get_class($bundle);
$bundlesMetadata[$name] = [
'path' => $bundle->getPath(),
'namespace' => $bundle->getNamespace(),
];
}

return [
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
'kernel.environment' => $this->environment,
'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%',
'kernel.debug' => $this->debug,
'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir,
'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir,
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
'kernel.bundles' => $bundles,
'kernel.bundles_metadata' => $bundlesMetadata,
'kernel.charset' => $this->getCharset(),
'kernel.container_class' => $this->getContainerClass(),
];
}

/**
* @internal
*/
public function setAnnotatedClassCache(array $annotatedClasses): void
{
file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map', sprintf('<?php return %s;', var_export($annotatedClasses, true)));
}

/**
* Initializes the service container.
*
Expand All @@ -92,8 +45,10 @@ public function setAnnotatedClassCache(array $annotatedClasses): void
*/
protected function initializeContainer(): void
{
$warmupDir = NSA::getProperty($this, 'warmupDir');

$class = $this->getContainerClass();
$buildDir = $this->warmupDir ?: $this->getBuildDir();
$buildDir = $warmupDir ?: $this->getBuildDir();
$cache = new ConfigCache($buildDir.'/'.$class.'.php', $this->debug);
$cachePath = $cache->getPath();

Expand Down
53 changes: 51 additions & 2 deletions tests/Functional/PluginInteractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

use Bazinga\GeocoderBundle\BazingaGeocoderBundle;
use Geocoder\Query\GeocodeQuery;
use Http\Message\RequestMatcher\RequestMatcher;
use Http\Mock\Client;
use Nyholm\BundleTest\TestKernel;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpKernel\KernelInterface;
Expand Down Expand Up @@ -51,11 +56,33 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
}

$kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml');
$kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_cn.yml');
$kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_cn.yml');
}]);
$kernel->setClearCacheAfterShutdown(false);
$container = self::getContainer();

$httpClient = $container->get(Client::class);
$httpClient->on(new RequestMatcher(), function (RequestInterface $request) {
if ('https://freegeoip.app/json/123.123.123.128' === (string) $request->getUri()) {
$stream = $this->createMock(StreamInterface::class);
$stream->expects(self::once())
->method('__toString')
->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}');

$response = $this->createMock(ResponseInterface::class);
$response->expects(self::once())
->method('getStatusCode')
->willReturn(200);
$response->expects(self::once())
->method('getBody')
->willReturn($stream);

return $response;
}

self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri()));
});

$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));
$country = $result->first()->getCountry()->getCode();
Expand All @@ -70,11 +97,33 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
}

$kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml');
$kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_fr.yml');
$kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_fr.yml');
}]);
$kernel->setClearCacheAfterShutdown(false);
$container = self::getContainer();

$httpClient = $container->get(Client::class);
$httpClient->on(new RequestMatcher(), function (RequestInterface $request) {
if ('https://freegeoip.app/json/87.98.128.10' === (string) $request->getUri()) {
$stream = $this->createMock(StreamInterface::class);
$stream->expects(self::once())
->method('__toString')
->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}');

$response = $this->createMock(ResponseInterface::class);
$response->expects(self::once())
->method('getStatusCode')
->willReturn(200);
$response->expects(self::once())
->method('getBody')
->willReturn($stream);

return $response;
}

self::fail(sprintf('Unexpected http call "%s %s".', $request->getMethod(), (string) $request->getUri()));
});

$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));
$country = $result->first()->getCountry()->getCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
bazinga_geocoder:
# The local IP (127.0.0.1) will be replaced by the fake_ip
# see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip
fake_ip:
fake_ip:
local_ip: ::1
ip: 123.123.123.128
# this ip is in china
providers:
geoPlugin:
factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory
factory: Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory
cache: 'app.simple_cache'
cache_lifetime: 42
cache_precision: ~
cache_precision: ~
options:
http_client: '@Http\Mock\Client'

services:
Http\Mock\Client: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
bazinga_geocoder:
# The local IP (127.0.0.1) will be replaced by the fake_ip
# see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip
fake_ip:
fake_ip:
local_ip: ::1
ip: 87.98.128.10
# this ip is in france
providers:
geoPlugin:
factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory
factory: Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory
cache: 'app.simple_cache'
cache_lifetime: 42
cache_precision: ~
cache_precision: ~
options:
http_client: '@Http\Mock\Client'

services:
Http\Mock\Client: ~
7 changes: 7 additions & 0 deletions tests/baseline-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@
%Geocoder\\ProviderAggregator::__construct\(\): Implicitly marking parameter \$decider as nullable is deprecated, the explicit nullable type must be used instead%
%Since symfony/var-exporter 7.3: The "Symfony\\Component\\VarExporter\\LazyGhostTrait" trait is deprecated, use native lazy objects instead.%
%Method "Http\\Promise\\Promise::wait\(\)" might add " Resolved value, null if \$unwrap is set to false" as a native return type declaration in the future. Do the same in implementation "Geocoder\\Plugin\\Promise\\GeocoderFulfilledPromise" now to avoid errors or add an explicit @return annotation to suppress this message.%
%The "report_fields_where_declared" configuration option is deprecated and will be removed in DoctrineBundle 3.0. When using ORM 3, report_fields_where_declared will always be true%
%Class "Doctrine\\ORM\\Proxy\\DefaultProxyClassNameResolver" is deprecated. Use native lazy objects instead%
%Calling Doctrine\\ORM\\Configuration::(getProxyDir|setProxyDir|getAutoGenerateProxyClasses|setAutoGenerateProxyClasses|setProxyNamespace|getProxyNamespace) is deprecated and will not be possible in Doctrine ORM 4.0%
%Class "Doctrine\\ORM\\Proxy\\Autoloader" is deprecated. Use native lazy objects instead%
%Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0%
%Not setting "doctrine.orm.enable_native_lazy_objects" to true is deprecated%
%Disabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0%