Completed
Push — develop ( 9193e7...62056c )
by Jaap
12:45 queued 02:43
created

PropertyAssemblerTest::givenADocBlockObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 1
b 0
f 0
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
0 ignored issues
show
Bug introduced by
It seems like $docBlockMock defined by parameter $docBlockMock on line 81 can also be of type object<Mockery\MockInterface>; however, phpDocumentor\Reflection...Property::__construct() does only seem to accept null|object<phpDocumentor\Reflection\DocBlock>, maybe add an additional type check?

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.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$docBlockMock is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
108
    }
109
}
110