/** * @test */ public function processRequestResetsCommandMethodArguments() { $mockRequest = $this->getMockBuilder(\TYPO3\Flow\Cli\Request::class)->disableOriginalConstructor()->getMock(); $mockResponse = $this->getMockBuilder(\TYPO3\Flow\Mvc\ResponseInterface::class)->getMock(); $mockArguments = new Arguments(); $mockArguments->addNewArgument('foo'); $this->inject($this->commandController, 'arguments', $mockArguments); $this->assertCount(1, $this->commandController->_get('arguments')); $this->commandController->processRequest($mockRequest, $mockResponse); $this->assertCount(0, $this->commandController->_get('arguments')); }
/** * Initializes the arguments array of this controller by creating an empty argument object for each of the * method arguments found in the designated command method. * * @return void * @throws InvalidArgumentTypeException */ protected function initializeCommandMethodArguments() { $this->arguments->removeAll(); $methodParameters = $this->reflectionService->getMethodParameters(get_class($this), $this->commandMethodName); foreach ($methodParameters as $parameterName => $parameterInfo) { $dataType = null; if (isset($parameterInfo['type'])) { $dataType = $parameterInfo['type']; } elseif ($parameterInfo['array']) { $dataType = 'array'; } if ($dataType === null) { throw new InvalidArgumentTypeException(sprintf('The argument type for parameter $%s of method %s->%s() could not be detected.', $parameterName, get_class($this), $this->commandMethodName), 1306755296); } $defaultValue = isset($parameterInfo['defaultValue']) ? $parameterInfo['defaultValue'] : null; $this->arguments->addNewArgument($parameterName, $dataType, $parameterInfo['optional'] === false, $defaultValue); } }
/** * @test * @expectedException \TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException */ public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet() { $mockPropertyMapper = $this->getMockBuilder(\TYPO3\Flow\Property\PropertyMapper::class)->disableOriginalConstructor()->setMethods(array('convert'))->getMock(); $mockPropertyMapper->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0)); $controllerArguments = new Arguments(); $controllerArguments->addNewArgument('foo', 'string', true); $controllerArguments->addNewArgument('baz', 'string', true); foreach ($controllerArguments as $controllerArgument) { $this->inject($controllerArgument, 'propertyMapper', $mockPropertyMapper); } $controller = $this->getAccessibleMock(\TYPO3\Flow\Mvc\Controller\AbstractController::class, array('processRequest')); $controller->_call('initializeController', $this->mockActionRequest, $this->mockHttpResponse); $controller->_set('arguments', $controllerArguments); $this->mockActionRequest->expects($this->at(0))->method('hasArgument')->with('foo')->will($this->returnValue(true)); $this->mockActionRequest->expects($this->at(1))->method('getArgument')->with('foo')->will($this->returnValue('bar')); $this->mockActionRequest->expects($this->at(2))->method('hasArgument')->with('baz')->will($this->returnValue(false)); $controller->_call('mapRequestArgumentsToControllerArguments'); }
/** * @test */ public function addingAnArgumentUsesStringAsDataTypeDefault() { $arguments = new Arguments(); $argument = $arguments->addNewArgument('someArgumentName'); $this->assertEquals('string', $argument->getDataType()); }
/** * @test * @expectedException TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException */ public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet() { $httpRequest = HttpRequest::create(new Uri('http://localhost/')); $request = $httpRequest->createActionRequest(); $response = new HttpResponse(); $controllerArguments = new Arguments(); $controllerArguments->addNewArgument('foo', 'string', TRUE); $controller = $this->getAccessibleMock('TYPO3\\Flow\\Mvc\\Controller\\AbstractController', array('processRequest')); $this->inject($controller, 'flashMessageContainer', new FlashMessageContainer()); $controller->_call('initializeController', $request, $response); $controller->_set('arguments', $controllerArguments); $controller->_call('mapRequestArgumentsToControllerArguments'); }
/** * @test * @expectedException \TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException */ public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet() { $mockPropertyMapper = $this->getMock('TYPO3\\Flow\\Property\\PropertyMapper', array('convert'), array(), '', FALSE); $mockPropertyMapper->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0)); $controllerArguments = new Arguments(); $controllerArguments->addNewArgument('foo', 'string', TRUE); $controllerArguments->addNewArgument('baz', 'string', TRUE); foreach ($controllerArguments as $controllerArgument) { $this->inject($controllerArgument, 'propertyMapper', $mockPropertyMapper); } $controller = $this->getAccessibleMock('TYPO3\\Flow\\Mvc\\Controller\\AbstractController', array('processRequest')); $controller->_call('initializeController', $this->mockActionRequest, $this->mockHttpResponse); $controller->_set('arguments', $controllerArguments); $this->mockActionRequest->expects($this->at(0))->method('hasArgument')->with('foo')->will($this->returnValue(TRUE)); $this->mockActionRequest->expects($this->at(1))->method('getArgument')->with('foo')->will($this->returnValue('bar')); $this->mockActionRequest->expects($this->at(2))->method('hasArgument')->with('baz')->will($this->returnValue(FALSE)); $controller->_call('mapRequestArgumentsToControllerArguments'); }