1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com) |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* @link http://phpdoc.org |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpDocumentor\Descriptor\Type; |
13
|
|
|
|
14
|
|
|
class CollectionDescriptorTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** @var CollectionDescriptor */ |
17
|
|
|
private $fixture; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Initializes the fixture for this test. |
21
|
|
|
*/ |
22
|
|
|
public function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->fixture = new CollectionDescriptor('array'); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getName |
29
|
|
|
*/ |
30
|
|
|
public function testRetrieveNameForBaseTypeWithTypeString() |
31
|
|
|
{ |
32
|
|
|
$this->assertSame('array', $this->fixture->getName()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getName |
37
|
|
|
*/ |
38
|
|
|
public function testRetrieveNameForBaseTypeWithTypeDescriptor() |
39
|
|
|
{ |
40
|
|
|
$fixture = new CollectionDescriptor(new UnknownTypeDescriptor('array')); |
41
|
|
|
|
42
|
|
|
$this->assertSame('array', $fixture->getName()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getBaseType |
47
|
|
|
*/ |
48
|
|
|
public function testRetrieveBaseTypeWithTypeStringReturnsNull() |
49
|
|
|
{ |
50
|
|
|
$this->assertSame(null, $this->fixture->getBaseType()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getBaseType |
55
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::setBaseType |
56
|
|
|
*/ |
57
|
|
|
public function testSetAndRetrieveBaseTypeWithTypeDescriptor() |
58
|
|
|
{ |
59
|
|
|
$expected = new UnknownTypeDescriptor('array'); |
60
|
|
|
$this->fixture->setBaseType($expected); |
61
|
|
|
|
62
|
|
|
$this->assertSame($expected, $this->fixture->getBaseType()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getTypes |
67
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::setTypes |
68
|
|
|
*/ |
69
|
|
|
public function testSetAndRetrieveTypes() |
70
|
|
|
{ |
71
|
|
|
$expected = new UnknownTypeDescriptor('array'); |
72
|
|
|
$this->fixture->setTypes(array($expected)); |
73
|
|
|
|
74
|
|
|
$this->assertSame(array($expected), $this->fixture->getTypes()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getKeyTypes |
79
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::setKeyTypes |
80
|
|
|
*/ |
81
|
|
|
public function testSetAndRetrieveKeyTypes() |
82
|
|
|
{ |
83
|
|
|
$expected = new UnknownTypeDescriptor('string'); |
84
|
|
|
$this->fixture->setKeyTypes(array($expected)); |
85
|
|
|
|
86
|
|
|
$this->assertSame(array($expected), $this->fixture->getKeyTypes()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::__toString |
91
|
|
|
*/ |
92
|
|
|
public function testRetrieveCollectionNotationFromObject() |
93
|
|
|
{ |
94
|
|
|
$this->fixture->setKeyTypes(array(new StringDescriptor())); |
95
|
|
|
$this->fixture->setTypes(array(new FloatDescriptor(), new IntegerDescriptor())); |
96
|
|
|
|
97
|
|
|
$this->assertSame('array<string,float|integer>', (string) $this->fixture); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::__toString |
102
|
|
|
*/ |
103
|
|
|
public function testRetrieveCollectionNotationFromObjectWithoutKeys() |
104
|
|
|
{ |
105
|
|
|
$this->fixture->setTypes(array(new FloatDescriptor(), new IntegerDescriptor())); |
106
|
|
|
|
107
|
|
|
$this->assertSame('array<float|integer>', (string) $this->fixture); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: