Yaffs site version 1.1
[yaffs-website] / vendor / phpdocumentor / reflection-docblock / tests / phpDocumentor / Reflection / DocBlock / Type / CollectionTest.php
1 <?php
2 /**
3  * phpDocumentor Collection Test
4  * 
5  * PHP version 5.3
6  *
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
11  */
12
13 namespace phpDocumentor\Reflection\DocBlock\Type;
14
15 use phpDocumentor\Reflection\DocBlock\Context;
16
17 /**
18  * Test class for \phpDocumentor\Reflection\DocBlock\Type\Collection
19  * 
20  * @covers phpDocumentor\Reflection\DocBlock\Type\Collection
21  *
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
26  */
27 class CollectionTest extends \PHPUnit_Framework_TestCase
28 {
29     /**
30      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
31      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getContext
32      * 
33      * @return void
34      */
35     public function testConstruct()
36     {
37         $collection = new Collection();
38         $this->assertCount(0, $collection);
39         $this->assertEquals('', $collection->getContext()->getNamespace());
40         $this->assertCount(0, $collection->getContext()->getNamespaceAliases());
41     }
42
43     /**
44      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
45      * 
46      * @return void
47      */
48     public function testConstructWithTypes()
49     {
50         $collection = new Collection(array('integer', 'string'));
51         $this->assertCount(2, $collection);
52     }
53
54     /**
55      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
56      * 
57      * @return void
58      */
59     public function testConstructWithNamespace()
60     {
61         $collection = new Collection(array(), new Context('\My\Space'));
62         $this->assertEquals('My\Space', $collection->getContext()->getNamespace());
63
64         $collection = new Collection(array(), new Context('My\Space'));
65         $this->assertEquals('My\Space', $collection->getContext()->getNamespace());
66
67         $collection = new Collection(array(), null);
68         $this->assertEquals('', $collection->getContext()->getNamespace());
69     }
70
71     /**
72      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
73      * 
74      * @return void
75      */
76     public function testConstructWithNamespaceAliases()
77     {
78         $fixture = array('a' => 'b');
79         $collection = new Collection(array(), new Context(null, $fixture));
80         $this->assertEquals(
81             array('a' => '\b'),
82             $collection->getContext()->getNamespaceAliases()
83         );
84     }
85
86     /**
87      * @param string $fixture
88      * @param array  $expected
89      *
90      * @dataProvider provideTypesToExpand
91      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
92      * 
93      * @return void
94      */
95     public function testAdd($fixture, $expected)
96     {
97         $collection = new Collection(
98             array(),
99             new Context('\My\Space', array('Alias' => '\My\Space\Aliasing'))
100         );
101         $collection->add($fixture);
102
103         $this->assertSame($expected, $collection->getArrayCopy());
104     }
105
106     /**
107      * @param string $fixture
108      * @param array  $expected
109      *
110      * @dataProvider provideTypesToExpandWithoutNamespace
111      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
112      * 
113      * @return void
114      */
115     public function testAddWithoutNamespace($fixture, $expected)
116     {
117         $collection = new Collection(
118             array(),
119             new Context(null, array('Alias' => '\My\Space\Aliasing'))
120         );
121         $collection->add($fixture);
122
123         $this->assertSame($expected, $collection->getArrayCopy());
124     }
125
126     /**
127      * @param string $fixture
128      * @param array  $expected
129      *
130      * @dataProvider provideTypesToExpandWithPropertyOrMethod
131      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
132      *
133      * @return void
134      */
135     public function testAddMethodsAndProperties($fixture, $expected)
136     {
137         $collection = new Collection(
138             array(),
139             new Context(null, array('LinkDescriptor' => '\phpDocumentor\LinkDescriptor'))
140         );
141         $collection->add($fixture);
142
143         $this->assertSame($expected, $collection->getArrayCopy());
144     }
145
146     /**
147      * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
148      * @expectedException InvalidArgumentException
149      * 
150      * @return void
151      */
152     public function testAddWithInvalidArgument()
153     {
154         $collection = new Collection();
155         $collection->add(array());
156     }
157
158     /**
159      * Returns the types and their expected values to test the retrieval of
160      * types.
161      *
162      * @param string $method    Name of the method consuming this data provider.
163      * @param string $namespace Name of the namespace to user as basis.
164      *
165      * @return string[]
166      */
167     public function provideTypesToExpand($method, $namespace = '\My\Space\\')
168     {
169         return array(
170             array('', array()),
171             array(' ', array()),
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')),
180             array(
181                 'DocBlock|Tag',
182                 array($namespace .'DocBlock', $namespace .'Tag')
183             ),
184             array(
185                 'DocBlock|null',
186                 array($namespace.'DocBlock', 'null')
187             ),
188             array(
189                 '\My\Space\DocBlock|Tag',
190                 array('\My\Space\DocBlock', $namespace.'Tag')
191             ),
192             array(
193                 'DocBlock[]|null',
194                 array($namespace.'DocBlock[]', 'null')
195             ),
196             array(
197                 'DocBlock[]|int[]',
198                 array($namespace.'DocBlock[]', 'int[]')
199             ),
200             array(
201                 'LinkDescriptor::setLink()',
202                 array($namespace.'LinkDescriptor::setLink()')
203             ),
204             array(
205                 'Alias\LinkDescriptor::setLink()',
206                 array('\My\Space\Aliasing\LinkDescriptor::setLink()')
207             ),
208         );
209     }
210
211     /**
212      * Returns the types and their expected values to test the retrieval of
213      * types when no namespace is available.
214      *
215      * @param string $method Name of the method consuming this data provider.
216      *
217      * @return string[]
218      */
219     public function provideTypesToExpandWithoutNamespace($method)
220     {
221         return $this->provideTypesToExpand($method, '\\');
222     }
223
224     /**
225      * Returns the method and property types and their expected values to test
226      * the retrieval of types.
227      *
228      * @param string $method Name of the method consuming this data provider.
229      *
230      * @return string[]
231      */
232     public function provideTypesToExpandWithPropertyOrMethod($method)
233     {
234         return array(
235             array(
236                 'LinkDescriptor::setLink()',
237                 array('\phpDocumentor\LinkDescriptor::setLink()')
238             ),
239             array(
240                 'phpDocumentor\LinkDescriptor::setLink()',
241                 array('\phpDocumentor\LinkDescriptor::setLink()')
242             ),
243             array(
244                 'LinkDescriptor::$link',
245                 array('\phpDocumentor\LinkDescriptor::$link')
246             ),
247             array(
248                 'phpDocumentor\LinkDescriptor::$link',
249                 array('\phpDocumentor\LinkDescriptor::$link')
250             ),
251         );
252     }
253 }