Merge pull request #67 from mbed67/fix-bug-in-collection

fix for bug #1672 in phpDocumentor2
This commit is contained in:
Mike van Riel
2016-01-25 09:17:30 +01:00
2 changed files with 66 additions and 1 deletions
@@ -161,7 +161,8 @@ class Collection extends \ArrayObject
$namespace_aliases = $this->context->getNamespaceAliases();
// if the first segment is not an alias; prepend namespace name and
// return
if (!isset($namespace_aliases[$type_parts[0]])) {
if (!isset($namespace_aliases[$type_parts[0]]) &&
!isset($namespace_aliases[strstr($type_parts[0], '::', true)])) {
$namespace = $this->context->getNamespace();
if ('' !== $namespace) {
$namespace .= self::OPERATOR_NAMESPACE;
@@ -169,6 +170,12 @@ class Collection extends \ArrayObject
return self::OPERATOR_NAMESPACE . $namespace . $type;
}
if (strpos($type_parts[0], '::')) {
$type_parts[] = strstr($type_parts[0], '::');
$type_parts[0] = $namespace_aliases[strstr($type_parts[0], '::', true)];
return implode('', $type_parts);
}
$type_parts[0] = $namespace_aliases[$type_parts[0]];
$type = implode(self::OPERATOR_NAMESPACE, $type_parts);
}
@@ -123,6 +123,26 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, $collection->getArrayCopy());
}
/**
* @param string $fixture
* @param array $expected
*
* @dataProvider provideTypesToExpandWithPropertyOrMethod
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
*
* @return void
*/
public function testAddMethodsAndProperties($fixture, $expected)
{
$collection = new Collection(
array(),
new Context(null, array('LinkDescriptor' => '\phpDocumentor\LinkDescriptor'))
);
$collection->add($fixture);
$this->assertSame($expected, $collection->getArrayCopy());
}
/**
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
* @expectedException InvalidArgumentException
@@ -177,6 +197,14 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
'DocBlock[]|int[]',
array($namespace.'DocBlock[]', 'int[]')
),
array(
'LinkDescriptor::setLink()',
array($namespace.'LinkDescriptor::setLink()')
),
array(
'Alias\LinkDescriptor::setLink()',
array('\My\Space\Aliasing\LinkDescriptor::setLink()')
),
);
}
@@ -192,4 +220,34 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
{
return $this->provideTypesToExpand($method, '\\');
}
/**
* Returns the method and property types and their expected values to test
* the retrieval of types.
*
* @param string $method Name of the method consuming this data provider.
*
* @return string[]
*/
public function provideTypesToExpandWithPropertyOrMethod($method)
{
return array(
array(
'LinkDescriptor::setLink()',
array('\phpDocumentor\LinkDescriptor::setLink()')
),
array(
'phpDocumentor\LinkDescriptor::setLink()',
array('\phpDocumentor\LinkDescriptor::setLink()')
),
array(
'LinkDescriptor::$link',
array('\phpDocumentor\LinkDescriptor::$link')
),
array(
'phpDocumentor\LinkDescriptor::$link',
array('\phpDocumentor\LinkDescriptor::$link')
),
);
}
}