Skip to content

Commit 99314bf

Browse files
fix(state): handle empty request in read provider (#6403)
1 parent 0775bb7 commit 99314bf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/State/Provider/ReadProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5454
return null;
5555
}
5656

57-
if (null === $filters = $request?->attributes->get('_api_filters')) {
57+
if (null === ($filters = $request?->attributes->get('_api_filters')) && $request) {
5858
$queryString = RequestParser::getQueryString($request);
5959
$filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
6060
}

src/State/Tests/ReadProviderTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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;
15+
16+
use ApiPlatform\Metadata\GetCollection;
17+
use ApiPlatform\Serializer\SerializerContextBuilderInterface;
18+
use ApiPlatform\State\Provider\ReadProvider;
19+
use ApiPlatform\State\ProviderInterface;
20+
use PHPUnit\Framework\TestCase;
21+
22+
class ReadProviderTest extends TestCase
23+
{
24+
public function testWithoutRequest(): void
25+
{
26+
$operation = new GetCollection(read: true);
27+
$provider = $this->createMock(ProviderInterface::class);
28+
$provider->method('provide')->willReturn(['ok']);
29+
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
30+
31+
$readProvider = new ReadProvider($provider, $serializerContextBuilder);
32+
$this->assertEquals($readProvider->provide($operation), ['ok']);
33+
}
34+
}

0 commit comments

Comments
 (0)