feat(state): added "Accept-Post" and "Allow" headers - #8
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements compliance with the LDP (Linked Data Platform) specification by adding two HTTP headers to API responses: Accept-Post (listing supported POST content types) and Allow (listing permitted HTTP methods for a resource).
Changes:
- Added
LinkedDataPlatformProcessorto setAccept-PostandAllowheaders based on resource operations - Integrated the processor into the Laravel service provider
- Added comprehensive test coverage for both functional and unit testing
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/State/Processor/LinkedDataPlatformProcessor.php | New processor that analyzes resource operations and sets LDP-compliant headers |
| src/Laravel/ApiPlatformProvider.php | Registers the new LinkedDataPlatformProcessor in the Laravel DI container |
| src/State/Tests/Processor/LinkedDataPlatformProcessorTest.php | Unit tests verifying processor behavior for header generation |
| tests/Functional/LinkDataPlatformTest.php | Functional tests ensuring headers are correctly set in real API requests |
| tests/Fixtures/TestBundle/ApiResource/DummyGetPostDeleteOperation.php | Test fixture resource with GET, POST, and DELETE operations |
| src/State/Tests/Fixtures/ApiResource/Dummy.php | Basic test fixture for unit testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $this->assertResponseHeaderSame('accept-post', 'application/ld+json, application/hal+json, application/vnd.api+json, application/xml, text/xml, application/json, text/html, application/graphql, multipart/form-data'); | ||
| } | ||
|
|
||
| public function testAcceptPostHeaderDoesNotExistResourceWithoutPost(): void |
There was a problem hiding this comment.
The test method name contains a grammatical error. Consider renaming to 'testAcceptPostHeaderDoesNotExistForResourceWithoutPost' to improve readability and clarity.
| public function testAcceptPostHeaderDoesNotExistResourceWithoutPost(): void | |
| public function testAcceptPostHeaderDoesNotExistForResourceWithoutPost(): void |
| provider: [self::class, 'provide'], ), | ||
| new Post( | ||
| uriTemplate: '/dummy_get_post_delete_operations', | ||
| provider: [self::class, 'provide'], ), | ||
| new Delete( | ||
| uriTemplate: '/dummy_get_post_delete_operations/{id}', | ||
| provider: [self::class, 'provideItem'], ), |
There was a problem hiding this comment.
Inconsistent formatting: closing parenthesis and comma are on the same line as the provider parameter, while other operations place the closing parenthesis on a new line. Consider moving the closing parenthesis to a new line for consistency with lines 36-37.
| provider: [self::class, 'provide'], ), | |
| new Post( | |
| uriTemplate: '/dummy_get_post_delete_operations', | |
| provider: [self::class, 'provide'], ), | |
| new Delete( | |
| uriTemplate: '/dummy_get_post_delete_operations/{id}', | |
| provider: [self::class, 'provideItem'], ), | |
| provider: [self::class, 'provide'], | |
| ), | |
| new Post( | |
| uriTemplate: '/dummy_get_post_delete_operations', | |
| provider: [self::class, 'provide'], | |
| ), | |
| new Delete( | |
| uriTemplate: '/dummy_get_post_delete_operations/{id}', | |
| provider: [self::class, 'provideItem'], | |
| ), |
| provider: [self::class, 'provide'], ), | ||
| new Post( | ||
| uriTemplate: '/dummy_get_post_delete_operations', | ||
| provider: [self::class, 'provide'], ), |
There was a problem hiding this comment.
Inconsistent formatting: closing parenthesis and comma are on the same line as the provider parameter. Consider moving the closing parenthesis to a new line for consistency with the Delete operation formatting on lines 36-37.
| provider: [self::class, 'provide'], ), | |
| new Post( | |
| uriTemplate: '/dummy_get_post_delete_operations', | |
| provider: [self::class, 'provide'], ), | |
| provider: [self::class, 'provide'], | |
| ), | |
| new Post( | |
| uriTemplate: '/dummy_get_post_delete_operations', | |
| provider: [self::class, 'provide'], | |
| ), |
| $this->decorated->method('process')->willReturn(new Response()); | ||
| } | ||
|
|
||
| public function testHeadersAcceptPostIsReturnWhenPostAllowed(): void |
There was a problem hiding this comment.
The test method name has a grammatical error. 'IsReturn' should be 'IsReturned'. Consider renaming to 'testHeadersAcceptPostIsReturnedWhenPostAllowed' for grammatical correctness.
| public function testHeadersAcceptPostIsReturnWhenPostAllowed(): void | |
| public function testHeadersAcceptPostIsReturnedWhenPostAllowed(): void |
| $this->assertStringContainsString('POST', $allowHeader); | ||
| $operation = new Get('/dummy/{dummyResourceId}{._format}', class: Dummy::class); | ||
|
|
||
| /** @var Response $response */ |
There was a problem hiding this comment.
The PHPDoc comment on line 120 incorrectly documents $processor as a Response when it should document the variable on line 127. This comment appears to be misplaced and should either be removed or moved to line 126.
| /** @var Response $response */ |
Pull Request Test Coverage Report for Build 20941246093Details
💛 - Coveralls |
# This is the 1st commit message: feat(state): added "Accept-Post" and "Allow" headers To ensure compliance with the LDP specification (https://www.w3.org/TR/ldp/): Added the "Accept-Post" header containing the list of supported Post formats. Added the "Allow" header with values based on the allowed operations on the queried resources. # Conflicts: # src/Symfony/Bundle/Resources/config/state/processor.xml # src/Symfony/Bundle/Resources/config/symfony/events.xml # The commit message #2 will be skipped: # WIP
78f162b to
7770f8a
Compare
feat(state): added "Accept-Post" and "Allow" headers
To ensure compliance with the LDP specification (https://www.w3.org/TR/ldp/): Added the "Accept-Post" header containing the list of supported Post formats.
Added the "Allow" header with values based on the allowed operations on the queried resources.