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 | * @author Mike van Riel <[email protected]> |
||
8 | * @author Sven Hagemann <[email protected]> |
||
9 | * @copyright 2010-2012 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 | namespace phpDocumentor\Descriptor\Builder\Reflector; |
||
14 | |||
15 | use phpDocumentor\Reflection\DocBlock; |
||
16 | use phpDocumentor\Descriptor\Collection; |
||
17 | |||
18 | use Mockery as m; |
||
19 | |||
20 | /** |
||
21 | * Test class for \phpDocumentor\Descriptor\Builder |
||
22 | * |
||
23 | * @covers \phpDocumentor\Descriptor\Builder\Reflector\FileAssembler |
||
24 | */ |
||
25 | class FileAssemblerTest extends \PHPUnit_Framework_TestCase |
||
26 | { |
||
27 | /** @var FileAssembler $fixture */ |
||
28 | protected $fixture; |
||
29 | |||
30 | /** |
||
31 | * Creates a new fixture to test with. |
||
32 | */ |
||
33 | protected function setUp() |
||
34 | { |
||
35 | $this->fixture = new FileAssembler(); |
||
36 | $this->fixture->setBuilder($this->getProjectDescriptorBuilderMock()); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Creates a Descriptor from a provided class. |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | public function testCreateFileDescriptorFromReflector() |
||
45 | { |
||
46 | $filename = 'file.php'; |
||
47 | $content = '<?php ... ?>'; |
||
48 | $hash = md5($content); |
||
49 | $defaultPackageName = 'Package'; |
||
50 | |||
51 | $abstractDescriptor = m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
||
52 | $abstractDescriptor->shouldReceive('getLineNumber')->andReturn(1337); |
||
53 | |||
54 | $docBlockDescription = new DocBlock\Description( |
||
55 | <<<DOCBLOCK |
||
56 | /** |
||
57 | * This is a example description |
||
58 | */ |
||
59 | DOCBLOCK |
||
60 | ); |
||
61 | |||
62 | $docBlockMock = m::mock('phpDocumentor\Reflection\DocBlock'); |
||
63 | $docBlockMock->shouldReceive('getTagsByName')->andReturn(array()); |
||
64 | $docBlockMock->shouldReceive('getTags')->andReturn(array()); |
||
65 | $docBlockMock->shouldReceive('getShortDescription')->andReturn('This is a example description'); |
||
66 | $docBlockMock->shouldReceive('getLongDescription')->andReturn($docBlockDescription); |
||
67 | |||
68 | $fileReflectorMock = m::mock('phpDocumentor\Reflection\FileReflector'); |
||
69 | $fileReflectorMock->shouldReceive('getName')->andReturn($filename); |
||
70 | $fileReflectorMock->shouldReceive('getFilename')->andReturn($filename); |
||
71 | $fileReflectorMock->shouldReceive('getHash')->andReturn($hash); |
||
72 | $fileReflectorMock->shouldReceive('getContents')->andReturn($content); |
||
73 | $fileReflectorMock->shouldReceive('getDefaultPackageName')->andReturn($defaultPackageName); |
||
74 | $fileReflectorMock->shouldReceive('getDocBlock')->andReturn($docBlockMock); |
||
75 | |||
76 | $fileReflectorMock->shouldReceive('getConstants')->once()->andReturn( |
||
77 | new Collection(array($abstractDescriptor)) |
||
78 | ); |
||
79 | |||
80 | $fileReflectorMock->shouldReceive('getFunctions')->once()->andReturn( |
||
81 | new Collection(array($abstractDescriptor)) |
||
82 | ); |
||
83 | |||
84 | $fileReflectorMock->shouldReceive('getClasses')->once()->andReturn( |
||
85 | new Collection(array($abstractDescriptor)) |
||
86 | ); |
||
87 | |||
88 | $fileReflectorMock->shouldReceive('getInterfaces')->once()->andReturn( |
||
89 | new Collection(array($abstractDescriptor)) |
||
90 | ); |
||
91 | |||
92 | $fileReflectorMock->shouldReceive('getTraits')->once()->andReturn( |
||
93 | new Collection(array($abstractDescriptor)) |
||
94 | ); |
||
95 | |||
96 | $fileReflectorMock->shouldReceive('getMarkers')->once()->andReturn( |
||
97 | array('type', 'message', 1337) |
||
98 | ); |
||
99 | |||
100 | $fileReflectorMock->shouldReceive('getIncludes')->andReturn(new Collection); |
||
101 | $fileReflectorMock->shouldReceive('getNamespaceAliases')->andReturn(new Collection); |
||
102 | |||
103 | $descriptor = $this->fixture->create($fileReflectorMock); |
||
104 | |||
105 | $this->assertSame($filename, $descriptor->getName()); |
||
106 | $this->assertSame($hash, $descriptor->getHash()); |
||
107 | $this->assertSame($content, $descriptor->getSource()); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Create a descriptor builder mock |
||
112 | * |
||
113 | * @return m\MockInterface |
||
114 | */ |
||
115 | protected function getProjectDescriptorBuilderMock() |
||
116 | { |
||
117 | $projectDescriptorBuilderMock = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder'); |
||
118 | |||
119 | $projectDescriptorBuilderMock->shouldReceive('getProjectDescriptor->getSettings->shouldIncludeSource')->andReturn(true); |
||
120 | $projectDescriptorBuilderMock->shouldReceive('buildDescriptor')->andReturnUsing(function ($param) { |
||
0 ignored issues
–
show
|
|||
121 | $mock = m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
||
122 | $mock->shouldReceive('setLocation')->atLeast()->once(); |
||
123 | $mock->shouldReceive('getTags')->atLeast()->once()->andReturn(new Collection); |
||
124 | $mock->shouldReceive('getFullyQualifiedStructuralElementName')->once()->andReturn('Frank_is_een_eindbaas'); |
||
125 | |||
126 | return $mock; |
||
127 | }); |
||
128 | |||
129 | return $projectDescriptorBuilderMock; |
||
130 | } |
||
131 | } |
||
132 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.