These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * phpDocumentor |
||
4 | * |
||
5 | * PHP Version 5.3 |
||
6 | * |
||
7 | * @copyright 2010-2013 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; |
||
13 | |||
14 | /** |
||
15 | * Tests the functionality for the ArgumentDescriptor class. |
||
16 | */ |
||
17 | class ArgumentDescriptorTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
18 | { |
||
19 | /** @var ArgumentDescriptor $fixture */ |
||
20 | protected $fixture; |
||
21 | |||
22 | /** |
||
23 | * Creates a new (emoty) fixture object. |
||
24 | */ |
||
25 | protected function setUp() |
||
26 | { |
||
27 | $this->fixture = new ArgumentDescriptor(); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::getTypes |
||
32 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::setTypes |
||
33 | */ |
||
34 | public function testSetAndGetTypes() |
||
35 | { |
||
36 | $this->assertSame(array(), $this->fixture->getTypes()); |
||
37 | |||
38 | $this->fixture->setTypes(array(1)); |
||
0 ignored issues
–
show
|
|||
39 | |||
40 | $this->assertSame(array(1), $this->fixture->getTypes()); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::getDefault |
||
45 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::setDefault |
||
46 | */ |
||
47 | public function testSetAndGetDefault() |
||
48 | { |
||
49 | $this->assertNull($this->fixture->getDefault()); |
||
50 | |||
51 | $this->fixture->setDefault('a'); |
||
52 | |||
53 | $this->assertSame('a', $this->fixture->getDefault()); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::isByReference |
||
58 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::setByReference |
||
59 | */ |
||
60 | public function testSetAndGetWhetherArgumentIsPassedByReference() |
||
61 | { |
||
62 | $this->assertFalse($this->fixture->isByReference()); |
||
63 | |||
64 | $this->fixture->setByReference(true); |
||
65 | |||
66 | $this->assertTrue($this->fixture->isByReference()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::getDescription |
||
71 | */ |
||
72 | public function testDescriptionInheritsWhenNoneIsPresent() |
||
73 | { |
||
74 | // Arrange |
||
75 | $description = 'This is a description'; |
||
76 | $this->fixture->setDescription(null); |
||
77 | $parentArgument = $this->whenFixtureHasMethodAndArgumentInParentClassWithSameName('same_argument'); |
||
78 | $parentArgument->setDescription($description); |
||
79 | // Act |
||
80 | $result = $this->fixture->getDescription(); |
||
81 | |||
82 | // Assert |
||
83 | $this->assertSame($description, $result); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::getDescription |
||
88 | */ |
||
89 | public function testDescriptionIsNotInheritedWhenPresent() |
||
90 | { |
||
91 | // Arrange |
||
92 | $description = 'This is a description'; |
||
93 | $this->fixture->setDescription($description); |
||
94 | $parentArgument = $this->whenFixtureHasMethodAndArgumentInParentClassWithSameName('same_argument'); |
||
95 | $parentArgument->setDescription('some random text'); |
||
96 | // Act |
||
97 | $result = $this->fixture->getDescription(); |
||
98 | |||
99 | // Assert |
||
100 | $this->assertSame($description, $result); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @covers phpDocumentor\Descriptor\ArgumentDescriptor::getTypes |
||
105 | */ |
||
106 | public function testTypeIsInheritedWhenNoneIsPresent() |
||
107 | { |
||
108 | // Arrange |
||
109 | $types = array('string'); |
||
110 | $this->fixture->setTypes(null); |
||
111 | $parentArgument = $this->whenFixtureHasMethodAndArgumentInParentClassWithSameName('same_argument'); |
||
112 | $parentArgument->setTypes($types); |
||
113 | // Act |
||
114 | $result = $this->fixture->getTypes(); |
||
115 | |||
116 | // Assert |
||
117 | $this->assertSame($types, $result); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @param string $argumentName The name of the current method. |
||
122 | * |
||
123 | * @return ArgumentDescriptor |
||
124 | */ |
||
125 | private function whenFixtureHasMethodAndArgumentInParentClassWithSameName($argumentName) |
||
126 | { |
||
127 | $this->fixture->setName($argumentName); |
||
128 | |||
129 | $parentArgument = new ArgumentDescriptor(); |
||
130 | $parentArgument->setName($argumentName); |
||
131 | |||
132 | $parentMethod = new MethodDescriptor(); |
||
133 | $parentMethod->setName('same'); |
||
134 | $parentMethod->addArgument($argumentName, $parentArgument); |
||
135 | |||
136 | $method = new MethodDescriptor; |
||
137 | $method->setName('same'); |
||
138 | $method->addArgument($argumentName, $this->fixture); |
||
139 | |||
140 | $parent = new ClassDescriptor(); |
||
141 | $parent->getMethods()->set('same', $parentMethod); |
||
142 | $parentMethod->setParent($parent); |
||
143 | |||
144 | $class = new ClassDescriptor(); |
||
145 | $class->setParent($parent); |
||
146 | $class->getMethods()->set('same', $method); |
||
147 | $method->setParent($class); |
||
148 | |||
149 | return $parentArgument; |
||
150 | |||
151 | } |
||
152 | } |
||
153 |
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: