1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @author Mike van Riel <[email protected]> |
8
|
|
|
* @author Sven Hagemann <[email protected]> |
9
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Descriptor\Builder\Reflector; |
15
|
|
|
|
16
|
|
|
use Mockery as m; |
17
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
18
|
|
|
use phpDocumentor\Reflection\Php\Argument; |
19
|
|
|
use phpDocumentor\Reflection\Type; |
20
|
|
|
use phpDocumentor\Reflection\Types\Boolean; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Test class for phpDocumentor\Descriptor\Builder\Reflector\ArgumentAssembler |
24
|
|
|
*/ |
25
|
|
|
class ArgumentAssemblerTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
26
|
|
|
{ |
27
|
|
|
/** @var ArgumentAssembler $fixture */ |
28
|
|
|
protected $fixture; |
29
|
|
|
|
30
|
|
|
/** @var ProjectDescriptorBuilder|m\MockInterface */ |
31
|
|
|
protected $builderMock; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Creates a new fixture to test with. |
35
|
|
|
*/ |
36
|
|
|
protected function setUp() |
37
|
|
|
{ |
38
|
|
|
$this->builderMock = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder'); |
39
|
|
|
$this->fixture = new ArgumentAssembler(); |
40
|
|
|
$this->fixture->setBuilder($this->builderMock); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @covers \phpDocumentor\Descriptor\Builder\Reflector\ArgumentAssembler::create |
45
|
|
|
*/ |
46
|
|
|
public function testCreateArgumentDescriptorFromReflector() |
47
|
|
|
{ |
48
|
|
|
// Arrange |
49
|
|
|
$name = 'goodArgument'; |
50
|
|
|
$type = new Boolean(); |
51
|
|
|
|
52
|
|
|
$argumentReflectorMock = $this->givenAnArgumentReflectorWithNameAndType($name, $type); |
53
|
|
|
|
54
|
|
|
// Act |
55
|
|
|
$descriptor = $this->fixture->create($argumentReflectorMock); |
56
|
|
|
|
57
|
|
|
// Assert |
58
|
|
|
$this->assertSame($name, $descriptor->getName()); |
59
|
|
|
$this->assertSame($type, $descriptor->getType()); |
60
|
|
|
$this->assertNull($descriptor->getDefault()); |
61
|
|
|
$this->assertFalse($descriptor->isByReference()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @covers \phpDocumentor\Descriptor\Builder\Reflector\ArgumentAssembler::create |
66
|
|
|
* @covers \phpDocumentor\Descriptor\Builder\Reflector\ArgumentAssembler::overwriteTypeAndDescriptionFromParamTag |
67
|
|
|
*/ |
68
|
|
|
public function testIfTypeAndDescriptionAreSetFromParamDescriptor() |
69
|
|
|
{ |
70
|
|
|
// Arrange |
71
|
|
|
$name = 'goodArgument'; |
72
|
|
|
$type = new Boolean(); |
73
|
|
|
|
74
|
|
|
$argumentReflectorMock = $this->givenAnArgumentReflectorWithNameAndType($name, $type); |
75
|
|
|
|
76
|
|
|
// Mock a paramDescriptor |
77
|
|
|
$paramDescriptorTagMock = m::mock('phpDocumentor\Descriptor\Tag\ParamDescriptor'); |
78
|
|
|
$paramDescriptorTagMock->shouldReceive('getVariableName')->once()->andReturn($name); |
79
|
|
|
$paramDescriptorTagMock->shouldReceive('getDescription')->once()->andReturn('Is this a good argument, or nah?'); |
80
|
|
|
$paramDescriptorTagMock->shouldReceive('getType')->once()->andReturn($type); |
81
|
|
|
|
82
|
|
|
// Act |
83
|
|
|
$descriptor = $this->fixture->create($argumentReflectorMock, [$paramDescriptorTagMock]); |
|
|
|
|
84
|
|
|
|
85
|
|
|
// Assert |
86
|
|
|
$this->assertSame($name, $descriptor->getName()); |
87
|
|
|
$this->assertSame($type, $descriptor->getType()); |
88
|
|
|
$this->assertNull($descriptor->getDefault()); |
89
|
|
|
$this->assertFalse($descriptor->isByReference()); |
90
|
|
|
$this->assertFalse($descriptor->isVariadic()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @covers \phpDocumentor\Descriptor\Builder\Reflector\ArgumentAssembler::create |
95
|
|
|
*/ |
96
|
|
|
public function testIfVariadicArgumentsAreDetected() |
97
|
|
|
{ |
98
|
|
|
// Arrange |
99
|
|
|
$name = 'goodArgument'; |
100
|
|
|
$type = new Boolean(); |
101
|
|
|
|
102
|
|
|
$argumentReflectorMock = $this->givenAnArgumentReflectorWithNameAndType($name, $type, true); |
103
|
|
|
|
104
|
|
|
// Mock a paramDescriptor |
105
|
|
|
$paramDescriptorTagMock = m::mock('phpDocumentor\Descriptor\Tag\ParamDescriptor'); |
106
|
|
|
$paramDescriptorTagMock->shouldReceive('getVariableName')->once()->andReturn($name); |
107
|
|
|
$paramDescriptorTagMock->shouldReceive('getDescription')->once()->andReturn('Is this a good argument, or nah?'); |
108
|
|
|
$paramDescriptorTagMock->shouldReceive('getType')->once()->andReturn($type); |
109
|
|
|
|
110
|
|
|
// Act |
111
|
|
|
$descriptor = $this->fixture->create($argumentReflectorMock, [$paramDescriptorTagMock]); |
112
|
|
|
|
113
|
|
|
// Assert |
114
|
|
|
$this->assertSame($name, $descriptor->getName()); |
115
|
|
|
$this->assertSame($type, $descriptor->getType()); |
116
|
|
|
$this->assertNull($descriptor->getDefault()); |
117
|
|
|
$this->assertFalse($descriptor->isByReference()); |
118
|
|
|
$this->assertTrue($descriptor->isVariadic()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
protected function givenAnArgumentReflectorWithNameAndType( |
122
|
|
|
string $name, |
123
|
|
|
Type $type, |
124
|
|
|
bool $isVariadic = false |
125
|
|
|
): Argument { |
126
|
|
|
return new Argument($name, $type, null, false, $isVariadic); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
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: