Skip to content

Commit cd4f3f5

Browse files
Fix unit tests
1 parent 8c24b71 commit cd4f3f5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tests/EventListener/AddFormatListenerTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use ApiPlatform\Core\EventListener\AddFormatListener;
1717
use Negotiation\Negotiator;
1818
use PHPUnit\Framework\TestCase;
19+
use Prophecy\Argument;
20+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
1921
use Symfony\Component\HttpFoundation\Request;
2022
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
2123

@@ -24,18 +26,18 @@
2426
*/
2527
class AddFormatListenerTest extends TestCase
2628
{
27-
public function testNoResourceClass()
29+
public function testRequestFormatShouldNotBeSet()
2830
{
29-
$request = new Request();
30-
31+
$requestProphecy = $this->prophesize(Request::class);
32+
$parameterBagProphecy = $this->prophesize(ParameterBagInterface::class);
33+
$requestProphecy->attributes = $parameterBagProphecy;
3134
$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();
3438

3539
$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());
3941
}
4042

4143
public function testSupportedRequestFormat()

0 commit comments

Comments
 (0)