Skip to content

Fix unit tests #1631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions tests/EventListener/AddFormatListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,18 +26,18 @@
*/
class AddFormatListenerTest extends TestCase
{
public function testNoResourceClass()
public function testRequestFormatShouldNotBeSet()
{
$request = new Request();

$requestProphecy = $this->prophesize(Request::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects (without related interfaces) from external libraries should not be mocked, especially when its a value object like this one.

$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()
Expand Down