Completed
Pull Request — master (#17)
by John
03:40
created

DateBuilderTest::testBuild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 43

Duplication

Lines 52
Ratio 100 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 52
loc 52
rs 9.4929
cc 1
eloc 43
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Graze\CiffRenderer\Test\Builder;
4
5
use \Mockery as m;
6
use Graze\CiffRenderer\Field\Builder\DateBuilder;
7
use Graze\CiffRenderer\Field\Parser\DateParser\DateParser;
8
use Graze\CiffRenderer\Field\Renderer\FixedTextRenderer;
9
use Graze\CiffRenderer\Field\Parser\ParserManager;
10
use Intervention\Image\ImageManager;
11
use \SimpleXMLElement;
12
13 View Code Duplication
class DateBuilderTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    public function testBuild()
16
    {
17
        $parserManager = m::mock(ParserManager::class);
18
        $imageManager = m::mock(ImageManager::class);
19
        $xmlField = new SimpleXMLElement('<a/>');
20
        $scale = 10;
21
        $tracerColour = '#ccc';
22
        $fontResolver = function () {
23
        };
24
25
        $parser = m::mock(DateParser::class)
26
            ->shouldReceive('setXmlField')
27
            ->with($xmlField)
28
            ->shouldReceive('setParserManager')
29
            ->with($parserManager)
30
            ->getMock();
31
32
        $parserManager
33
            ->shouldReceive('addParser')
34
            ->with($parser);
35
36
        $renderer = m::mock(FixedTextRenderer::class)
37
            ->shouldReceive('setParser')
38
            ->with($parser)
39
            ->shouldReceive('setImageManager')
40
            ->with($imageManager)
41
            ->shouldReceive('setScale')
42
            ->with($scale)
43
            ->shouldReceive('setTracerColour')
44
            ->with($tracerColour)
45
            ->shouldReceive('setFontResolver')
46
            ->with($fontResolver)
47
            ->getMock();
48
49
        $builder = m::mock(DateBuilder::class)
50
            ->shouldAllowMockingProtectedMethods()
51
            ->shouldReceive('instantiateParser')
52
            ->andReturn($parser)
53
            ->shouldReceive('instantiateRenderer')
54
            ->andReturn($renderer)
55
            ->getMock()
56
            ->makePartial();
57
58
        $builder->setParserManager($parserManager);
59
        $builder->setImageManager($imageManager);
60
        $builder->setXmlField($xmlField);
61
        $builder->setScale($scale);
62
        $builder->setTracerColour($tracerColour);
63
        $builder->setFontResolver($fontResolver);
64
65
        $this->assertSame($renderer, $builder->build());
66
    }
67
}
68