Completed
Push — develop ( 8eb671...133594 )
by Mike
19:30 queued 09:24
created

Descriptor/Builder/Reflector/FileAssemblerTest.php (1 issue)

Upgrade to new PHP Analysis Engine

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-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\Collection;
18
use phpDocumentor\Descriptor\PackageDescriptor;
19
20
use phpDocumentor\Reflection\DocBlock;
21
use phpDocumentor\Reflection\Php\File;
22
23
/**
24
 * Test class for \phpDocumentor\Descriptor\Builder
25
 *
26
 * @covers \phpDocumentor\Descriptor\Builder\Reflector\FileAssembler
27
 */
28
class FileAssemblerTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
29
{
30
    /** @var FileAssembler $fixture */
31
    protected $fixture;
32
33
    /** @var PackageDescriptor */
34
    private $defaultPackage;
35
36
    /**
37
     * Creates a new fixture to test with.
38
     */
39
    protected function setUp()
40
    {
41
        $this->fixture = new FileAssembler();
42
        $this->fixture->setBuilder($this->getProjectDescriptorBuilderMock());
43
        $this->defaultPackage = new PackageDescriptor();
44
        $this->defaultPackage->setName('\\PhpDocumentor');
45
    }
46
47
    /**
48
     * Creates a Descriptor from a provided class.
49
     */
50
    public function testCreateFileDescriptorFromReflector()
51
    {
52
        $filename = 'file.php';
53
        $content = '<?php ... ?>';
54
        $hash = md5($content);
55
56
        $abstractDescriptor = m::mock('phpDocumentor\Descriptor\DescriptorAbstract');
57
        $abstractDescriptor->shouldReceive('getLineNumber')->andReturn(1337);
58
59
        $docBlockDescription = new DocBlock\Description(
60
            <<<DOCBLOCK
61
            /**
62
             * This is a example description
63
             */
64
DOCBLOCK
65
        );
66
67
        $docBlockMock = new DocBlock('This is a example description', $docBlockDescription);
68
69
        $fileReflectorMock = new File($hash, $filename, $content, $docBlockMock);
70
//        $fileReflectorMock->shouldReceive('getConstants')->once()->andReturn(
71
//            new Collection(array($abstractDescriptor))
72
//        );
73
//
74
//        $fileReflectorMock->shouldReceive('getFunctions')->once()->andReturn(
75
//            new Collection(array($abstractDescriptor))
76
//        );
77
//
78
//        $fileReflectorMock->shouldReceive('getClasses')->once()->andReturn(
79
//            new Collection(array($abstractDescriptor))
80
//        );
81
//
82
//        $fileReflectorMock->shouldReceive('getInterfaces')->once()->andReturn(
83
//            new Collection(array($abstractDescriptor))
84
//        );
85
//
86
//        $fileReflectorMock->shouldReceive('getTraits')->once()->andReturn(
87
//            new Collection(array($abstractDescriptor))
88
//        );
89
//
90
//        $fileReflectorMock->shouldReceive('getMarkers')->once()->andReturn(
91
//            array('type', 'message', 1337)
92
//        );
93
//
94
//        $fileReflectorMock->shouldReceive('getIncludes')->andReturn(new Collection);
95
//        $fileReflectorMock->shouldReceive('getNamespaceAliases')->andReturn(new Collection);
96
97
        $descriptor = $this->fixture->create($fileReflectorMock);
98
99
        $this->assertSame($filename, $descriptor->getName());
100
        $this->assertSame($hash, $descriptor->getHash());
101
        $this->assertSame($content, $descriptor->getSource());
102
        //TODO: check this when we are testing default package behavoir
103
        //$this->assertSame($this->defaultPackage, $descriptor->getPackage());
104
    }
105
106
    /**
107
     * Create a descriptor builder mock
108
     *
109
     * @return m\MockInterface
110
     */
111
    protected function getProjectDescriptorBuilderMock()
112
    {
113
        $projectDescriptorBuilderMock = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder');
114
        $projectDescriptorBuilderMock->shouldReceive('getDefaultPackage')
115
            ->andReturn($this->defaultPackage);
116
117
        $projectDescriptorBuilderMock->shouldReceive(
118
            'getProjectDescriptor->getSettings->shouldIncludeSource'
119
        )->andReturn(true);
120
        $projectDescriptorBuilderMock->shouldReceive('buildDescriptor')->andReturnUsing(function ($param) {
0 ignored issues
show
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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')
125
                ->once()
126
                ->andReturn('Frank_is_een_eindbaas');
127
128
            return $mock;
129
        });
130
131
        return $projectDescriptorBuilderMock;
132
    }
133
}
134