|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 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\Provider; |
| 15 | + |
| 16 | +use ApiPlatform\Metadata\Get; |
| 17 | +use ApiPlatform\Serializer\SerializerContextBuilderInterface; |
| 18 | +use ApiPlatform\State\Provider\ReadProvider; |
| 19 | +use ApiPlatform\State\ProviderInterface; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | +use Symfony\Component\HttpFoundation\Request; |
| 22 | + |
| 23 | +class ReadProviderTest extends TestCase |
| 24 | +{ |
| 25 | + public function testSetsSerializerContext(): void |
| 26 | + { |
| 27 | + $data = new \stdClass(); |
| 28 | + $operation = new Get(read: true); |
| 29 | + $decorated = $this->createStub(ProviderInterface::class); |
| 30 | + $decorated->method('provide')->willReturn($data); |
| 31 | + $serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class); |
| 32 | + $serializerContextBuilder->expects($this->once())->method('createFromRequest')->willReturn(['a']); |
| 33 | + $provider = new ReadProvider($decorated, $serializerContextBuilder); |
| 34 | + $request = new Request(); |
| 35 | + $provider->provide($operation, ['id' => 1], ['request' => $request]); |
| 36 | + $this->assertEquals(['a'], $request->attributes->get('_api_normalization_context')); |
| 37 | + } |
| 38 | +} |
0 commit comments