From 1a2dfa786f65ee6527ded2da8c4a0beb6ee99006 Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:21:52 +0200 Subject: [PATCH 1/3] feat: disable event_listeners_backward_compatibility_layer --- api/config/packages/api_platform.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/api/config/packages/api_platform.yaml b/api/config/packages/api_platform.yaml index 68ef972eb..10f5450c2 100644 --- a/api/config/packages/api_platform.yaml +++ b/api/config/packages/api_platform.yaml @@ -22,6 +22,7 @@ api_platform: extra_properties: standard_put: true rfc_7807_compliant_errors: true + event_listeners_backward_compatibility_layer: false oauth: enabled: true clientId: '%env(OIDC_SWAGGER_CLIENT_ID)%' From c34802681b8d1559f662ea48c7523666a8c795c3 Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Mon, 25 Sep 2023 09:59:02 +0200 Subject: [PATCH 2/3] fix: fix remove processors --- api/src/State/Processor/BookRemoveProcessor.php | 6 ++---- api/src/State/Processor/MercureProcessor.php | 8 +++++--- api/src/State/Processor/ReviewRemoveProcessor.php | 6 ++---- api/tests/State/Processor/BookRemoveProcessorTest.php | 5 +++-- api/tests/State/Processor/MercureProcessorTest.php | 2 +- api/tests/State/Processor/ReviewRemoveProcessorTest.php | 5 +++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/api/src/State/Processor/BookRemoveProcessor.php b/api/src/State/Processor/BookRemoveProcessor.php index de79ac002..7b33351b7 100644 --- a/api/src/State/Processor/BookRemoveProcessor.php +++ b/api/src/State/Processor/BookRemoveProcessor.php @@ -28,7 +28,7 @@ public function __construct( /** * @param Book $data */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): Book + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void { $object = clone $data; @@ -48,11 +48,9 @@ public function process(mixed $data, Operation $operation, array $uriVariables = $uriVariables, $context + [ 'item_uri_template' => $uriTemplate, - 'data' => json_encode(['@id' => $iri]), + MercureProcessor::DATA => json_encode(['@id' => $iri]), ] ); } - - return $data; } } diff --git a/api/src/State/Processor/MercureProcessor.php b/api/src/State/Processor/MercureProcessor.php index 20690a6ae..baa693c73 100644 --- a/api/src/State/Processor/MercureProcessor.php +++ b/api/src/State/Processor/MercureProcessor.php @@ -19,6 +19,8 @@ final readonly class MercureProcessor implements ProcessorInterface { + public const DATA = 'mercure_data'; + public function __construct( private SerializerInterface $serializer, private HubRegistry $hubRegistry, @@ -42,8 +44,8 @@ public function process(mixed $data, Operation $operation, array $uriVariables = if (!isset($context['topics'])) { $context['topics'] = [$this->iriConverter->getIriFromResource($data, UrlGeneratorInterface::ABS_URL, $operation)]; } - if (!isset($context['data'])) { - $context['data'] = $this->serializer->serialize( + if (!isset($context[self::DATA])) { + $context[self::DATA] = $this->serializer->serialize( $data, key($this->formats), ($operation->getNormalizationContext() ?? []) + (isset($context['item_uri_template']) ? [ @@ -54,7 +56,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables = $this->hubRegistry->getHub()->publish(new Update( topics: $context['topics'], - data: $context['data'] + data: $context[self::DATA] )); return $data; diff --git a/api/src/State/Processor/ReviewRemoveProcessor.php b/api/src/State/Processor/ReviewRemoveProcessor.php index 05efb2ce9..4f8401938 100644 --- a/api/src/State/Processor/ReviewRemoveProcessor.php +++ b/api/src/State/Processor/ReviewRemoveProcessor.php @@ -28,7 +28,7 @@ public function __construct( /** * @param Review $data */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): Review + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void { $object = clone $data; @@ -48,11 +48,9 @@ public function process(mixed $data, Operation $operation, array $uriVariables = $uriVariables, $context + [ 'item_uri_template' => $uriTemplate, - 'data' => json_encode(['@id' => $iri]), + MercureProcessor::DATA => json_encode(['@id' => $iri]), ] ); } - - return $data; } } diff --git a/api/tests/State/Processor/BookRemoveProcessorTest.php b/api/tests/State/Processor/BookRemoveProcessorTest.php index 8eea20cb4..f0217c6e2 100644 --- a/api/tests/State/Processor/BookRemoveProcessorTest.php +++ b/api/tests/State/Processor/BookRemoveProcessorTest.php @@ -14,6 +14,7 @@ use ApiPlatform\State\ProcessorInterface; use App\Entity\Book; use App\State\Processor\BookRemoveProcessor; +use App\State\Processor\MercureProcessor; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -87,7 +88,7 @@ public function testItRemovesBookAndSendMercureUpdates(): void [], [ 'item_uri_template' => '/admin/books/{id}{._format}', - 'data' => json_encode(['@id' => '/admin/books/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), + MercureProcessor::DATA => json_encode(['@id' => '/admin/books/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), ], ], [ @@ -96,7 +97,7 @@ public function testItRemovesBookAndSendMercureUpdates(): void [], [ 'item_uri_template' => '/books/{id}{._format}', - 'data' => json_encode(['@id' => '/books/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), + MercureProcessor::DATA => json_encode(['@id' => '/books/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), ], ], ); diff --git a/api/tests/State/Processor/MercureProcessorTest.php b/api/tests/State/Processor/MercureProcessorTest.php index 6192d096a..8b48947ba 100644 --- a/api/tests/State/Processor/MercureProcessorTest.php +++ b/api/tests/State/Processor/MercureProcessorTest.php @@ -104,7 +104,7 @@ public function testItSendsAMercureUpdateWithContextOptions(): void $this->processor->process($this->objectMock, $this->operationMock, [], [ 'item_uri_template' => '/admin/books/{id}{._format}', 'topics' => ['/admin/books/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6'], - 'data' => json_encode(['bar' => 'baz']), + MercureProcessor::DATA => json_encode(['bar' => 'baz']), ]); } } diff --git a/api/tests/State/Processor/ReviewRemoveProcessorTest.php b/api/tests/State/Processor/ReviewRemoveProcessorTest.php index e1f434e70..12dc38928 100644 --- a/api/tests/State/Processor/ReviewRemoveProcessorTest.php +++ b/api/tests/State/Processor/ReviewRemoveProcessorTest.php @@ -13,6 +13,7 @@ use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; use ApiPlatform\State\ProcessorInterface; use App\Entity\Review; +use App\State\Processor\MercureProcessor; use App\State\Processor\ReviewRemoveProcessor; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -87,7 +88,7 @@ public function testItRemovesBookAndSendMercureUpdates(): void [], [ 'item_uri_template' => '/admin/reviews/{id}{._format}', - 'data' => json_encode(['@id' => '/admin/reviews/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), + MercureProcessor::DATA => json_encode(['@id' => '/admin/reviews/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), ], ], [ @@ -96,7 +97,7 @@ public function testItRemovesBookAndSendMercureUpdates(): void [], [ 'item_uri_template' => '/books/{bookId}/reviews/{id}{._format}', - 'data' => json_encode(['@id' => '/books/8ad70d36-abaf-4c9b-aeaa-7ec63e6ca6f3/reviews/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), + MercureProcessor::DATA => json_encode(['@id' => '/books/8ad70d36-abaf-4c9b-aeaa-7ec63e6ca6f3/reviews/9aff4b91-31cf-4e91-94b0-1d52bbe23fe6']), ], ], ); From ea426fd8272b1d25fab1f907968b1b1f21903e12 Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Mon, 25 Sep 2023 09:59:13 +0200 Subject: [PATCH 3/3] fix: event_listeners BC layer --- api/tests/Api/ReviewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/tests/Api/ReviewTest.php b/api/tests/Api/ReviewTest.php index 6602f3f8c..040d76ccb 100644 --- a/api/tests/Api/ReviewTest.php +++ b/api/tests/Api/ReviewTest.php @@ -217,7 +217,7 @@ public function testAsAUserICannotAddAReviewWithValidDataOnAnInvalidBook(): void self::assertJsonContains([ '@type' => 'hydra:Error', 'hydra:title' => 'An error occurred', - 'hydra:description' => 'Invalid identifier value or configuration.', + 'hydra:description' => 'Invalid uri variables.', ]); }