/** * @param string $notation * @param string $returnType * @param string $name * @param string[] $arguments * @param string $description * * @dataProvider provideNotations * @covers phpDocumentor\Descriptor\Builder\Reflector\Tags\MethodAssembler::create * @covers phpDocumentor\Descriptor\Builder\Reflector\Tags\MethodAssembler::createArgumentDescriptorForMagicMethod */ public function testCreateMethodDescriptorFromVariousNotations($notation, $returnType, $name, $arguments = array(), $description = '') { $this->builder->shouldReceive('buildDescriptor')->with(m::on(function (TypeCollection $value) use($returnType) { return $value[0] == $returnType; }))->andReturn(new Collection(array($returnType))); foreach ($arguments as $argument) { list($argumentType, $argumentName, $argumentDefault) = $argument; $this->builder->shouldReceive('buildDescriptor')->with(m::on(function (TypeCollection $value) use($argumentType) { return $value[0] == $argumentType; }))->andReturn(new Collection(array($argumentType))); } $tag = new MethodTag('method', $notation); $descriptor = $this->fixture->create($tag); $this->assertSame(1, $descriptor->getResponse()->getTypes()->count()); $this->assertSame($returnType, $descriptor->getResponse()->getTypes()->get(0)); $this->assertSame($name, $descriptor->getMethodName()); $this->assertSame($description, $descriptor->getDescription()); $this->assertSame(count($arguments), $descriptor->getArguments()->count()); foreach ($arguments as $argument) { list($argumentType, $argumentName, $argumentDefault) = $argument; $this->assertSame($argumentType, $descriptor->getArguments()->get($argumentName)->getTypes()->get(0)); $this->assertSame($argumentName, $descriptor->getArguments()->get($argumentName)->getName()); $this->assertSame($argumentDefault, $descriptor->getArguments()->get($argumentName)->getDefault()); } }
/** * Creates a new fixture to test with. */ protected function setUp() { $this->builderMock = m::mock('phpDocumentor\\Descriptor\\ProjectDescriptorBuilder'); $this->builderMock->shouldReceive('buildDescriptor')->andReturn(null); $this->argumentAssemblerMock = m::mock('phpDocumentor\\Descriptor\\Builder\\Reflector\\ArgumentAssembler'); $this->argumentAssemblerMock->shouldReceive('getBuilder')->andReturn($this->builderMock); $this->fixture = new MethodAssembler($this->argumentAssemblerMock); $this->fixture->setBuilder($this->builderMock); }
/** * @covers phpDocumentor\Descriptor\Builder\Reflector\Tags\ReturnAssembler::create */ public function testCreatingReturnDescriptorFromReflector() { $types = new Collection(); $this->builder->shouldReceive('buildDescriptor')->with(m::on(function ($value) { return $value instanceof TypeCollection && $value[0] == 'string'; }))->andReturn($types); $reflector = new ReturnTag('return', 'string This is a description'); $descriptor = $this->fixture->create($reflector); $this->assertSame('return', $descriptor->getName()); $this->assertSame('This is a description', $descriptor->getDescription()); $this->assertSame($types, $descriptor->getTypes()); }
/** * @param $expected * @return Collection */ protected function thenProjectBuilderShouldSetCollectionOfExpectedTypes($expected) { $types = new Collection($expected); $this->builderMock->shouldReceive('buildDescriptor')->with(m::on(function ($value) use($expected) { return $value instanceof Collection && $value->getArrayCopy() == $expected; }))->andReturn($types); return $types; }
/** * @covers phpDocumentor\Descriptor\Filter\StripInternal::filter */ public function testDescriptorIsUnmodifiedIfThereIsNoInternalTag() { $this->builderMock->shouldReceive('isVisibilityAllowed')->andReturn(true); $descriptor = m::mock('phpDocumentor\\Descriptor\\DescriptorAbstract'); $descriptor->shouldReceive('getDescription'); $descriptor->shouldReceive('setDescription'); $descriptor->shouldReceive('getTags->get')->with('internal')->andReturn(false); // we clone the descriptor so its references differ; if something changes in the descriptor then // the $descriptor variable and the returned clone will differ $this->assertEquals($descriptor, $this->fixture->filter(clone $descriptor)); }
/** * @covers phpDocumentor\Descriptor\Filter\StripOnVisibility::filter */ public function testKeepsDescriptorIfDescriptorNotInstanceOfVisibilityInterface() { $this->builderMock->shouldReceive('isVisibilityAllowed')->andReturn(false); $descriptor = m::mock('\\phpDocumentor\\Descriptor\\DescriptorAbstract'); $this->assertSame($descriptor, $this->fixture->filter($descriptor)); }