From cd4f3f5babea6ad1c4c0ac5ad4ac25354858baf3 Mon Sep 17 00:00:00 2001 From: Vincent CHALAMON Date: Mon, 8 Jan 2018 17:03:53 +0100 Subject: [PATCH] Fix unit tests --- tests/EventListener/AddFormatListenerTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/EventListener/AddFormatListenerTest.php b/tests/EventListener/AddFormatListenerTest.php index e4dca204c2e..135b30c3eb6 100644 --- a/tests/EventListener/AddFormatListenerTest.php +++ b/tests/EventListener/AddFormatListenerTest.php @@ -16,6 +16,8 @@ use ApiPlatform\Core\EventListener\AddFormatListener; use Negotiation\Negotiator; use PHPUnit\Framework\TestCase; +use Prophecy\Argument; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\GetResponseEvent; @@ -24,18 +26,18 @@ */ class AddFormatListenerTest extends TestCase { - public function testNoResourceClass() + public function testRequestFormatShouldNotBeSet() { - $request = new Request(); - + $requestProphecy = $this->prophesize(Request::class); + $parameterBagProphecy = $this->prophesize(ParameterBagInterface::class); + $requestProphecy->attributes = $parameterBagProphecy; $eventProphecy = $this->prophesize(GetResponseEvent::class); - $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); - $event = $eventProphecy->reveal(); + $eventProphecy->getRequest()->willReturn($requestProphecy)->shouldBeCalled(); + $parameterBagProphecy->has(Argument::type('string'))->willReturn(false)->shouldBeCalled(); + $requestProphecy->setFormat('jsonld', 'application/ld+json')->shouldNotBeCalled(); $listener = new AddFormatListener(new Negotiator(), ['jsonld' => 'application/ld+json']); - $listener->onKernelRequest($event); - - $this->assertNull($request->getFormat('application/ld+json')); + $listener->onKernelRequest($eventProphecy->reveal()); } public function testSupportedRequestFormat()