Skip to content

Commit e90299a

Browse files
committed
Fix test
1 parent fe24ecb commit e90299a

File tree

7 files changed

+79
-67
lines changed

7 files changed

+79
-67
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"php-http/discovery": "^1.14",
2121
"symfony/console": "^5.4 || ^6.4 || ^7.0",
2222
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0",
23+
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
2324
"symfony/options-resolver": "^5.4 || ^6.4 || ^7.0",
2425
"willdurand/geocoder": "^4.6|^5.0"
2526
},

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,6 @@ parameters:
115115
count: 1
116116
path: src/DependencyInjection/BazingaGeocoderExtension.php
117117

118-
-
119-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:end\\(\\)\\.$#"
120-
count: 2
121-
path: src/DependencyInjection/Configuration.php
122-
123-
-
124-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:variableNode\\(\\)\\.$#"
125-
count: 1
126-
path: src/DependencyInjection/Configuration.php
127-
128118
-
129119
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Event\\\\OnFlushEventArgs\\:\\:getEntityManager\\(\\)\\.$#"
130120
count: 1

tests/Functional/CustomTestKernel.php

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Bazinga\GeocoderBundle\Tests\Functional;
1414

1515
use Nyholm\BundleTest\TestKernel;
16+
use Nyholm\NSA;
1617
use Symfony\Component\Config\ConfigCache;
1718
use Symfony\Component\DependencyInjection\Dumper\Preloader;
1819
use Symfony\Component\ErrorHandler\DebugClassLoader;
@@ -28,15 +29,6 @@
2829
*/
2930
class CustomTestKernel extends TestKernel
3031
{
31-
private $warmupDir;
32-
33-
public function reboot(?string $warmupDir)
34-
{
35-
$this->shutdown();
36-
$this->warmupDir = $warmupDir;
37-
$this->boot();
38-
}
39-
4032
/*
4133
* Needed, otherwise the used cache is different on each kernel boot, which is a big issue in PluginInteractionTest
4234
*/
@@ -45,45 +37,6 @@ public function getCacheDir(): string
4537
return realpath(sys_get_temp_dir()).'/NyholmBundleTest/cachePluginInteractionTest';
4638
}
4739

48-
/**
49-
* Returns the kernel parameters.
50-
*/
51-
protected function getKernelParameters(): array
52-
{
53-
$bundles = [];
54-
$bundlesMetadata = [];
55-
56-
foreach ($this->bundles as $name => $bundle) {
57-
$bundles[$name] = \get_class($bundle);
58-
$bundlesMetadata[$name] = [
59-
'path' => $bundle->getPath(),
60-
'namespace' => $bundle->getNamespace(),
61-
];
62-
}
63-
64-
return [
65-
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
66-
'kernel.environment' => $this->environment,
67-
'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%',
68-
'kernel.debug' => $this->debug,
69-
'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir,
70-
'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir,
71-
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
72-
'kernel.bundles' => $bundles,
73-
'kernel.bundles_metadata' => $bundlesMetadata,
74-
'kernel.charset' => $this->getCharset(),
75-
'kernel.container_class' => $this->getContainerClass(),
76-
];
77-
}
78-
79-
/**
80-
* @internal
81-
*/
82-
public function setAnnotatedClassCache(array $annotatedClasses): void
83-
{
84-
file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map', sprintf('<?php return %s;', var_export($annotatedClasses, true)));
85-
}
86-
8740
/**
8841
* Initializes the service container.
8942
*
@@ -92,8 +45,10 @@ public function setAnnotatedClassCache(array $annotatedClasses): void
9245
*/
9346
protected function initializeContainer(): void
9447
{
48+
$warmupDir = NSA::getProperty($this, 'warmupDir');
49+
9550
$class = $this->getContainerClass();
96-
$buildDir = $this->warmupDir ?: $this->getBuildDir();
51+
$buildDir = $warmupDir ?: $this->getBuildDir();
9752
$cache = new ConfigCache($buildDir.'/'.$class.'.php', $this->debug);
9853
$cachePath = $cache->getPath();
9954

tests/Functional/PluginInteractionTest.php

Lines changed: 51 additions & 2 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;
@@ -51,11 +56,33 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
5156
}
5257

5358
$kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml');
54-
$kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_cn.yml');
59+
$kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_cn.yml');
5560
}]);
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();
@@ -70,11 +97,33 @@ public function testCachePluginUsesIpFromFakeIpPlugin(): void
7097
}
7198

7299
$kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml');
73-
$kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_fr.yml');
100+
$kernel->addTestConfig(__DIR__.'/config/fakeip_with_cache_fr.yml');
74101
}]);
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/geo_plugin_fakeip_with_cache_cn.yml renamed to tests/Functional/config/fakeip_with_cache_cn.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
bazinga_geocoder:
33
# The local IP (127.0.0.1) will be replaced by the fake_ip
44
# see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip
5-
fake_ip:
5+
fake_ip:
66
local_ip: ::1
77
ip: 123.123.123.128
88
# this ip is in china
99
providers:
1010
geoPlugin:
11-
factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory
11+
factory: Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory
1212
cache: 'app.simple_cache'
1313
cache_lifetime: 42
14-
cache_precision: ~
14+
cache_precision: ~
15+
options:
16+
http_client: '@Http\Mock\Client'
17+
18+
services:
19+
Http\Mock\Client: ~

tests/Functional/config/geo_plugin_fakeip_with_cache_fr.yml renamed to tests/Functional/config/fakeip_with_cache_fr.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
bazinga_geocoder:
33
# The local IP (127.0.0.1) will be replaced by the fake_ip
44
# see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip
5-
fake_ip:
5+
fake_ip:
66
local_ip: ::1
77
ip: 87.98.128.10
88
# this ip is in france
99
providers:
1010
geoPlugin:
11-
factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory
11+
factory: Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory
1212
cache: 'app.simple_cache'
1313
cache_lifetime: 42
14-
cache_precision: ~
14+
cache_precision: ~
15+
options:
16+
http_client: '@Http\Mock\Client'
17+
18+
services:
19+
Http\Mock\Client: ~

tests/baseline-ignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@
8383
%Geocoder\\ProviderAggregator::__construct\(\): Implicitly marking parameter \$decider as nullable is deprecated, the explicit nullable type must be used instead%
8484
%Since symfony/var-exporter 7.3: The "Symfony\\Component\\VarExporter\\LazyGhostTrait" trait is deprecated, use native lazy objects instead.%
8585
%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.%
86+
%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%
87+
%Class "Doctrine\\ORM\\Proxy\\DefaultProxyClassNameResolver" is deprecated. Use native lazy objects instead%
88+
%Calling Doctrine\\ORM\\Configuration::(getProxyDir|setProxyDir|getAutoGenerateProxyClasses|setAutoGenerateProxyClasses|setProxyNamespace|getProxyNamespace) is deprecated and will not be possible in Doctrine ORM 4.0%
89+
%Class "Doctrine\\ORM\\Proxy\\Autoloader" is deprecated. Use native lazy objects instead%
90+
%Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0%
91+
%Not setting "doctrine.orm.enable_native_lazy_objects" to true is deprecated%
92+
%Disabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0%

0 commit comments

Comments
 (0)