MethodAssemblerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 12
dl 0
loc 114
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testCreateMethodDescriptorFromVariousNotations() 0 19 2
B provideNotations() 0 60 1
1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Descriptor\Builder\Reflector\Tags;
13
14
use Mockery as m;
15
use phpDocumentor\Descriptor\ProjectDescriptorBuilder;
16
use phpDocumentor\Reflection\DocBlock\Description;
17
use phpDocumentor\Reflection\DocBlock\Tags\Method;
18
use phpDocumentor\Reflection\Types\Boolean;
19
use phpDocumentor\Reflection\Types\Integer;
20
use phpDocumentor\Reflection\Types\Mixed_;
21
use phpDocumentor\Reflection\Types\String_;
22
use phpDocumentor\Reflection\Types\Void_;
23
24
class MethodAssemblerTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
25
{
26
    /** @var MethodAssembler */
27
    private $fixture;
28
29
    /** @var m\MockInterface|ProjectDescriptorBuilder */
30
    protected $builder;
31
32
    /**
33
     * Initialize fixture with its dependencies.
34
     */
35
    protected function setUp()
36
    {
37
        $this->builder = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder');
38
        $this->fixture = new MethodAssembler();
39
        $this->fixture->setBuilder($this->builder);
40
    }
41
42
    /**
43
     * @param string   $returnType
44
     * @param string   $name
45
     * @param string[] $arguments
46
     * @param string   $description
47
     *
48
     * @dataProvider provideNotations
49
     * @covers \phpDocumentor\Descriptor\Builder\Reflector\Tags\MethodAssembler::create
50
     * @covers \phpDocumentor\Descriptor\Builder\Reflector\Tags\MethodAssembler::createArgumentDescriptorForMagicMethod
51
     */
52
    public function testCreateMethodDescriptorFromVariousNotations(
53
        $returnType,
54
        $name,
55
        $arguments = [],
56
        $description = null
57
    ) {
58
        $tag = new Method($name, $arguments, $returnType, false, $description);
59
60
        $descriptor = $this->fixture->create($tag);
61
62
        $this->assertEquals($returnType, $descriptor->getResponse()->getType());
63
        $this->assertSame($name, $descriptor->getMethodName());
64
        $this->assertSame($description, $descriptor->getDescription());
65
        $this->assertSame(count($arguments), $descriptor->getArguments()->count());
66
        foreach ($arguments as $argument) {
67
            $this->assertSame($argument['type'], $descriptor->getArguments()->get($argument['name'])->getType());
68
            $this->assertSame($argument['name'], $descriptor->getArguments()->get($argument['name'])->getName());
69
        }
70
    }
71
72
    /**
73
     * Test several different notations for the magic method.
74
     *
75
     * @return string[][]
76
     */
77
    public function provideNotations()
78
    {
79
        return [
80
            // just a method without a return type
81
            [new Void_(), 'myMethod'],
82
83
            // a method with two arguments
84
            [
85
                new Void_(),
86
                'myMethod',
87
                [
88
                    ['name' => '$argument1', 'type' => new Mixed_()],
89
                    ['name' => '$argument2', 'type' => new Mixed_()],
90
                ],
91
            ],
92
93
            // a method with two arguments without dollar sign
94
            [
95
                new Void_(),
96
                'myMethod',
97
                [
98
                    ['name' => '$argument1', 'type' => new Mixed_()],
99
                    ['name' => '$argument2', 'type' => new Mixed_()],
100
                ],
101
            ],
102
103
            // a method without return type, but with 2 arguments and a description
104
            [
105
                new Void_(),
106
                'myMethod',
107
                [
108
                    ['name' => '$argument1', 'type' => new Mixed_()],
109
                    ['name' => '$argument2', 'type' => new Mixed_()],
110
                ],
111
                new Description('This is a description.'),
112
            ],
113
114
            // a method without return type, but with 2 arguments (with types) and a description
115
            [
116
                new Void_(),
117
                'myMethod',
118
                [
119
                    ['name' => '$argument1', 'type' => new Boolean()],
120
                    ['name' => '$argument2', 'type' => new String_()],
121
                ],
122
                new Description('This is a description.'),
123
            ],
124
125
            // a method with return type, 2 arguments (with types) and a description
126
            [
127
                new Integer(),
128
                'myMethod',
129
                [
130
                    ['name' => '$argument1', 'type' => new Boolean()],
131
                    ['name' => '$argument2', 'type' => new String_()],
132
                ],
133
                new Description('This is a description.'),
134
            ],
135
        ];
136
    }
137
}
138