addNewArgument() public method

If an argument with the same name exists already, it will be replaced by the new argument object.
public addNewArgument ( string $name, string $dataType = 'string', boolean $isRequired = true, mixed $defaultValue = null ) : Argument
$name string Name of the argument
$dataType string Name of one of the built-in data types
$isRequired boolean TRUE if this argument should be marked as required
$defaultValue mixed Default value of the argument. Only makes sense if $isRequired==FALSE
return Argument The new argument
 /**
  * @test
  */
 public function processRequestResetsCommandMethodArguments()
 {
     $mockRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
     $mockResponse = $this->getMockBuilder(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->commandManager->getCommandMethodParameters(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);
     }
 }
 /**
  * Helper which initializes the property mapping configuration and returns arguments
  *
  * @param array $trustedProperties
  * @return Mvc\Controller\Arguments
  */
 protected function initializePropertyMappingConfiguration(array $trustedProperties)
 {
     $request = $this->getMockBuilder(Mvc\ActionRequest::class)->setMethods(['getInternalArgument'])->disableOriginalConstructor()->getMock();
     $request->expects($this->any())->method('getInternalArgument')->with('__trustedProperties')->will($this->returnValue('fooTrustedProperties'));
     $arguments = new Mvc\Controller\Arguments();
     $mockHashService = $this->getMockBuilder(HashService::class)->setMethods(['validateAndStripHmac'])->getMock();
     $mockHashService->expects($this->once())->method('validateAndStripHmac')->with('fooTrustedProperties')->will($this->returnValue(serialize($trustedProperties)));
     $arguments->addNewArgument('foo', 'something');
     $this->inject($arguments->getArgument('foo'), 'propertyMappingConfiguration', new PropertyMappingConfiguration());
     $requestHashService = new Mvc\Controller\MvcPropertyMappingConfigurationService();
     $this->inject($requestHashService, 'hashService', $mockHashService);
     $requestHashService->initializePropertyMappingConfigurationFromRequest($request, $arguments);
     return $arguments;
 }
 /**
  * @test
  * @expectedException \Neos\Flow\Mvc\Exception\RequiredArgumentMissingException
  */
 public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet()
 {
     $mockPropertyMapper = $this->getMockBuilder(PropertyMapper::class)->disableOriginalConstructor()->setMethods(['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(AbstractController::class, ['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());
 }