|
| 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 | +} |
0 commit comments