/** * @covers phpDocumentor\Descriptor\FunctionDescriptor::setArguments * @covers phpDocumentor\Descriptor\FunctionDescriptor::getArguments */ public function testSettingAndGettingArguments() { $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $this->fixture->getArguments()); $mockInstance = m::mock('phpDocumentor\\Descriptor\\Collection'); $mock =& $mockInstance; $this->fixture->setArguments($mock); $this->assertSame($mockInstance, $this->fixture->getArguments()); }
/** * 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; }
/** * Generates a URL from the given node or returns false if unable. * * @param string|Descriptor\FunctionDescriptor $node * * @return string|false */ public function __invoke($node) { $converter = new QualifiedNameToUrlConverter(); return '/namespaces/' . $converter->fromNamespace($node->getNamespace()) . '.html#function_' . $node->getName(); }
/** * Export this function definition to the given parent DOMElement. * * @param \DOMElement $parent Element to augment. * @param FunctionDescriptor $function Element to export. * @param \DOMElement $child if supplied this element will be augmented instead of freshly added. * * @return void */ public function buildFunction(\DOMElement $parent, FunctionDescriptor $function, \DOMElement $child = null) { if (!$child) { $child = new \DOMElement('function'); $parent->appendChild($child); } $namespace = $function->getNamespace() ? $function->getNamespace() : $parent->getAttribute('namespace'); $child->setAttribute('namespace', ltrim($namespace, '\\')); $child->setAttribute('line', $function->getLine()); $child->appendChild(new \DOMElement('name', $function->getName())); $child->appendChild(new \DOMElement('full_name', $function->getFullyQualifiedStructuralElementName())); $this->buildDocBlock($child, $function); foreach ($function->getArguments() as $argument) { $this->buildArgument($child, $argument); } }
/** * 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); }
/** * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::execute * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::addElementsOfTypeToPackage */ public function testAddFunctionToNamespace() { $function = new FunctionDescriptor(); $function->setPackage('My\\Space'); $function->setFullyQualifiedStructuralElementName('My\\Space\\Function1'); $this->project->getFiles()->get(0)->getFunctions()->add($function); // double check if a second function in the same deep namespace ends up at the right location $function2 = new FunctionDescriptor(); $function2->setPackage('My\\Space'); $function2->setFullyQualifiedStructuralElementName('My\\Space\\Function2'); $this->project->getFiles()->get(0)->getFunctions()->add($function2); $this->fixture->execute($this->project); $this->assertSame(array($function, $function2), $this->project->getIndexes()->get('packages')->get('\\My\\Space')->getFunctions()->getAll()); }
/** * Generates a URL from the given node or returns false if unable. * * @param \phpDocumentor\Descriptor\FunctionDescriptor $node * * @return string|false */ public function __invoke($node) { $namespaceName = $node->getNamespace(); $name = $node->getName(); return '/namespaces/' . str_replace('\\', '.', ltrim($namespaceName, '\\')) . '.html#function_' . $name; }
/** * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey */ public function testAddFunctionsToIndex() { $file1 = $this->project->getFiles()->get(0); $functionDescriptor1 = new FunctionDescriptor(); $functionDescriptor1->setFullyQualifiedStructuralElementName('function1'); $file1->getFunctions()->add($functionDescriptor1); $file2 = $this->project->getFiles()->get(1); $functionDescriptor2 = new FunctionDescriptor(); $functionDescriptor2->setFullyQualifiedStructuralElementName('function2'); $file2->getFunctions()->add($functionDescriptor2); $this->fixture->execute($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(2, $elements); $this->assertSame(array('function1', 'function2'), array_keys($elements)); $this->assertSame(array($functionDescriptor1, $functionDescriptor2), array_values($elements)); $elements = $this->project->getIndexes()->get('functions')->getAll(); $this->assertCount(2, $elements); $this->assertSame(array('function1', 'function2'), array_keys($elements)); $this->assertSame(array($functionDescriptor1, $functionDescriptor2), array_values($elements)); }