/** * @covers phpDocumentor\Descriptor\TraitDescriptor::setPackage */ public function testSettingAndGettingPackage() { $package = new \phpDocumentor\Descriptor\PackageDescriptor(); $mockPropertyDescriptor = m::mock('phpDocumentor\\Descriptor\\PropertyDescriptor'); $mockPropertyDescriptor->shouldReceive('setPackage')->with($package); $mockMethodDescriptor = m::mock('phpDocumentor\\Descriptor\\MethodDescriptor'); $mockMethodDescriptor->shouldReceive('setPackage')->with($package); $propertyCollection = new Collection(array($mockPropertyDescriptor)); $methodCollection = new Collection(array($mockMethodDescriptor)); $this->fixture->setProperties($propertyCollection); $this->fixture->setMethods($methodCollection); $this->fixture->setPackage($package); $this->assertSame($package, $this->fixture->getPackage()); }
/** * Creates a Descriptor from the provided data. * * @param TraitReflector $data * * @return TraitDescriptor */ public function create($data) { $traitDescriptor = new TraitDescriptor(); $traitDescriptor->setFullyQualifiedStructuralElementName($data->getName()); $traitDescriptor->setName($data->getShortName()); $traitDescriptor->setLine($data->getLinenumber()); $traitDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: ''); // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself $traitDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace())); $this->assembleDocBlock($data->getDocBlock(), $traitDescriptor); $this->addProperties($data->getProperties(), $traitDescriptor); $this->addMethods($data->getMethods(), $traitDescriptor); return $traitDescriptor; }
/** * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::execute * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::addElementsOfTypeToPackage */ public function testAddTraitToNamespace() { $trait = new TraitDescriptor(); $trait->setPackage('My\\Space'); $trait->setFullyQualifiedStructuralElementName('My\\Space\\Trait1'); $this->project->getFiles()->get(0)->getTraits()->add($trait); // double check if a second trait in the same deep namespace ends up at the right location $trait2 = new TraitDescriptor(); $trait2->setPackage('My\\Space'); $trait2->setFullyQualifiedStructuralElementName('My\\Space\\Trait2'); $this->project->getFiles()->get(0)->getTraits()->add($trait2); $this->fixture->execute($this->project); $this->assertSame(array($trait, $trait2), $this->project->getIndexes()->get('packages')->get('\\My\\Space')->getTraits()->getAll()); }