From 2db4243034f07d053e6102af8d3b17b627cc2581 Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Thu, 30 May 2024 16:39:12 +0200 Subject: [PATCH] feature/easy-api-platform-remove-deprecations --- .../Symfony/Resources/config/services.php | 5 -- .../src/Routing/IriConverter.php | 46 ---------- .../src/Routing/NoIriItemInterface.php | 12 --- .../Routing/SelfProvidedIriItemInterface.php | 12 --- .../Bridge/Symfony/Stubs/IriConverterStub.php | 28 ------ .../tests/Bridge/Symfony/Stubs/KernelStub.php | 1 - .../tests/Routing/IriConverterTest.php | 90 ------------------- 7 files changed, 194 deletions(-) delete mode 100644 packages/EasyApiPlatform/src/Routing/IriConverter.php delete mode 100644 packages/EasyApiPlatform/src/Routing/NoIriItemInterface.php delete mode 100644 packages/EasyApiPlatform/src/Routing/SelfProvidedIriItemInterface.php delete mode 100644 packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/IriConverterStub.php delete mode 100644 packages/EasyApiPlatform/tests/Routing/IriConverterTest.php diff --git a/packages/EasyApiPlatform/src/Bridge/Symfony/Resources/config/services.php b/packages/EasyApiPlatform/src/Bridge/Symfony/Resources/config/services.php index e814bd05e7..725a2a2b0e 100644 --- a/packages/EasyApiPlatform/src/Bridge/Symfony/Resources/config/services.php +++ b/packages/EasyApiPlatform/src/Bridge/Symfony/Resources/config/services.php @@ -4,7 +4,6 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; use EonX\EasyApiPlatform\Bridge\Symfony\Listeners\ReadListener; -use EonX\EasyApiPlatform\Routing\IriConverter; return static function (ContainerConfigurator $container): void { $services = $container->services(); @@ -13,10 +12,6 @@ ->autowire() ->autoconfigure(); - $services->set(IriConverter::class) - ->decorate('api_platform.iri_converter') - ->arg('$decorated', service('.inner')); - $services->set(ReadListener::class) ->arg( '$resourceMetadataCollectionFactory', diff --git a/packages/EasyApiPlatform/src/Routing/IriConverter.php b/packages/EasyApiPlatform/src/Routing/IriConverter.php deleted file mode 100644 index d86e231bb8..0000000000 --- a/packages/EasyApiPlatform/src/Routing/IriConverter.php +++ /dev/null @@ -1,46 +0,0 @@ -getIri(); - } - - if ($resource instanceof NoIriItemInterface) { - return '__iri_not_supported'; - } - - return $this->decorated->getIriFromResource( - $resource, - $referenceType ?? UrlGeneratorInterface::ABS_PATH, - $operation, - $context ?? [] - ); - } - - public function getResourceFromIri(string $iri, ?array $context = null, ?Operation $operation = null): object - { - return $this->decorated->getResourceFromIri($iri, $context ?? [], $operation); - } -} diff --git a/packages/EasyApiPlatform/src/Routing/NoIriItemInterface.php b/packages/EasyApiPlatform/src/Routing/NoIriItemInterface.php deleted file mode 100644 index 57709f86dc..0000000000 --- a/packages/EasyApiPlatform/src/Routing/NoIriItemInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -setDefinition('api_platform.iri_converter', new Definition(IriConverterStub::class)); $container->setDefinition( 'api_platform.serializer.context_builder', new Definition(SerializerContextBuilderStub::class) diff --git a/packages/EasyApiPlatform/tests/Routing/IriConverterTest.php b/packages/EasyApiPlatform/tests/Routing/IriConverterTest.php deleted file mode 100644 index 1c67d76af3..0000000000 --- a/packages/EasyApiPlatform/tests/Routing/IriConverterTest.php +++ /dev/null @@ -1,90 +0,0 @@ -getIriFromResource($resource); - - self::assertSame('__iri_not_supported', $result); - } - - public function testGetIriFromResourceSucceedsWhenResourceImplementsSelfProvidedIriItemInterface(): void - { - $resource = new class() implements SelfProvidedIriItemInterface { - public function getIri(): string - { - return 'some-iri'; - } - }; - /** @var \ApiPlatform\Api\IriConverterInterface $decoratedIriConverter */ - $decoratedIriConverter = self::mock(IriConverterInterface::class); - $iriConverter = new IriConverter($decoratedIriConverter); - - $result = $iriConverter->getIriFromResource($resource); - - self::assertSame('some-iri', $result); - } - - public function testGetIriFromResourceSucceedsWhenResourceWithoutAnyInterface(): void - { - $resource = new class() { - // Just an object - }; - /** @var \ApiPlatform\Api\IriConverterInterface $decoratedIriConverter */ - $decoratedIriConverter = self::mock( - IriConverterInterface::class, - static function (MockInterface $mock) use ($resource): void { - $mock->expects('getIriFromResource') - ->with($resource, UrlGeneratorInterface::ABS_PATH, null, []) - ->andReturn('some-iri'); - } - ); - $iriConverter = new IriConverter($decoratedIriConverter); - - $result = $iriConverter->getIriFromResource($resource); - - self::assertSame('some-iri', $result); - } - - public function testGetResourceFromIriSucceeds(): void - { - $expectedResult = new Dummy(); - /** @var \ApiPlatform\Api\IriConverterInterface $decoratedIriConverter */ - $decoratedIriConverter = self::mock( - IriConverterInterface::class, - static function (MockInterface $mock) use ($expectedResult): void { - $mock->expects('getResourceFromIri') - ->with('some-iri', [], null) - ->andReturn($expectedResult); - } - ); - $iriConverter = new IriConverter($decoratedIriConverter); - - $actualResult = $iriConverter->getResourceFromIri('some-iri'); - - self::assertSame($expectedResult, $actualResult); - } -}