Esempio n. 1
0
 /**
  * @test
  */
 public function getArgumentDefinitionsReturnsArrayOfArgumentDefinitionIfCommandExpectsArguments()
 {
     $mockParameterReflection = $this->getMock('TYPO3\\FLOW3\\Reflection\\ParameterReflection', array(), array(), '', FALSE);
     $mockReflectionService = $this->getMock('TYPO3\\FLOW3\\Reflection\\ReflectionService');
     $mockMethodParameters = array('argument1' => array('optional' => FALSE), 'argument2' => array('optional' => TRUE));
     $mockReflectionService->expects($this->atLeastOnce())->method('getMethodParameters')->will($this->returnValue($mockMethodParameters));
     $this->command->injectReflectionService($mockReflectionService);
     $this->mockMethodReflection->expects($this->atLeastOnce())->method('getParameters')->will($this->returnValue(array($mockParameterReflection)));
     $this->mockMethodReflection->expects($this->atLeastOnce())->method('getTagsValues')->will($this->returnValue(array('param' => array('@param $argument1 argument1 description', '@param $argument2 argument2 description'))));
     $expectedResult = array(new \TYPO3\FLOW3\Cli\CommandArgumentDefinition('argument1', TRUE, 'argument1 description'), new \TYPO3\FLOW3\Cli\CommandArgumentDefinition('argument2', FALSE, 'argument2 description'));
     $actualResult = $this->command->getArgumentDefinitions();
     $this->assertEquals($expectedResult, $actualResult);
 }
Esempio n. 2
0
 /**
  * Converts the given parameter reflection into an information array
  *
  * @param \TYPO3\FLOW3\Reflection\ParameterReflection $parameter The parameter to reflect
  * @param \TYPO3\FLOW3\Reflection\MethodReflection $method The parameter's method
  * @return array Parameter information array
  */
 protected function convertParameterReflectionToArray(\TYPO3\FLOW3\Reflection\ParameterReflection $parameter, \TYPO3\FLOW3\Reflection\MethodReflection $method = NULL)
 {
     $parameterInformation = array(self::DATA_PARAMETER_POSITION => $parameter->getPosition());
     if ($parameter->isPassedByReference()) {
         $parameterInformation[self::DATA_PARAMETER_BY_REFERENCE] = TRUE;
     }
     if ($parameter->isArray()) {
         $parameterInformation[self::DATA_PARAMETER_ARRAY] = TRUE;
     }
     if ($parameter->isOptional()) {
         $parameterInformation[self::DATA_PARAMETER_OPTIONAL] = TRUE;
     }
     if ($parameter->allowsNull()) {
         $parameterInformation[self::DATA_PARAMETER_ALLOWS_NULL] = TRUE;
     }
     $parameterClass = $parameter->getClass();
     if ($parameterClass !== NULL) {
         $parameterInformation[self::DATA_PARAMETER_CLASS] = $parameterClass->getName();
     }
     if ($parameter->isOptional() && $parameter->isDefaultValueAvailable()) {
         $parameterInformation[self::DATA_PARAMETER_DEFAULT_VALUE] = $parameter->getDefaultValue();
     }
     if ($method !== NULL) {
         $paramAnnotations = $method->isTaggedWith('param') ? $method->getTagValues('param') : array();
         if (isset($paramAnnotations[$parameter->getPosition()])) {
             $explodedParameters = explode(' ', $paramAnnotations[$parameter->getPosition()]);
             if (count($explodedParameters) >= 2) {
                 $parameterInformation[self::DATA_PARAMETER_TYPE] = ltrim($explodedParameters[0], '\\');
             }
         }
     }
     if (!isset($parameterInformation[self::DATA_PARAMETER_TYPE]) && $parameterClass !== NULL) {
         $parameterInformation[self::DATA_PARAMETER_TYPE] = ltrim($parameterClass->getName(), '\\');
     } elseif (!isset($parameterInformation[self::DATA_PARAMETER_TYPE])) {
         $parameterInformation[self::DATA_PARAMETER_TYPE] = 'mixed';
     }
     return $parameterInformation;
 }