Skip to content

Commit 8cf88d9

Browse files
committed
attempt test fix fakeip cache
1 parent 248712f commit 8cf88d9

5 files changed

+131
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"php-http/curl-client": "^2.2",
6060
"php-http/message": "^1.13",
6161
"phpstan/phpstan": "^1.9.2",
62+
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
6263
"symfony/config": "^4.4 || ^5.0 || ^6.0",
6364
"symfony/phpunit-bridge": "^5.2 || ^6.0",
6465
"symfony/validator": "^4.4 || ^5.0 || ^6.0",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the BazingaGeocoderBundle package.
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @license MIT License
11+
*/
12+
13+
namespace Bazinga\GeocoderBundle\Tests\Functional;
14+
15+
use Geocoder\Query\GeocodeQuery;
16+
use Bazinga\GeocoderBundle\BazingaGeocoderBundle;
17+
use Bazinga\GeocoderBundle\Tests\PublicServicePass;
18+
use Nyholm\BundleTest\TestKernel;
19+
use Nyholm\NSA;
20+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
21+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
22+
use Symfony\Component\HttpKernel\KernelInterface;
23+
24+
final class PluginInteractionTest extends KernelTestCase
25+
{
26+
use ExpectDeprecationTrait;
27+
28+
protected static function getKernelClass(): string
29+
{
30+
return TestKernel::class;
31+
}
32+
33+
protected static function createKernel(array $options = []): KernelInterface
34+
{
35+
/**
36+
* @var TestKernel $kernel
37+
*/
38+
$kernel = parent::createKernel($options);
39+
$kernel->addTestBundle(BazingaGeocoderBundle::class);
40+
$kernel->addTestCompilerPass(new PublicServicePass('|[Bb]azinga:*|'));
41+
$kernel->addTestCompilerPass(new PublicServicePass('|[gG]eocoder:*|'));
42+
$kernel->handleOptions($options);
43+
44+
return $kernel;
45+
}
46+
47+
public function testCachePluginUsesIpFromFakeIpPlugin(): void
48+
{
49+
$kernel = self::bootKernel(['config' => static function (TestKernel $kernel) {
50+
$kernel->addTestConfig(__DIR__.'/config/framework.yml');
51+
$kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml');
52+
$kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_cn.yml');
53+
}]);
54+
$container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer();
55+
56+
$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
57+
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));
58+
$country = $result->first()->getCountry()->getCode();
59+
self::assertEquals($country, 'CN');
60+
61+
$kernel = self::bootKernel(['config' => static function (TestKernel $kernel) {
62+
$kernel->addTestConfig(__DIR__.'/config/framework.yml');
63+
$kernel->addTestConfig(__DIR__.'/config/cache_symfony.yml');
64+
$kernel->addTestConfig(__DIR__.'/config/geo_plugin_fakeip_with_cache_fr.yml');
65+
}]);
66+
$container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer();
67+
68+
$geoPluginGeocoder = $container->get('bazinga_geocoder.provider.geoPlugin');
69+
$result = $geoPluginGeocoder->geocodeQuery(GeocodeQuery::create('::1'));
70+
$country = $result->first()->getCountry()->getCode();
71+
self::assertEquals($country, 'FR');
72+
}
73+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
framework:
2+
cache:
3+
# Put the unique name of your app here: the prefix seed
4+
# is used to compute stable namespaces for cache keys.
5+
#prefix_seed: your_vendor_name/app_name
6+
7+
# The app cache caches to the filesystem by default.
8+
# Other options include:
9+
10+
# Redis
11+
#app: cache.adapter.redis
12+
#default_redis_provider: redis://localhost
13+
14+
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
15+
#app: cache.adapter.apcu
16+
17+
# Namespaced pools use the above "app" backend by default
18+
#pools:
19+
#my.dedicated.cache: ~
20+
app: cache.adapter.filesystem
21+
system: cache.adapter.system
22+
pools:
23+
app.cache.geoPlugin:
24+
adapter: cache.app
25+
default_lifetime: 600
26+
services:
27+
app.simple_cache:
28+
class: Symfony\Component\Cache\Psr16Cache
29+
arguments: ['@app.cache.geoPlugin']
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See the docs at https://github.com/geocoder-php/BazingaGeocoderBundle
2+
bazinga_geocoder:
3+
# The local IP (127.0.0.1) will be replaced by the fake_ip
4+
# see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip
5+
fake_ip:
6+
local_ip: ::1
7+
ip: 123.123.123.128
8+
# this ip is in china
9+
providers:
10+
geoPlugin:
11+
factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory
12+
cache: 'app.simple_cache'
13+
cache_lifetime: 42
14+
cache_precision: ~
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See the docs at https://github.com/geocoder-php/BazingaGeocoderBundle
2+
bazinga_geocoder:
3+
# The local IP (127.0.0.1) will be replaced by the fake_ip
4+
# see https://github.com/geocoder-php/BazingaGeocoderBundle/blob/5.0.0/Resources/doc/index.md#fake-local-ip
5+
fake_ip:
6+
local_ip: ::1
7+
ip: 87.98.128.10
8+
# this ip is in france
9+
providers:
10+
geoPlugin:
11+
factory: Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory
12+
cache: 'app.simple_cache'
13+
cache_lifetime: 42
14+
cache_precision: ~

0 commit comments

Comments
 (0)