Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
}
}