getContainer(); $req = $this->createMock(Request::class); $req->$type = new ParameterBag([ 'clientId' => 'clientId', $dataKey => $data ]); $req->expects($this->any()) ->method('isMethod') ->with('post') ->willReturn($type == 'request'); $reqStack = $this->createMock(RequestStack::class); $reqStack->expects($this->any()) ->method('getCurrentRequest') ->willReturn($req); $res = $this->getExchangeControllerMock($reqStack)->{$method.'Action'}($req); $content = json_decode($res->getContent(), true); $assertions($res, $content); } /** * @return \PHPUnit\Framework\MockObject\MockObject */ protected function getExchangeControllerMock($reqStack) { $container = self::$kernel->getContainer(); $serviceMock = $this->getServiceMock(); $exchangeControllerClassName = $this->getExchangeControllerClassName(); $exchangeControllerMock = $this->getMockBuilder($exchangeControllerClassName) ->setMethods(['getDeliveryApi']) ->setConstructorArgs([ $container->get('doctrine.orm.entity_manager'), $container->get('jms_serializer'), $reqStack, ]) ->getMock(); $exchangeControllerMock->expects($this->any()) ->method('getDeliveryApi') ->willReturn($serviceMock); $exchangeControllerMock->setContainer($container); return $exchangeControllerMock; } }