Skip to content

Commit

Permalink
fix(state): handle empty request in read provider (#6403)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-sainthillier committed Jun 3, 2024
1 parent 0775bb7 commit 99314bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/State/Provider/ReadProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
return null;
}

if (null === $filters = $request?->attributes->get('_api_filters')) {
if (null === ($filters = $request?->attributes->get('_api_filters')) && $request) {
$queryString = RequestParser::getQueryString($request);
$filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
}
Expand Down
34 changes: 34 additions & 0 deletions src/State/Tests/ReadProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\State\Tests;

use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Serializer\SerializerContextBuilderInterface;
use ApiPlatform\State\Provider\ReadProvider;
use ApiPlatform\State\ProviderInterface;
use PHPUnit\Framework\TestCase;

class ReadProviderTest extends TestCase
{
public function testWithoutRequest(): void
{
$operation = new GetCollection(read: true);
$provider = $this->createMock(ProviderInterface::class);
$provider->method('provide')->willReturn(['ok']);
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);

$readProvider = new ReadProvider($provider, $serializerContextBuilder);
$this->assertEquals($readProvider->provide($operation), ['ok']);
}
}

0 comments on commit 99314bf

Please sign in to comment.