1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2017 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Descriptor\Builder\Reflector; |
14
|
|
|
|
15
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
16
|
|
|
use phpDocumentor\Reflection\DocBlock; |
17
|
|
|
use phpDocumentor\Reflection\ClassReflector\PropertyReflector; |
18
|
|
|
use Mockery as m; |
19
|
|
|
use phpDocumentor\Reflection\DocBlock\Description; |
20
|
|
|
use phpDocumentor\Reflection\Fqsen; |
21
|
|
|
use phpDocumentor\Reflection\Php\Property; |
22
|
|
|
use phpDocumentor\Reflection\Php\Visibility; |
23
|
|
|
use phpDocumentor\Reflection\Types\String_; |
24
|
|
|
|
25
|
|
|
class PropertyAssemblerTest extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
|
/** @var PropertyAssembler $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->builderMock->shouldReceive('buildDescriptor')->andReturn(null); |
40
|
|
|
|
41
|
|
|
$this->fixture = new PropertyAssembler(); |
42
|
|
|
$this->fixture->setBuilder($this->builderMock); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @covers phpDocumentor\Descriptor\Builder\Reflector\PropertyAssembler::create |
47
|
|
|
*/ |
48
|
|
|
public function testCreatePropertyDescriptorFromReflector() |
49
|
|
|
{ |
50
|
|
|
// Arrange |
51
|
|
|
$namespace = 'Namespace'; |
52
|
|
|
$propertyName = 'property'; |
53
|
|
|
|
54
|
|
|
$propertyReflectorMock = $this->givenAPropertyReflector( |
55
|
|
|
$namespace, |
56
|
|
|
$propertyName, |
57
|
|
|
$this->givenADocBlockObject(true) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
// Act |
61
|
|
|
$descriptor = $this->fixture->create($propertyReflectorMock); |
62
|
|
|
|
63
|
|
|
// Assert |
64
|
|
|
$expectedFqsen = '\\' . $namespace . '::$' . $propertyName; |
65
|
|
|
$this->assertSame($expectedFqsen, (string)$descriptor->getFullyQualifiedStructuralElementName()); |
66
|
|
|
$this->assertSame($propertyName, $descriptor->getName()); |
67
|
|
|
$this->assertSame('\\' . $namespace, $descriptor->getNamespace()); |
68
|
|
|
$this->assertSame('protected', (string)$descriptor->getVisibility()); |
69
|
|
|
$this->assertFalse($descriptor->isStatic()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Creates a sample property reflector for the tests with the given data. |
74
|
|
|
* |
75
|
|
|
* @param string $namespace |
76
|
|
|
* @param string $propertyName |
77
|
|
|
* @param DocBlock|m\MockInterface $docBlockMock |
78
|
|
|
* |
79
|
|
|
* @return PropertyReflector|m\MockInterface |
80
|
|
|
*/ |
81
|
|
|
protected function givenAPropertyReflector($namespace, $propertyName, $docBlockMock = null) |
82
|
|
|
{ |
83
|
|
|
$propertyReflectorMock = new Property( |
84
|
|
|
new Fqsen('\\' . $namespace . '::$' . $propertyName), |
85
|
|
|
new Visibility(Visibility::PROTECTED_), |
86
|
|
|
$docBlockMock |
|
|
|
|
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
return $propertyReflectorMock; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Generates a DocBlock object with applicable defaults for these tests. |
94
|
|
|
* |
95
|
|
|
* @return DocBlock|m\MockInterface |
96
|
|
|
*/ |
97
|
|
|
protected function givenADocBlockObject($withTags) |
98
|
|
|
{ |
99
|
|
|
$docBlockDescription = new Description('This is an example description'); |
100
|
|
|
|
101
|
|
|
$tags = []; |
102
|
|
|
|
103
|
|
|
if ($withTags) { |
104
|
|
|
$tags[] = new DocBlock\Tags\Var_('variableName', new String_(), new Description('Var description')); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $docBlockMock = new DocBlock('This is a example description', $docBlockDescription, $tags); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.