From 912dae1c33c2b3de1ae132fc08c2e6996c6e8f72 Mon Sep 17 00:00:00 2001 From: Tomasz Grochowski Date: Mon, 27 Sep 2021 17:42:51 +0200 Subject: [PATCH] fix: change order of mapping paths being loaded (#4465) Co-authored-by: Tomasz Grochowski Co-authored-by: Alan Poulain --- CHANGELOG.md | 1 + .../DependencyInjection/ApiPlatformExtension.php | 2 +- .../ApiPlatformExtensionTest.php | 14 ++++---------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e3f3f82fa1..30f4ae3c011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 2.7.0 +* **BC**: `mapping.paths` in configuration should override bundles configuration (#4465) * GraphQL: Add ability to use different pagination types for the queries of a resource (#4453) * Security: **BC** Fix `ApiProperty` `security` attribute expression being passed a class string for the `object` variable on updates/creates - null is now passed instead if the object is not available (#4184) * Security: `ApiProperty` now supports a `security_post_denormalize` attribute, which provides access to the `object` variable for the object being updated/created and `previous_object` for the object before it was updated (#4184) diff --git a/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index cfafef6b29b..743d9d96fcd 100644 --- a/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -330,7 +330,7 @@ private function getBundlesResourcesPaths(ContainerBuilder $container, array $co private function getResourcesToWatch(ContainerBuilder $container, array $config): array { - $paths = array_unique(array_merge($config['mapping']['paths'], $this->getBundlesResourcesPaths($container, $config))); + $paths = array_unique(array_merge($this->getBundlesResourcesPaths($container, $config), $config['mapping']['paths'])); // Flex structure (only if nothing specified) $projectDir = $container->getParameter('kernel.project_dir'); diff --git a/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index b35dbeadce4..9fc02347584 100644 --- a/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -101,7 +101,6 @@ use Nelmio\ApiDocBundle\NelmioApiDocBundle; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\Exception\Doubler\MethodNotFoundException; use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Config\Resource\DirectoryResource; @@ -899,6 +898,9 @@ static function (string $path): string { self::assertSame( $normalizePaths([ + "{$fixturesDirectory}/Fixtures/TestBundle/Resources/config/api_resources.yml", + "{$fixturesDirectory}/Fixtures/TestBundle/Resources/config/api_resources/dummy_address.yml", + "{$fixturesDirectory}/Fixtures/TestBundle/Resources/config/api_resources/my_resource.yml", "{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/B.yaml", "{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/Bb.yaml", "{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/a.yaml", @@ -906,9 +908,6 @@ static function (string $path): string { "{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/b/a.yaml", "{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/c.yaml", "{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/c/a.yaml", - "{$fixturesDirectory}/Fixtures/TestBundle/Resources/config/api_resources.yml", - "{$fixturesDirectory}/Fixtures/TestBundle/Resources/config/api_resources/dummy_address.yml", - "{$fixturesDirectory}/Fixtures/TestBundle/Resources/config/api_resources/my_resource.yml", ]), $normalizePaths($paths) ); @@ -1037,12 +1036,7 @@ private function getPartialContainerBuilderProphecy($configuration = null) } $containerBuilderProphecy->fileExists(Argument::type('string'))->shouldBeCalled(); - - try { - $containerBuilderProphecy->fileExists(Argument::type('string'))->shouldBeCalled(); - } catch (MethodNotFoundException $e) { - $containerBuilderProphecy->addResource(Argument::type(ResourceInterface::class))->shouldBeCalled(); - } + $containerBuilderProphecy->addResource(Argument::type(ResourceInterface::class))->shouldBeCalled(); $containerBuilderProphecy->hasExtension('http://symfony.com/schema/dic/services')->shouldBeCalled();