예제 #1
0
	/**
	 * @test
	 * @author Bastian Waidelich <*****@*****.**>
	 */
	public function getArgumentDefinitionsReturnsArrayOfArgumentDefinitionIfCommandExpectsArguments() {
		$mockParameterReflection = $this->getMock(\TYPO3\CMS\Extbase\Reflection\ParameterReflection::class, array(), array(), '', FALSE);
		$mockReflectionService = $this->getMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
		$mockMethodParameters = array('argument1' => array('optional' => FALSE), 'argument2' => array('optional' => TRUE));
		$mockReflectionService->expects($this->atLeastOnce())->method('getMethodParameters')->will($this->returnValue($mockMethodParameters));
		$this->command->_set('reflectionService', $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'))));
		$mockCommandArgumentDefinition1 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, array(), array(), '', FALSE);
		$mockCommandArgumentDefinition2 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, array(), array(), '', FALSE);
		$this->mockObjectManager->expects($this->at(0))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, 'argument1', TRUE, 'argument1 description')->will($this->returnValue($mockCommandArgumentDefinition1));
		$this->mockObjectManager->expects($this->at(1))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, 'argument2', FALSE, 'argument2 description')->will($this->returnValue($mockCommandArgumentDefinition2));
		$expectedResult = array($mockCommandArgumentDefinition1, $mockCommandArgumentDefinition2);
		$actualResult = $this->command->getArgumentDefinitions();
		$this->assertSame($expectedResult, $actualResult);
	}
예제 #2
0
 /**
  * @param ControllerInterface $controller
  * @param string $methodName
  * @return ParameterReflection[]
  */
 protected function getExpectedArgumentsForMethod(ControllerInterface $controller, $methodName)
 {
     $reflection = new MethodReflection($controller, $methodName);
     return $reflection->getParameters();
 }
예제 #3
0
 /**
  * Converts the given parameter reflection into an information array
  *
  * @param ParameterReflection $parameter The parameter to reflect
  * @param int $parameterPosition
  * @param MethodReflection|NULL $method
  * @return array Parameter information array
  */
 protected function convertParameterReflectionToArray(ParameterReflection $parameter, $parameterPosition, MethodReflection $method = null)
 {
     $parameterInformation = ['position' => $parameterPosition, 'byReference' => $parameter->isPassedByReference(), 'array' => $parameter->isArray(), 'optional' => $parameter->isOptional(), 'allowsNull' => $parameter->allowsNull()];
     $parameterClass = $parameter->getClass();
     $parameterInformation['class'] = $parameterClass !== null ? $parameterClass->getName() : null;
     if ($parameter->isDefaultValueAvailable()) {
         $parameterInformation['defaultValue'] = $parameter->getDefaultValue();
     }
     if ($parameterClass !== null) {
         $parameterInformation['type'] = $parameterClass->getName();
     } elseif ($method !== null) {
         $methodTagsAndValues = $this->getMethodTagsValues($method->getDeclaringClass()->getName(), $method->getName());
         if (isset($methodTagsAndValues['param']) && isset($methodTagsAndValues['param'][$parameterPosition])) {
             $explodedParameters = explode(' ', $methodTagsAndValues['param'][$parameterPosition]);
             if (count($explodedParameters) >= 2) {
                 if (TypeHandlingUtility::isSimpleType($explodedParameters[0])) {
                     // ensure that short names of simple types are resolved correctly to the long form
                     // this is important for all kinds of type checks later on
                     $typeInfo = TypeHandlingUtility::parseType($explodedParameters[0]);
                     $parameterInformation['type'] = $typeInfo['type'];
                 } else {
                     $parameterInformation['type'] = $explodedParameters[0];
                 }
             }
         }
     }
     if (isset($parameterInformation['type']) && $parameterInformation['type'][0] === '\\') {
         $parameterInformation['type'] = substr($parameterInformation['type'], 1);
     }
     return $parameterInformation;
 }
예제 #4
0
 /**
  * Converts the given parameter reflection into an information array
  *
  * @param ParameterReflection $parameter The parameter to reflect
  * @param integer $parameterPosition
  * @param MethodReflection|NULL $method
  * @return array Parameter information array
  */
 protected function convertParameterReflectionToArray(ParameterReflection $parameter, $parameterPosition, MethodReflection $method = NULL)
 {
     $parameterInformation = array('position' => $parameterPosition, 'byReference' => $parameter->isPassedByReference(), 'array' => $parameter->isArray(), 'optional' => $parameter->isOptional(), 'allowsNull' => $parameter->allowsNull());
     $parameterClass = $parameter->getClass();
     $parameterInformation['class'] = $parameterClass !== NULL ? $parameterClass->getName() : NULL;
     if ($parameter->isDefaultValueAvailable()) {
         $parameterInformation['defaultValue'] = $parameter->getDefaultValue();
     }
     if ($parameterClass !== NULL) {
         $parameterInformation['type'] = $parameterClass->getName();
     } elseif ($method !== NULL) {
         $methodTagsAndValues = $this->getMethodTagsValues($method->getDeclaringClass()->getName(), $method->getName());
         if (isset($methodTagsAndValues['param']) && isset($methodTagsAndValues['param'][$parameterPosition])) {
             $explodedParameters = explode(' ', $methodTagsAndValues['param'][$parameterPosition]);
             if (count($explodedParameters) >= 2) {
                 $parameterInformation['type'] = $explodedParameters[0];
             }
         }
     }
     if (isset($parameterInformation['type']) && $parameterInformation['type'][0] === '\\') {
         $parameterInformation['type'] = substr($parameterInformation['type'], 1);
     }
     return $parameterInformation;
 }
예제 #5
0
 /**
  * Get the tag configuration from this method and respect multiple line and space configuration
  *
  * @param MethodReflection|ClassReflection $reflectionObject
  * @param array                            $tagNames
  *
  * @return array
  */
 public static function getTagConfiguration($reflectionObject, array $tagNames)
 {
     $tags = $reflectionObject->getTagsValues();
     $configuration = [];
     foreach ($tagNames as $tagName) {
         $configuration[$tagName] = [];
         if (!is_array($tags[$tagName])) {
             continue;
         }
         foreach ($tags[$tagName] as $c) {
             $configuration[$tagName] = array_merge($configuration[$tagName], GeneralUtility::trimExplode(' ', $c, true));
         }
     }
     return $configuration;
 }