Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c50d4c

Browse files
authored
fix(state): add link header processor without links (#5888)
fixes #5886
1 parent 045488d commit 0c50d4c

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/State/Processor/AddLinkHeaderProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
3737

3838
// We add our header here as Symfony does it only for the main Request and we want it to be done on errors (sub-request) as well
3939
$linksProvider = $request->attributes->get('_api_platform_links');
40-
if ($this->serializer && ($links = $linksProvider->getLinks())) {
40+
if ($this->serializer && ($links = $linksProvider?->getLinks())) {
4141
$response->headers->set('Link', $this->serializer->serialize($links));
4242
}
4343

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\State\Tests\Processor;
15+
16+
use ApiPlatform\Metadata\Get;
17+
use ApiPlatform\State\Processor\AddLinkHeaderProcessor;
18+
use ApiPlatform\State\ProcessorInterface;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class AddLinkHeaderProcessorTest extends TestCase
22+
{
23+
public function testWithoutLinks(): void
24+
{
25+
$data = new \stdClass();
26+
$operation = new Get();
27+
$decorated = $this->createStub(ProcessorInterface::class);
28+
$decorated->method('process')->willReturn($data);
29+
$processor = new AddLinkHeaderProcessor($decorated);
30+
$this->assertEquals($data, $processor->process($data, $operation));
31+
}
32+
}

0 commit comments

Comments
 (0)