3 * phpDocumentor Collection Test
7 * @author Mike van Riel <mike.vanriel@naenius.com>
8 * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
9 * @license http://www.opensource.org/licenses/mit-license.php MIT
10 * @link http://phpdoc.org
13 namespace phpDocumentor\Reflection\DocBlock\Type;
15 use phpDocumentor\Reflection\DocBlock\Context;
18 * Test class for \phpDocumentor\Reflection\DocBlock\Type\Collection
20 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection
22 * @author Mike van Riel <mike.vanriel@naenius.com>
23 * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
24 * @license http://www.opensource.org/licenses/mit-license.php MIT
25 * @link http://phpdoc.org
27 class CollectionTest extends \PHPUnit_Framework_TestCase
30 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
31 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getContext
35 public function testConstruct()
37 $collection = new Collection();
38 $this->assertCount(0, $collection);
39 $this->assertEquals('', $collection->getContext()->getNamespace());
40 $this->assertCount(0, $collection->getContext()->getNamespaceAliases());
44 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
48 public function testConstructWithTypes()
50 $collection = new Collection(array('integer', 'string'));
51 $this->assertCount(2, $collection);
55 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
59 public function testConstructWithNamespace()
61 $collection = new Collection(array(), new Context('\My\Space'));
62 $this->assertEquals('My\Space', $collection->getContext()->getNamespace());
64 $collection = new Collection(array(), new Context('My\Space'));
65 $this->assertEquals('My\Space', $collection->getContext()->getNamespace());
67 $collection = new Collection(array(), null);
68 $this->assertEquals('', $collection->getContext()->getNamespace());
72 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
76 public function testConstructWithNamespaceAliases()
78 $fixture = array('a' => 'b');
79 $collection = new Collection(array(), new Context(null, $fixture));
82 $collection->getContext()->getNamespaceAliases()
87 * @param string $fixture
88 * @param array $expected
90 * @dataProvider provideTypesToExpand
91 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
95 public function testAdd($fixture, $expected)
97 $collection = new Collection(
99 new Context('\My\Space', array('Alias' => '\My\Space\Aliasing'))
101 $collection->add($fixture);
103 $this->assertSame($expected, $collection->getArrayCopy());
107 * @param string $fixture
108 * @param array $expected
110 * @dataProvider provideTypesToExpandWithoutNamespace
111 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
115 public function testAddWithoutNamespace($fixture, $expected)
117 $collection = new Collection(
119 new Context(null, array('Alias' => '\My\Space\Aliasing'))
121 $collection->add($fixture);
123 $this->assertSame($expected, $collection->getArrayCopy());
127 * @param string $fixture
128 * @param array $expected
130 * @dataProvider provideTypesToExpandWithPropertyOrMethod
131 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
135 public function testAddMethodsAndProperties($fixture, $expected)
137 $collection = new Collection(
139 new Context(null, array('LinkDescriptor' => '\phpDocumentor\LinkDescriptor'))
141 $collection->add($fixture);
143 $this->assertSame($expected, $collection->getArrayCopy());
147 * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
148 * @expectedException InvalidArgumentException
152 public function testAddWithInvalidArgument()
154 $collection = new Collection();
155 $collection->add(array());
159 * Returns the types and their expected values to test the retrieval of
162 * @param string $method Name of the method consuming this data provider.
163 * @param string $namespace Name of the namespace to user as basis.
167 public function provideTypesToExpand($method, $namespace = '\My\Space\\')
172 array('int', array('int')),
173 array('int ', array('int')),
174 array('string', array('string')),
175 array('DocBlock', array($namespace.'DocBlock')),
176 array('DocBlock[]', array($namespace.'DocBlock[]')),
177 array(' DocBlock ', array($namespace.'DocBlock')),
178 array('\My\Space\DocBlock', array('\My\Space\DocBlock')),
179 array('Alias\DocBlock', array('\My\Space\Aliasing\DocBlock')),
182 array($namespace .'DocBlock', $namespace .'Tag')
186 array($namespace.'DocBlock', 'null')
189 '\My\Space\DocBlock|Tag',
190 array('\My\Space\DocBlock', $namespace.'Tag')
194 array($namespace.'DocBlock[]', 'null')
198 array($namespace.'DocBlock[]', 'int[]')
201 'LinkDescriptor::setLink()',
202 array($namespace.'LinkDescriptor::setLink()')
205 'Alias\LinkDescriptor::setLink()',
206 array('\My\Space\Aliasing\LinkDescriptor::setLink()')
212 * Returns the types and their expected values to test the retrieval of
213 * types when no namespace is available.
215 * @param string $method Name of the method consuming this data provider.
219 public function provideTypesToExpandWithoutNamespace($method)
221 return $this->provideTypesToExpand($method, '\\');
225 * Returns the method and property types and their expected values to test
226 * the retrieval of types.
228 * @param string $method Name of the method consuming this data provider.
232 public function provideTypesToExpandWithPropertyOrMethod($method)
236 'LinkDescriptor::setLink()',
237 array('\phpDocumentor\LinkDescriptor::setLink()')
240 'phpDocumentor\LinkDescriptor::setLink()',
241 array('\phpDocumentor\LinkDescriptor::setLink()')
244 'LinkDescriptor::$link',
245 array('\phpDocumentor\LinkDescriptor::$link')
248 'phpDocumentor\LinkDescriptor::$link',
249 array('\phpDocumentor\LinkDescriptor::$link')