/**
  * Creates a Descriptor from a provided class.
  *
  * @return void
  */
 public function testCreateArgumentDescriptorFromReflector()
 {
     $name = 'goodArgument';
     $type = 'boolean';
     $argumentReflectorMock = m::mock('phpDocumentor\\Reflection\\FunctionReflector\\ArgumentReflector');
     $argumentReflectorMock->shouldReceive('getName')->andReturn($name);
     $argumentReflectorMock->shouldReceive('getType')->andReturn($type);
     $argumentReflectorMock->shouldReceive('getDefault')->andReturn(false);
     // Turns out its a bad argument ;)
     $descriptor = $this->fixture->create($argumentReflectorMock);
     $this->assertSame($name, $descriptor->getName());
     $this->assertSame(array($type), $descriptor->getTypes());
     $this->assertSame(false, $descriptor->getDefault());
 }
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param FunctionReflector $data
  *
  * @return FunctionDescriptor
  */
 public function create($data)
 {
     $functionDescriptor = new FunctionDescriptor();
     $functionDescriptor->setFullyQualifiedStructuralElementName($data->getName() . '()');
     $functionDescriptor->setName($data->getShortName());
     $functionDescriptor->setLine($data->getLinenumber());
     // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself
     $functionDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace()));
     $this->assembleDocBlock($data->getDocBlock(), $functionDescriptor);
     foreach ($data->getArguments() as $argument) {
         $argumentAssembler = new ArgumentAssembler();
         $argumentDescriptor = $argumentAssembler->create($argument, $functionDescriptor->getTags()->get('param', array()));
         $functionDescriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor);
     }
     return $functionDescriptor;
 }
 /**
  * Prepares a mock Argument with the given name.
  *
  * @param string $argumentName
  *
  * @return ArgumentDescriptor|m\MockInterface
  */
 protected function givenAnArgumentWithName($argumentName)
 {
     $argumentMock = m::mock('phpDocumentor\\Descriptor\\ArgumentDescriptor');
     $argumentMock->shouldReceive('getName')->andReturn($argumentName);
     $this->argumentAssemblerMock->shouldReceive('create')->andReturn($argumentMock);
     return $argumentMock;
 }
Ejemplo n.º 4
0
 /**
  * Creates a new ArgumentDescriptor from the given Reflector and Param.
  *
  * @param FunctionDescriptor                  $functionDescriptor
  * @param FunctionReflector\ArgumentReflector $argument
  *
  * @return ArgumentDescriptor
  */
 protected function createArgumentDescriptor($functionDescriptor, $argument)
 {
     $params = $functionDescriptor->getTags()->get('param', array());
     if (!$this->argumentAssembler->getBuilder()) {
         $this->argumentAssembler->setBuilder($this->builder);
     }
     return $this->argumentAssembler->create($argument, $params);
 }
Ejemplo n.º 5
0
 /**
  * Adds a single reflected Argument to the Method Descriptor.
  *
  * @param ArgumentReflector $argument
  * @param MethodDescriptor  $descriptor
  *
  * @return void
  */
 protected function addArgument($argument, $descriptor)
 {
     $params = $descriptor->getTags()->get('param', array());
     if (!$this->argumentAssembler->getBuilder()) {
         $this->argumentAssembler->setBuilder($this->builder);
     }
     $argumentDescriptor = $this->argumentAssembler->create($argument, $params);
     $descriptor->addArgument($argumentDescriptor->getName(), $argumentDescriptor);
 }
Ejemplo n.º 6
0
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param MethodReflector $data
  *
  * @return MethodDescriptor
  */
 public function create($data)
 {
     $methodDescriptor = new MethodDescriptor();
     $methodDescriptor->setFullyQualifiedStructuralElementName($data->getName() . '()');
     $methodDescriptor->setName($data->getShortName());
     $methodDescriptor->setVisibility($data->getVisibility() ?: 'public');
     $methodDescriptor->setFinal($data->isFinal());
     $methodDescriptor->setAbstract($data->isAbstract());
     $methodDescriptor->setStatic($data->isStatic());
     $this->assembleDocBlock($data->getDocBlock(), $methodDescriptor);
     foreach ($data->getArguments() as $argument) {
         $argumentAssembler = new ArgumentAssembler();
         $argumentDescriptor = $argumentAssembler->create($argument, $methodDescriptor->getTags()->get('param', array()));
         $methodDescriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor);
     }
     $methodDescriptor->setLine($data->getLinenumber());
     return $methodDescriptor;
 }
 /**
  * @covers phpDocumentor\Descriptor\Builder\Reflector\ArgumentAssembler::create
  * @covers phpDocumentor\Descriptor\Builder\Reflector\ArgumentAssembler::overwriteTypeAndDescriptionFromParamTag
  */
 public function testIfTypeAndDescriptionAreSetFromParamDescriptor()
 {
     // Arrange
     $name = 'goodArgument';
     $type = 'boolean';
     $argumentReflectorMock = $this->givenAnArgumentReflectorWithNameAndType($name, $type);
     $types = $this->thenProjectBuilderShouldSetCollectionOfExpectedTypes(array($type));
     // Mock a paramDescriptor
     $paramDescriptorTagMock = m::mock('phpDocumentor\\Descriptor\\Tag\\ParamDescriptor');
     $paramDescriptorTagMock->shouldReceive('getVariableName')->once()->andReturn($name);
     $paramDescriptorTagMock->shouldReceive('getDescription')->once()->andReturn('Is this a good argument, or nah?');
     $paramDescriptorTagMock->shouldReceive('getTypes')->once()->andReturn($types);
     // Act
     $descriptor = $this->fixture->create($argumentReflectorMock, array($paramDescriptorTagMock));
     // Assert
     $this->assertSame($name, $descriptor->getName());
     $this->assertSame($types, $descriptor->getTypes());
     $this->assertSame(false, $descriptor->getDefault());
     $this->assertSame(false, $descriptor->isByReference());
 }