Test Failed
Push — master ( 72a6c5...9329b7 )
by Arun
03:52
created

DescriptionFactoryTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 152
Duplicated Lines 36.18 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 55
loc 152
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testDescriptionCanParseASimpleString() 10 10 1
A testEscapeSequences() 10 10 1
A testDescriptionCanParseAStringWithInlineTag() 0 16 1
A testDescriptionCanParseAStringStartingWithInlineTag() 0 16 1
B testIfSuperfluousStartingSpacesAreRemoved() 35 35 1
A provideSimpleExampleDescriptions() 0 9 1
A provideEscapeSequences() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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-2015 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\Reflection\DocBlock;
14
15
use Mockery as m;
16
use phpDocumentor\Reflection\DocBlock\Tags\Link;
17
use phpDocumentor\Reflection\Types\Context;
18
19
/**
20
 * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\DescriptionFactory
21
 * @covers ::<private>
22
 */
23
class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @covers ::__construct
27
     * @covers ::create
28
     * @uses         phpDocumentor\Reflection\DocBlock\Description
29
     * @dataProvider provideSimpleExampleDescriptions
30
     */
31 View Code Duplication
    public function testDescriptionCanParseASimpleString($contents)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $tagFactory = m::mock(TagFactory::class);
34
        $tagFactory->shouldReceive('create')->never();
35
36
        $factory     = new DescriptionFactory($tagFactory);
37
        $description = $factory->create($contents, new Context(''));
38
39
        $this->assertSame($contents, $description->render());
40
    }
41
42
    /**
43
     * @covers ::__construct
44
     * @covers ::create
45
     * @uses         phpDocumentor\Reflection\DocBlock\Description
46
     * @dataProvider provideEscapeSequences
47
     */
48 View Code Duplication
    public function testEscapeSequences($contents, $expected)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $tagFactory = m::mock(TagFactory::class);
51
        $tagFactory->shouldReceive('create')->never();
52
53
        $factory     = new DescriptionFactory($tagFactory);
54
        $description = $factory->create($contents, new Context(''));
55
56
        $this->assertSame($expected, $description->render());
57
    }
58
59
    /**
60
     * @covers ::__construct
61
     * @covers ::create
62
     * @uses   phpDocumentor\Reflection\DocBlock\Description
63
     * @uses   phpDocumentor\Reflection\DocBlock\Tags\Link
64
     * @uses   phpDocumentor\Reflection\DocBlock\Tags\BaseTag
65
     * @uses   phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
66
     * @uses   phpDocumentor\Reflection\Types\Context
67
     */
68
    public function testDescriptionCanParseAStringWithInlineTag()
69
    {
70
        $contents   = 'This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.';
71
        $context    = new Context('');
72
        $tagFactory = m::mock(TagFactory::class);
73
        $tagFactory->shouldReceive('create')
74
            ->once()
75
            ->with('@link http://phpdoc.org/ description', $context)
76
            ->andReturn(new Link('http://phpdoc.org/', new Description('description')))
77
        ;
78
79
        $factory     = new DescriptionFactory($tagFactory);
80
        $description = $factory->create($contents, $context);
81
82
        $this->assertSame($contents, $description->render());
83
    }
84
85
    /**
86
     * @covers ::__construct
87
     * @covers ::create
88
     * @uses   phpDocumentor\Reflection\DocBlock\Description
89
     * @uses   phpDocumentor\Reflection\DocBlock\Tags\Link
90
     * @uses   phpDocumentor\Reflection\DocBlock\Tags\BaseTag
91
     * @uses   phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
92
     * @uses   phpDocumentor\Reflection\Types\Context
93
     */
94
    public function testDescriptionCanParseAStringStartingWithInlineTag()
95
    {
96
        $contents   = '{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.';
97
        $context    = new Context('');
98
        $tagFactory = m::mock(TagFactory::class);
99
        $tagFactory->shouldReceive('create')
100
            ->once()
101
            ->with('@link http://phpdoc.org/ This', $context)
102
            ->andReturn(new Link('http://phpdoc.org/', new Description('This')))
103
        ;
104
105
        $factory     = new DescriptionFactory($tagFactory);
106
        $description = $factory->create($contents, $context);
107
108
        $this->assertSame($contents, $description->render());
109
    }
110
111
    /**
112
     * @covers ::__construct
113
     * @covers ::create
114
     * @uses   phpDocumentor\Reflection\DocBlock\Description
115
     */
116 View Code Duplication
    public function testIfSuperfluousStartingSpacesAreRemoved()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $factory         = new DescriptionFactory(m::mock(TagFactory::class));
119
        $descriptionText = <<<DESCRIPTION
120
This is a multiline
121
  description that you commonly
122
  see with tags.
123
124
      It does have a multiline code sample
125
      that should align, no matter what
126
127
  All spaces superfluous spaces on the
128
  second and later lines should be
129
  removed but the code sample should
130
  still be indented.
131
DESCRIPTION;
132
133
        $expectedDescription = <<<DESCRIPTION
134
This is a multiline
135
description that you commonly
136
see with tags.
137
138
    It does have a multiline code sample
139
    that should align, no matter what
140
141
All spaces superfluous spaces on the
142
second and later lines should be
143
removed but the code sample should
144
still be indented.
145
DESCRIPTION;
146
147
        $description = $factory->create($descriptionText, new Context(''));
148
149
        $this->assertSame($expectedDescription, $description->render());
150
    }
151
152
    /**
153
     * Provides a series of example strings that the parser should correctly interpret and return.
154
     *
155
     * @return string[][]
156
     */
157
    public function provideSimpleExampleDescriptions()
158
    {
159
        return [
160
            ['This is text for a description.'],
161
            ['This is text for a description containing { that is literal.'],
162
            ['This is text for a description containing } that is literal.'],
163
            ['This is text for a description with {just a text} that is not a tag.'],
164
        ];
165
    }
166
167
    public function provideEscapeSequences()
168
    {
169
        return [
170
            ['This is text for a description with a {@}.', 'This is text for a description with a @.'],
171
            ['This is text for a description with a {}.', 'This is text for a description with a }.'],
172
        ];
173
    }
174
}
175