|
16 | 16 | use ApiPlatform\Core\EventListener\AddFormatListener;
|
17 | 17 | use Negotiation\Negotiator;
|
18 | 18 | use PHPUnit\Framework\TestCase;
|
| 19 | +use Prophecy\Argument; |
| 20 | +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
19 | 21 | use Symfony\Component\HttpFoundation\Request;
|
20 | 22 | use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
21 | 23 |
|
|
24 | 26 | */
|
25 | 27 | class AddFormatListenerTest extends TestCase
|
26 | 28 | {
|
27 |
| - public function testNoResourceClass() |
| 29 | + public function testRequestFormatShouldNotBeSet() |
28 | 30 | {
|
29 |
| - $request = new Request(); |
30 |
| - |
| 31 | + $requestProphecy = $this->prophesize(Request::class); |
| 32 | + $parameterBagProphecy = $this->prophesize(ParameterBagInterface::class); |
| 33 | + $requestProphecy->attributes = $parameterBagProphecy; |
31 | 34 | $eventProphecy = $this->prophesize(GetResponseEvent::class);
|
32 |
| - $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); |
33 |
| - $event = $eventProphecy->reveal(); |
| 35 | + $eventProphecy->getRequest()->willReturn($requestProphecy)->shouldBeCalled(); |
| 36 | + $parameterBagProphecy->has(Argument::type('string'))->willReturn(false)->shouldBeCalled(); |
| 37 | + $requestProphecy->setFormat('jsonld', 'application/ld+json')->shouldNotBeCalled(); |
34 | 38 |
|
35 | 39 | $listener = new AddFormatListener(new Negotiator(), ['jsonld' => 'application/ld+json']);
|
36 |
| - $listener->onKernelRequest($event); |
37 |
| - |
38 |
| - $this->assertNull($request->getFormat('application/ld+json')); |
| 40 | + $listener->onKernelRequest($eventProphecy->reveal()); |
39 | 41 | }
|
40 | 42 |
|
41 | 43 | public function testSupportedRequestFormat()
|
|
0 commit comments