diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 184f26a7..aa07df6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,8 +53,22 @@ jobs: max-parallel: 10 fail-fast: true matrix: - php: ['7.3', '7.4', '8.0'] - sf_version: ['4.4.*', '5.2.*', '5.3.*'] + strategy: ['default'] + php: ['7.3', '7.4', '8.0', '8.1'] + include: + - php: '7.3' + sf_version: '4.4.*' + strategy: 'lowest' + - php: '7.4' + sf_version: '5.4.*' + - php: '8.0' + sf_version: '5.4.*' + - php: '8.1' + sf_version: '5.4.*' + - php: '8.0' + sf_version: '6.0.*' + - php: '8.1' + sf_version: '6.0.*' steps: - name: "Setup PHP" uses: shivammathur/setup-php@v2 @@ -66,37 +80,14 @@ jobs: - name: "Checkout code" uses: actions/checkout@v2 - - name: "Install Composer dependencies" + - name: "Install Composer dependencies (default)" + if: matrix.strategy != 'lowest' env: SYMFONY_REQUIRE: ${{ matrix.sf_version }} run: composer update --no-interaction --optimize-autoloader - - name: "Run tests" - env: - SYMFONY_DEPRECATIONS_HELPER: 'max[self]=2' - run: ./vendor/bin/simple-phpunit -v --testsuite main - - phpunit-lowest: - name: "PHPUnit (Lowest)" - runs-on: ubuntu-latest - strategy: - max-parallel: 10 - fail-fast: true - matrix: - php: ['7.4'] - sf_version: ['4.4.*', '5.2.*', '5.3.*'] - steps: - - name: "Setup PHP" - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - tools: composer:v2, flex - coverage: none - - - name: "Checkout code" - uses: actions/checkout@v2 - - - name: "Install Composer dependencies" + - name: "Install Composer dependencies (lowest)" + if: matrix.strategy == 'lowest' env: SYMFONY_REQUIRE: ${{ matrix.sf_version }} run: composer update --no-interaction --prefer-stable --prefer-lowest --optimize-autoloader @@ -113,8 +104,20 @@ jobs: max-parallel: 10 fail-fast: true matrix: - php: ['7.3', '7.4', '8.0'] - sf_version: ['4.4.*', '5.2.*', '5.3.*'] + php: ['7.4', '8.0', '8.1'] + include: + - php: '7.4' + sf_version: '4.4.*' + - php: '7.4' + sf_version: '5.4.*' + - php: '8.0' + sf_version: '5.4.*' + - php: '8.1' + sf_version: '5.4.*' + - php: '8.0' + sf_version: '6.0.*' + - php: '8.1' + sf_version: '6.0.*' steps: - name: "Setup PHP" uses: shivammathur/setup-php@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f96e46f..bd11b8ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The changelog describes what have been "Added", "Changed", "Removed" or "Fixed" between versions. +## Version 5.16.1 + +### Fixed + +- Allow Symfony 6 + ## Version 5.16.0 ### Added diff --git a/Command/GeocodeCommand.php b/Command/GeocodeCommand.php index 9fde664b..3c04a362 100644 --- a/Command/GeocodeCommand.php +++ b/Command/GeocodeCommand.php @@ -62,6 +62,8 @@ protected function configure() /** * {@inheritdoc} + * + * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/DependencyInjection/BazingaGeocoderExtension.php b/DependencyInjection/BazingaGeocoderExtension.php index 4c1d7e8c..d44c3161 100644 --- a/DependencyInjection/BazingaGeocoderExtension.php +++ b/DependencyInjection/BazingaGeocoderExtension.php @@ -59,7 +59,7 @@ public function load(array $configs, ContainerBuilder $container) $definition->replaceArgument(2, $config['fake_ip']['use_faker']); if ($config['fake_ip']['use_faker'] && !class_exists(Generator::class)) { - throw new \LogicException('To enable this option, you must install fzaninotto/faker package.'); + throw new \LogicException('To enable this option, you must install fakerphp/faker package.'); } } else { $container->removeDefinition(FakeIpPlugin::class); @@ -173,7 +173,7 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con } /** - * {@inheritdoc} + * @return Configuration */ public function getConfiguration(array $config, ContainerBuilder $container) { diff --git a/Doctrine/ORM/GeocoderListener.php b/Doctrine/ORM/GeocoderListener.php index 3e8b4d6b..ecc5cbdc 100644 --- a/Doctrine/ORM/GeocoderListener.php +++ b/Doctrine/ORM/GeocoderListener.php @@ -44,6 +44,8 @@ public function __construct(Provider $geocoder, DriverInterface $driver) /** * {@inheritdoc} + * + * @return array */ public function getSubscribedEvents() { diff --git a/Plugin/FakeIpPlugin.php b/Plugin/FakeIpPlugin.php index 7e1ce0de..479d390a 100644 --- a/Plugin/FakeIpPlugin.php +++ b/Plugin/FakeIpPlugin.php @@ -17,6 +17,7 @@ use Geocoder\Plugin\Plugin; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\Query; +use Http\Promise\Promise; /** * Replace local IP with something better. @@ -52,7 +53,7 @@ public function __construct(?string $needle, string $replacement = null, bool $u } /** - * {@inheritdoc} + * @return Promise */ public function handleQuery(Query $query, callable $next, callable $first) { diff --git a/Plugin/ProfilingPlugin.php b/Plugin/ProfilingPlugin.php index 9a0c01ee..6034599b 100644 --- a/Plugin/ProfilingPlugin.php +++ b/Plugin/ProfilingPlugin.php @@ -19,6 +19,7 @@ use Geocoder\Query\GeocodeQuery; use Geocoder\Query\Query; use Geocoder\Query\ReverseQuery; +use Http\Promise\Promise; /** * @author Tobias Nyholm @@ -40,6 +41,9 @@ public function __construct(string $name) $this->name = $name; } + /** + * @return Promise + */ public function handleQuery(Query $query, callable $next, callable $first) { $startTime = microtime(true); diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 3b6be1da..87b7372e 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -215,7 +215,7 @@ bazinga_geocoder: ip: 123.123.123.123 ``` -You can also let [Faker](https://github.com/fzaninotto/Faker) generate fake ip for you. +You can also let [Faker](https://github.com/fakerphp/faker) generate fake ip for you. ```yaml bazinga_geocoder: diff --git a/Tests/Command/GeocodeCommandTest.php b/Tests/Command/GeocodeCommandTest.php index a3b622ab..a13de67c 100644 --- a/Tests/Command/GeocodeCommandTest.php +++ b/Tests/Command/GeocodeCommandTest.php @@ -32,7 +32,7 @@ class GeocodeCommandTest extends TestCase { private static $address = '10 rue Gambetta, Paris, France'; - public function testExecute() + public function testExecute(): void { $coordinates = new Coordinates(1, 2); $country = new Country('France', 'FR'); @@ -59,7 +59,7 @@ public function testExecute() $kernel->expects($this->any()) ->method('getContainer') - ->will($this->returnValue($container)); + ->willReturn($container); $kernel->expects($this->any()) ->method('getBundles') diff --git a/Tests/DependencyInjection/Compiler/AddProvidersPassTest.php b/Tests/DependencyInjection/Compiler/AddProvidersPassTest.php index 71360e65..8e5a276f 100644 --- a/Tests/DependencyInjection/Compiler/AddProvidersPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddProvidersPassTest.php @@ -17,25 +17,22 @@ use Geocoder\ProviderAggregator; use Http\Client\Curl\Client; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; class AddProvidersPassTest extends TestCase { - use SetUpTearDownTrait; - /** * @var AddProvidersPass */ private $compilerPass; - protected function doSetUp() + protected function setUp(): void { $this->compilerPass = new AddProvidersPass(); } - public function testRegistersProviders() + public function testRegistersProviders(): void { $containerBuilder = new ContainerBuilder(); $containerBuilder->setDefinition(ProviderAggregator::class, new Definition(ProviderAggregator::class)); diff --git a/Tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php b/Tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php index 7c8c4014..099f506b 100644 --- a/Tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php +++ b/Tests/DependencyInjection/Compiler/FactoryValidatorPassTest.php @@ -14,14 +14,11 @@ use Bazinga\GeocoderBundle\DependencyInjection\Compiler\FactoryValidatorPass; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; class FactoryValidatorPassTest extends TestCase { - use SetUpTearDownTrait; - /** * @var FactoryValidatorPass */ @@ -32,14 +29,14 @@ class FactoryValidatorPassTest extends TestCase */ private $factoryId; - protected function doSetUp() + protected function setUp(): void { $this->compilerPass = new FactoryValidatorPass(); $this->factoryId = 'dummy_factory_id'; $this->compilerPass::addFactoryServiceId($this->factoryId); } - protected function doTearDown() + protected function tearDown(): void { $reflection = new \ReflectionObject($this->compilerPass); $prop = $reflection->getProperty('factoryServiceIds'); @@ -47,7 +44,7 @@ protected function doTearDown() $prop->setValue([]); } - public function testProcessThrows() + public function testProcessThrows(): void { $this->expectException(ServiceNotFoundException::class); $this->expectExceptionMessage("Factory with ID \"$this->factoryId\" could not be found"); @@ -65,7 +62,7 @@ public function testProcessThrows() $this->compilerPass->process($container); } - public function testProcessDoesntThrowIfAliasExists() + public function testProcessDoesntThrowIfAliasExists(): void { $container = $this->createMock(ContainerBuilder::class); $container->expects($this->once()) @@ -80,7 +77,7 @@ public function testProcessDoesntThrowIfAliasExists() $this->compilerPass->process($container); } - public function testProcessDoesntThrowIfDefinitionExists() + public function testProcessDoesntThrowIfDefinitionExists(): void { $container = $this->createMock(ContainerBuilder::class); $container->expects($this->once()) diff --git a/Tests/DependencyInjection/Compiler/ProfilerPassTest.php b/Tests/DependencyInjection/Compiler/ProfilerPassTest.php index 83339f32..e7b8e458 100644 --- a/Tests/DependencyInjection/Compiler/ProfilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/ProfilerPassTest.php @@ -16,26 +16,23 @@ use Bazinga\GeocoderBundle\DependencyInjection\Compiler\ProfilerPass; use Bazinga\GeocoderBundle\Plugin\ProfilingPlugin; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; class ProfilerPassTest extends TestCase { - use SetUpTearDownTrait; - /** * @var ProfilerPass */ private $compilerPass; - protected function doSetUp() + protected function setUp(): void { $this->compilerPass = new ProfilerPass(); } - public function testRegistersProviders() + public function testRegistersProviders(): void { $geocoderDataCollectorDefinition = new Definition(GeocoderDataCollector::class); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index b3d24a6a..61e58006 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -22,7 +22,7 @@ */ class ConfigurationTest extends TestCase { - public function testGetConfigTreeBuilder() + public function testGetConfigTreeBuilder(): void { $config = Yaml::parse(file_get_contents(__DIR__.'/Fixtures/config.yml')); @@ -38,7 +38,7 @@ public function testGetConfigTreeBuilder() $this->assertSame('33.33.33.11', $config['fake_ip']['ip']); } - public function testGetConfigTreeBuilderNoDebug() + public function testGetConfigTreeBuilderNoDebug(): void { $config = Yaml::parse(file_get_contents(__DIR__.'/Fixtures/config.yml')); diff --git a/Tests/Doctrine/ORM/GeocoderListenerTest.php b/Tests/Doctrine/ORM/GeocoderListenerTest.php index 4b00ad53..667a6a60 100644 --- a/Tests/Doctrine/ORM/GeocoderListenerTest.php +++ b/Tests/Doctrine/ORM/GeocoderListenerTest.php @@ -13,27 +13,32 @@ namespace Bazinga\GeocoderBundle\Tests\Doctrine\ORM; use Bazinga\GeocoderBundle\Doctrine\ORM\GeocoderListener; +use Bazinga\GeocoderBundle\Mapping\Annotations\Address; +use Bazinga\GeocoderBundle\Mapping\Annotations\Geocodeable; +use Bazinga\GeocoderBundle\Mapping\Annotations\Latitude; +use Bazinga\GeocoderBundle\Mapping\Annotations\Longitude; use Bazinga\GeocoderBundle\Mapping\Driver\AnnotationDriver; use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\SimpleAnnotationReader; use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Events; +use Doctrine\ORM\Mapping\Column; +use Doctrine\ORM\Mapping\Entity; +use Doctrine\ORM\Mapping\GeneratedValue; +use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\OrmTestCase; use Geocoder\Provider\Nominatim\Nominatim; use Http\Client\Curl\Client; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; /** * @author Markus Bachmann */ class GeocoderListenerTest extends OrmTestCase { - use SetUpTearDownTrait; - /** * @var EntityManager */ @@ -44,8 +49,10 @@ class GeocoderListenerTest extends OrmTestCase */ private $listener; - public static function doSetUpBeforeClass(): void + public static function setUpBeforeClass(): void { + parent::setUpBeforeClass(); + if (!class_exists(OrmTestCase::class)) { /* * We check for DoctrineTestCase because it is in the same package as OrmTestCase and we want to be able to @@ -55,8 +62,10 @@ public static function doSetUpBeforeClass(): void } } - protected function doSetUp(): void + protected function setUp(): void { + parent::setUp(); + AnnotationRegistry::registerLoader('class_exists'); $conn = DriverManager::getConnection([ @@ -85,7 +94,7 @@ protected function doSetUp(): void ]); } - public function testPersistForProperty() + public function testPersistForProperty(): void { $dummy = new DummyWithProperty(); $dummy->address = 'Berlin, Germany'; @@ -106,7 +115,7 @@ public function testPersistForProperty() $this->assertNotEquals($clone->longitude, $dummy->longitude); } - public function testPersistForGetter() + public function testPersistForGetter(): void { $dummy = new DummyWithGetter(); $dummy->setAddress('Berlin, Germany'); @@ -127,7 +136,7 @@ public function testPersistForGetter() $this->assertNotEquals($clone->getLongitude(), $dummy->getLongitude()); } - public function testPersistForInvalidGetter() + public function testPersistForInvalidGetter(): void { $dummy = new DummyWithInvalidGetter(); $dummy->setAddress('Berlin, Germany'); @@ -139,7 +148,7 @@ public function testPersistForInvalidGetter() $this->em->flush(); } - public function testPersistForEmptyProperty() + public function testPersistForEmptyProperty(): void { $dummy = new DummyWithEmptyProperty(); $dummy->address = ''; @@ -151,7 +160,7 @@ public function testPersistForEmptyProperty() $this->assertNull($dummy->longitude); } - public function testDoesNotGeocodeIfAddressNotChanged() + public function testDoesNotGeocodeIfAddressNotChanged(): void { $this->em->getEventManager()->removeEventListener(Events::onFlush, $this->listener); @@ -192,14 +201,15 @@ public function testDoesNotGeocodeIfAddressNotChanged() class DummyWithProperty { /** - * @Id @GeneratedValue + * @Id + * @GeneratedValue * @Column(type="integer") */ public $id; /** * @Latitude - * @Column + * @Column() */ public $latitude; diff --git a/Tests/Functional/BundleInitializationTest.php b/Tests/Functional/BundleInitializationTest.php index 8ad0f7d2..0a0d9590 100644 --- a/Tests/Functional/BundleInitializationTest.php +++ b/Tests/Functional/BundleInitializationTest.php @@ -13,6 +13,7 @@ namespace Bazinga\GeocoderBundle\Tests\Functional; use Bazinga\GeocoderBundle\BazingaGeocoderBundle; +use Bazinga\GeocoderBundle\Tests\PublicServicePass; use Geocoder\Dumper\GeoArray; use Geocoder\Dumper\GeoJson; use Geocoder\Dumper\Gpx; @@ -24,33 +25,37 @@ use Geocoder\Plugin\PluginProvider; use Geocoder\Provider\GoogleMaps\GoogleMaps; use Geocoder\ProviderAggregator; -use Nyholm\BundleTest\BaseBundleTestCase; -use Nyholm\BundleTest\CompilerPass\PublicServicePass; +use Nyholm\BundleTest\TestKernel; use Nyholm\NSA; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\HttpKernel\KernelInterface; -class BundleInitializationTest extends BaseBundleTestCase +class BundleInitializationTest extends KernelTestCase { - use SetUpTearDownTrait; - - protected function doSetUp(): void + protected static function getKernelClass(): string { - $this->addCompilerPass(new PublicServicePass('|[Bb]azinga:*|')); - $this->addCompilerPass(new PublicServicePass('|[gG]eocoder:*|')); + return TestKernel::class; } - protected function getBundleClass() + protected static function createKernel(array $options = []): KernelInterface { - return BazingaGeocoderBundle::class; + /** + * @var TestKernel $kernel + */ + $kernel = parent::createKernel($options); + $kernel->addTestBundle(BazingaGeocoderBundle::class); + $kernel->addTestCompilerPass(new PublicServicePass('|[Bb]azinga:*|')); + $kernel->addTestCompilerPass(new PublicServicePass('|[gG]eocoder:*|')); + $kernel->handleOptions($options); + + return $kernel; } - public function testInitBundle() + public function testInitBundle(): void { - // Boot the kernel. - $this->bootKernel(); + $kernel = self::bootKernel(); - // Get the container - $container = $this->getContainer(); + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); // Test if services exists $this->assertTrue($container->has(ProviderAggregator::class)); @@ -58,17 +63,13 @@ public function testInitBundle() $this->assertInstanceOf(ProviderAggregator::class, $service); } - public function testBundleWithOneProviderConfiguration() + public function testBundleWithOneProviderConfiguration(): void { - // Create a new Kernel - $kernel = $this->createKernel(); - - // Add some configuration - $kernel->addConfigFile(__DIR__.'/config/simple.yml'); + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/config/simple.yml'); + }]); - // Boot the kernel as normal ... - $this->bootKernel(); - $container = $this->getContainer(); + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); $this->assertTrue($container->has('bazinga_geocoder.provider.acme')); $service = $container->get('bazinga_geocoder.provider.acme'); @@ -76,12 +77,13 @@ public function testBundleWithOneProviderConfiguration() $this->assertInstanceOf(GoogleMaps::class, NSA::getProperty($service, 'provider')); } - public function testBundleWithCachedProvider() + public function testBundleWithCachedProvider(): void { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/config/cache.yml'); - $this->bootKernel(); - $container = $this->getContainer(); + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/config/cache.yml'); + }]); + + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); $this->assertTrue($container->has('bazinga_geocoder.provider.acme')); $service = $container->get('bazinga_geocoder.provider.acme'); @@ -91,14 +93,13 @@ public function testBundleWithCachedProvider() $this->assertInstanceOf(CachePlugin::class, $plugins[0]); } - public function testCacheLifetimeCanBeNull() + public function testCacheLifetimeCanBeNull(): void { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/config/cache_without_lifetime.yml'); - - $this->bootKernel(); + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/config/cache_without_lifetime.yml'); + }]); - $container = $this->getContainer(); + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); self::assertTrue($container->has('bazinga_geocoder.provider.acme')); @@ -116,12 +117,13 @@ public function testCacheLifetimeCanBeNull() self::assertNull($cacheLifeTime); } - public function testBundleWithPluginsYml() + public function testBundleWithPluginsYml(): void { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/config/service_plugin.yml'); - $this->bootKernel(); - $container = $this->getContainer(); + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/config/service_plugin.yml'); + }]); + + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); $this->assertTrue($container->has('bazinga_geocoder.provider.acme')); $service = $container->get('bazinga_geocoder.provider.acme'); @@ -131,12 +133,13 @@ public function testBundleWithPluginsYml() $this->assertInstanceOf(LoggerPlugin::class, $plugins[0]); } - public function testBundleWithPluginXml() + public function testBundleWithPluginXml(): void { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/config/service_plugin.xml'); - $this->bootKernel(); - $container = $this->getContainer(); + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/config/service_plugin.xml'); + }]); + + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); $this->assertTrue($container->has('bazinga_geocoder.provider.acme')); $service = $container->get('bazinga_geocoder.provider.acme'); @@ -146,10 +149,11 @@ public function testBundleWithPluginXml() $this->assertInstanceOf(LoggerPlugin::class, $plugins[0]); } - public function testBundleHasRegisteredDumpers() + public function testBundleHasRegisteredDumpers(): void { - $this->bootKernel(); - $container = $this->getContainer(); + $kernel = self::bootKernel(); + + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); $this->assertTrue($container->has(GeoArray::class)); $this->assertTrue($container->has(GeoJson::class)); diff --git a/Tests/Functional/Helper/CacheHelper.php b/Tests/Functional/Helper/CacheHelper.php index 3ff6d715..c704c304 100644 --- a/Tests/Functional/Helper/CacheHelper.php +++ b/Tests/Functional/Helper/CacheHelper.php @@ -21,40 +21,64 @@ */ class CacheHelper implements CacheInterface { + /** + * @return mixed + */ public function get($key, $default = null) { } + /** + * @return bool + */ public function set($key, $value, $ttl = null) { return true; } + /** + * @return bool + */ public function delete($key) { return true; } + /** + * @return bool + */ public function clear() { return true; } + /** + * @return iterable + */ public function getMultiple($keys, $default = null) { return []; } + /** + * @return bool + */ public function setMultiple($values, $ttl = null) { return true; } + /** + * @return bool + */ public function deleteMultiple($keys) { return true; } + /** + * @return bool + */ public function has($key) { return false; diff --git a/Tests/Functional/ProviderFactoryTest.php b/Tests/Functional/ProviderFactoryTest.php index 0c78b66c..73fa31f0 100644 --- a/Tests/Functional/ProviderFactoryTest.php +++ b/Tests/Functional/ProviderFactoryTest.php @@ -13,6 +13,7 @@ namespace Bazinga\GeocoderBundle\Tests\Functional; use Bazinga\GeocoderBundle\BazingaGeocoderBundle; +use Bazinga\GeocoderBundle\Tests\PublicServicePass; use Geocoder\Provider\AlgoliaPlaces\AlgoliaPlaces; use Geocoder\Provider\ArcGISOnline\ArcGISOnline; use Geocoder\Provider\BingMaps\BingMaps; @@ -41,26 +42,51 @@ use Geocoder\Provider\PickPoint\PickPoint; use Geocoder\Provider\TomTom\TomTom; use Geocoder\Provider\Yandex\Yandex; -use Nyholm\BundleTest\BaseBundleTestCase; -use Nyholm\BundleTest\CompilerPass\PublicServicePass; +use Nyholm\BundleTest\TestKernel; use Nyholm\NSA; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\HttpKernel\KernelInterface; -class ProviderFactoryTest extends BaseBundleTestCase +class ProviderFactoryTest extends KernelTestCase { - use SetUpTearDownTrait; + protected static function getKernelClass(): string + { + return TestKernel::class; + } - protected function doSetUp(): void + protected static function createKernel(array $options = []): KernelInterface { - $this->addCompilerPass(new PublicServicePass('|bazinga.*|')); + /** + * @var TestKernel $kernel + */ + $kernel = parent::createKernel($options); + $kernel->addTestBundle(BazingaGeocoderBundle::class); + $kernel->addTestCompilerPass(new PublicServicePass('|[Bb]azinga:*|')); + $kernel->addTestCompilerPass(new PublicServicePass('|[gG]eocoder:*|')); + $kernel->handleOptions($options); + + return $kernel; } - protected function getBundleClass() + /** + * @dataProvider getProviders + */ + public function testProviderConfiguration($class, $serviceNames): void { - return BazingaGeocoderBundle::class; + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) use ($class) { + $kernel->addTestConfig(__DIR__.'/config/provider/'.strtolower(substr($class, strrpos($class, '\\') + 1)).'.yml'); + }]); + + $container = method_exists(__CLASS__, 'getContainer') ? self::getContainer() : $kernel->getContainer(); + + foreach ($serviceNames as $name) { + $this->assertTrue($container->has('bazinga_geocoder.provider.'.$name)); + $service = $container->get('bazinga_geocoder.provider.'.$name); + $this->assertInstanceOf($class, NSA::getProperty($service, 'provider')); + } } - public function getProviders() + public function getProviders(): iterable { yield [AlgoliaPlaces::class, ['empty', 'acme']]; yield [ArcGISOnline::class, ['empty', 'acme']]; @@ -95,26 +121,4 @@ public function getProviders() yield [TomTom::class, ['acme']]; yield [Yandex::class, ['empty', 'acme']]; } - - /** - * @dataProvider getProviders - */ - public function testProviderConfiguration($class, $serviceNames) - { - // Create a new Kernel - $kernel = $this->createKernel(); - - // Add some configuration - $kernel->addConfigFile(__DIR__.'/config/provider/'.strtolower(substr($class, strrpos($class, '\\') + 1)).'.yml'); - - // Boot the kernel as normal ... - $this->bootKernel(); - $container = $this->getContainer(); - - foreach ($serviceNames as $name) { - $this->assertTrue($container->has('bazinga_geocoder.provider.'.$name)); - $service = $container->get('bazinga_geocoder.provider.'.$name); - $this->assertInstanceOf($class, NSA::getProperty($service, 'provider')); - } - } } diff --git a/Tests/Mapping/Driver/AnnotationDriverTest.php b/Tests/Mapping/Driver/AnnotationDriverTest.php index e020f4a8..84354583 100644 --- a/Tests/Mapping/Driver/AnnotationDriverTest.php +++ b/Tests/Mapping/Driver/AnnotationDriverTest.php @@ -18,15 +18,12 @@ use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Annotations\SimpleAnnotationReader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; /** * @author Markus Bachmann */ class AnnotationDriverTest extends TestCase { - use SetUpTearDownTrait; - /** * @var AnnotationDriver */ @@ -37,7 +34,7 @@ class AnnotationDriverTest extends TestCase */ private $reader; - protected function doSetUp(): void + protected function setUp(): void { AnnotationRegistry::registerLoader('class_exists'); @@ -47,7 +44,7 @@ protected function doSetUp(): void $this->driver = new AnnotationDriver($this->reader); } - public function testLoadMetadata() + public function testLoadMetadata(): void { $obj = new Dummy(); $metadata = $this->driver->loadMetadataFromObject($obj); @@ -57,7 +54,7 @@ public function testLoadMetadata() $this->assertInstanceOf('ReflectionProperty', $metadata->longitudeProperty); } - public function testLoadMetadataFromWrongObject() + public function testLoadMetadataFromWrongObject(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage('The class '.Dummy2::class.' is not geocodeable'); @@ -65,7 +62,7 @@ public function testLoadMetadataFromWrongObject() $this->driver->loadMetadataFromObject(new Dummy2()); } - public function testIsGeocodable() + public function testIsGeocodable(): void { $this->assertTrue($this->driver->isGeocodeable(new Dummy())); } diff --git a/Tests/Mapping/Driver/AttributeDriverTest.php b/Tests/Mapping/Driver/AttributeDriverTest.php index 4bbfd943..a2ec185a 100644 --- a/Tests/Mapping/Driver/AttributeDriverTest.php +++ b/Tests/Mapping/Driver/AttributeDriverTest.php @@ -18,40 +18,34 @@ use Bazinga\GeocoderBundle\Mapping\Annotations\Longitude; use Bazinga\GeocoderBundle\Mapping\Driver\AttributeDriver; use Bazinga\GeocoderBundle\Mapping\Exception\MappingException; -use Doctrine\Common\Annotations\Reader; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; /** * @author Pierre du Plessis */ final class AttributeDriverTest extends TestCase { - use SetUpTearDownTrait; - /** * @var AttributeDriver */ private $driver; - /** - * @var Reader - */ - private $reader; - - public static function doSetUpBeforeClass(): void + public static function setUpBeforeClass(): void { if (PHP_VERSION_ID < 80000) { self::markTestSkipped(sprintf('"%s" is only supported on PHP 8', AttributeDriver::class)); } } - protected function doSetUp(): void + protected function setUp(): void { $this->driver = new AttributeDriver(); } - public function testLoadMetadata() + /** + * @requires PHP 8.0 + */ + public function testLoadMetadata(): void { $obj = new Dummy3(); $metadata = $this->driver->loadMetadataFromObject($obj); @@ -61,7 +55,10 @@ public function testLoadMetadata() $this->assertInstanceOf('ReflectionProperty', $metadata->longitudeProperty); } - public function testLoadMetadataFromWrongObject() + /** + * @requires PHP 8.0 + */ + public function testLoadMetadataFromWrongObject(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage('The class '.Dummy4::class.' is not geocodeable'); @@ -69,7 +66,10 @@ public function testLoadMetadataFromWrongObject() $this->driver->loadMetadataFromObject(new Dummy4()); } - public function testIsGeocodable() + /** + * @requires PHP 8.0 + */ + public function testIsGeocodable(): void { $this->assertTrue($this->driver->isGeocodeable(new Dummy3())); } diff --git a/Tests/Plugin/FakeIpPluginTest.php b/Tests/Plugin/FakeIpPluginTest.php index aae00c77..4997763c 100644 --- a/Tests/Plugin/FakeIpPluginTest.php +++ b/Tests/Plugin/FakeIpPluginTest.php @@ -22,7 +22,7 @@ */ class FakeIpPluginTest extends TestCase { - public function testSimpleHandleQuery() + public function testSimpleHandleQuery(): void { $fakeIpPlugin = new FakeIpPlugin('127.0.0.1', '123.123.123.123'); $query = GeocodeQuery::create('127.0.0.1'); @@ -37,7 +37,7 @@ public function testSimpleHandleQuery() * @testWith [null] * [""] */ - public function testEmptyLocalIpQuery(?string $localIp) + public function testEmptyLocalIpQuery(?string $localIp): void { $fakeIpPlugin = new FakeIpPlugin($localIp, '123.123.123.123'); $query = GeocodeQuery::create('124.124.124.124'); @@ -48,7 +48,7 @@ public function testEmptyLocalIpQuery(?string $localIp) $this->assertSame($query->getText(), '123.123.123.123'); } - public function testHandleQueryUsingFaker() + public function testHandleQueryUsingFaker(): void { $fakeIpPlugin = new FakeIpPlugin('127.0.0.1', '192.168.1.1', true); $query = GeocodeQuery::create('127.0.0.1'); diff --git a/Tests/PublicServicePass.php b/Tests/PublicServicePass.php new file mode 100644 index 00000000..daff186f --- /dev/null +++ b/Tests/PublicServicePass.php @@ -0,0 +1,56 @@ + + * + * @internal + * + * Note: this can be removed when we'll support only Symfony >5.3 + */ +final class PublicServicePass implements CompilerPassInterface +{ + /** + * A regex to match the services that should be public. + * + * @var string + */ + private $regex; + + /** + * @param string $regex + */ + public function __construct($regex = '|.*|') + { + $this->regex = $regex; + } + + public function process(ContainerBuilder $container) + { + foreach ($container->getDefinitions() as $id => $definition) { + if (preg_match($this->regex, $id)) { + $definition->setPublic(true); + } + } + + foreach ($container->getAliases() as $id => $alias) { + if (preg_match($this->regex, $id)) { + $alias->setPublic(true); + } + } + } +} diff --git a/Tests/Validator/Constraint/AddressValidatorTest.php b/Tests/Validator/Constraint/AddressValidatorTest.php index c6333424..eafeb09e 100644 --- a/Tests/Validator/Constraint/AddressValidatorTest.php +++ b/Tests/Validator/Constraint/AddressValidatorTest.php @@ -16,47 +16,47 @@ use Bazinga\GeocoderBundle\Validator\Constraint\AddressValidator; use Geocoder\Provider\Nominatim\Nominatim; use Http\Client\Curl\Client; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Component\Validator\Exception\UnexpectedValueException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; class AddressValidatorTest extends ConstraintValidatorTestCase { - protected function createValidator() + protected function createValidator(): AddressValidator { $geocoder = Nominatim::withOpenStreetMapServer(new Client(), 'BazingaGeocoderBundle/Test'); return new AddressValidator($geocoder); } - public function testNullIsValid() + public function testNullIsValid(): void { $this->validator->validate(null, new Address()); $this->assertNoViolation(); } - public function testEmptyStringIsValid() + public function testEmptyStringIsValid(): void { $this->validator->validate('', new Address()); $this->assertNoViolation(); } - public function testExpectsStringCompatibleType() + public function testExpectsStringCompatibleType(): void { - $this->expectException(UnexpectedTypeException::class); + $this->expectException(UnexpectedValueException::class); $this->validator->validate(new \stdClass(), new Address()); } - public function testValidAddress() + public function testValidAddress(): void { $this->validator->validate('Berlin, Germany', new Address()); $this->assertNoViolation(); } - public function testInvalidAddress() + public function testInvalidAddress(): void { $address = 'Bifrost, Nine Realms'; diff --git a/Validator/Constraint/AddressValidator.php b/Validator/Constraint/AddressValidator.php index 8efba9f8..f1dd35b6 100644 --- a/Validator/Constraint/AddressValidator.php +++ b/Validator/Constraint/AddressValidator.php @@ -43,11 +43,7 @@ public function validate($value, Constraint $constraint) } if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { - if (class_exists(UnexpectedValueException::class)) { - throw new UnexpectedValueException($value, 'string'); - } else { - throw new UnexpectedTypeException($value, 'string'); - } + throw new UnexpectedValueException($value, 'string'); } $value = (string) $value; diff --git a/composer.json b/composer.json index 795d8e48..930895ce 100644 --- a/composer.json +++ b/composer.json @@ -14,16 +14,16 @@ "php": "^7.3 || ^8.0", "geocoder-php/plugin": "^1.3", "php-http/discovery": "^1.13", - "symfony/console": "^4.4 || ^5.0", - "symfony/framework-bundle": "^4.4 || ^5.0", - "symfony/options-resolver": "^4.4 || ^5.0", + "symfony/console": "^4.4 || ^5.0 || ^6.0", + "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0", + "symfony/options-resolver": "^4.4 || ^5.0 || ^6.0", "willdurand/geocoder": "^4.4" }, "require-dev": { "doctrine/cache": "~1.3", "doctrine/orm": "~2.8", "fakerphp/faker": "^1.14", - "friendsofphp/php-cs-fixer": "^3.0", + "friendsofphp/php-cs-fixer": "^3.4", "geocoder-php/algolia-places-provider": "^0.3", "geocoder-php/arcgis-online-provider": "^4.3", "geocoder-php/bing-maps-provider": "^4.2", @@ -55,14 +55,14 @@ "geoip/geoip": "~1.17", "nyholm/nsa": "^1.2", "nyholm/psr7": "^1.3", - "nyholm/symfony-bundle-test": "^1.7", + "nyholm/symfony-bundle-test": "dev-master", "php-http/curl-client": "^2.2", "php-http/message": "^1.5", - "phpstan/phpstan": "^0.12.68", - "symfony/config": "^4.4 || ^5.0", - "symfony/phpunit-bridge": "^5.2", - "symfony/validator": "^4.4 || ^5.0", - "symfony/yaml": "^4.4 || ^5.0" + "phpstan/phpstan": "^1.1", + "symfony/config": "^4.4 || ^5.0 || ^6.0", + "symfony/phpunit-bridge": "^5.2 || ^6.0", + "symfony/validator": "^4.4 || ^5.0 || ^6.0", + "symfony/yaml": "^4.4 || ^5.0 || ^6.0" }, "conflict": { "geocoder-php/nominatim-provider": "<5.0" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 60fbf0c8..e3f82945 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,7 +1,7 @@ parameters: paths: - %currentWorkingDirectory% - excludes_analyse: + excludePaths: - ./vendor/ - ./Tests/ level: 2 @@ -12,6 +12,3 @@ parameters: - path: %currentWorkingDirectory%/ProviderFactory/GeoipFactory.php message: '#Geocoder\\Provider\\Geoip\\Geoip not found#' - - - path: %currentWorkingDirectory%/Plugin/FakeIpPlugin.php - message: '#Call to an undefined method Faker\\Generator::ipv4\(\)#'