Skip to content

Commit

Permalink
fix(state): read without output
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed May 3, 2024
1 parent 735e150 commit 8a7bd0b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/State/Provider/ReadProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
return null;
}

$output = $operation->getOutput() ?? [];
if (\array_key_exists('class', $output) && null === $output['class']) {
$request?->attributes->set('data', null);

return null;
}

if (null === $filters = $request?->attributes->get('_api_filters')) {
$queryString = RequestParser::getQueryString($request);
$filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
Expand Down
14 changes: 14 additions & 0 deletions src/State/Tests/Provider/ReadProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ public function testSetsSerializerContext(): void
$provider->provide($operation, ['id' => 1], ['request' => $request]);
$this->assertEquals(['a'], $request->attributes->get('_api_normalization_context'));
}

public function testShouldReadWithOutputFalse(): void
{
$data = new \stdClass();
$operation = new Get(read: true, output: false);
$decorated = $this->createStub(ProviderInterface::class);
$decorated->method('provide')->willReturn($data);
$serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class);
$serializerContextBuilder->expects($this->once())->method('createFromRequest')->willReturn(['a']);
$provider = new ReadProvider($decorated, $serializerContextBuilder);
$request = new Request();
$provider->provide($operation, ['id' => 1], ['request' => $request]);
$this->assertEquals($data, $request->attributes->get('data'));
}
}
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/ApiResource/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
headers: ['Location' => '/foobar', 'Hello' => 'World'],
status: 301,
output: false,
read: false,
operations: [
new Get(uriTemplate: 'redirect_to_foobar'),
],
Expand Down

0 comments on commit 8a7bd0b

Please sign in to comment.