/** * 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 \TYPO3\FLOW3\Mvc\Exception\InvalidArgumentTypeException */ protected function initializeCommandMethodArguments() { $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 \TYPO3\FLOW3\Mvc\Exception\InvalidArgumentTypeException('The argument type for parameter $' . $parameterName . ' of method ' . get_class($this) . '->' . $this->commandMethodName . '() could not be detected.', 1306755296); } $defaultValue = isset($parameterInfo['defaultValue']) ? $parameterInfo['defaultValue'] : NULL; $this->arguments->addNewArgument($parameterName, $dataType, $parameterInfo['optional'] === FALSE, $defaultValue); } }
/** * @test * @expectedException TYPO3\FLOW3\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\\FLOW3\\Mvc\\Controller\\AbstractController', array('processRequest')); $this->inject($controller, 'flashMessageContainer', new FlashMessageContainer()); $controller->_call('initializeController', $request, $response); $controller->_set('arguments', $controllerArguments); $controller->_call('mapRequestArgumentsToControllerArguments'); }
/** * @test */ public function addingAnArgumentUsesStringAsDataTypeDefault() { $arguments = new Arguments(); $argument = $arguments->addNewArgument('someArgumentName'); $this->assertEquals('string', $argument->getDataType()); }