ApiPlatform\Core\Tests\Doctrine\WriteListenerTest::testOnKernelViewWithControllerResultAndDeleteMethod PHP Method

testOnKernelViewWithControllerResultAndDeleteMethod() public method

    public function testOnKernelViewWithControllerResultAndDeleteMethod()
    {
        $dummy = new Dummy();
        $dummy->setName('Dummyrino');
        $objectManagerProphecy = $this->prophesize(ObjectManager::class);
        $objectManagerProphecy->remove($dummy)->shouldBeCalled();
        $objectManagerProphecy->flush()->shouldBeCalled();
        $managerRegistryProphecy = $this->prophesize(ManagerRegistry::class);
        $managerRegistryProphecy->getManagerForClass('Dummy')->willReturn($objectManagerProphecy->reveal());
        $writeListener = new WriteListener($managerRegistryProphecy->reveal());
        $request = new Request();
        $request->setMethod(Request::METHOD_DELETE);
        $request->attributes->set('_api_resource_class', 'Dummy');
        $event = $this->prophesize(GetResponseForControllerResultEvent::class);
        $event->setControllerResult(null)->shouldBeCalled();
        $event->getRequest()->willReturn($request);
        $event->getControllerResult()->willReturn($dummy);
        $this->assertNull($writeListener->onKernelView($event->reveal()));
        $this->assertNotEquals($dummy, $writeListener->onKernelView($event->reveal()));
    }