Completed
Push — master ( fd3130...674c45 )
by John
03:39
created

FieldParserFixedTextTest::getXmlField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 29
nc 1
nop 0
dl 0
loc 4
rs 9.456
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Test\Parser\FieldParser;
4
5
use Mockery as m;
6
use Graze\CiffRenderer\Test\AbstractFieldParserTest;
7
use Graze\CiffRenderer\Parser\FieldParser\FieldParserFixedText;
8
use \SimpleXMLElement;
9
10
class FieldParserFixedTextTest extends AbstractFieldParserTest
11
{
12
    /**
13
     * @var FieldParserFixedText
14
     */
15
    private $parser;
16
17
    /**
18
     * @return SimpleXMLElement
19
     */
20
    protected function getXmlField()
21
    {
22
        return new SimpleXMLElement(
23
            '<Field Name="i am field name">
24
                <FldType>MergeField</FldType>
25
                <X>4200</X>
26
                <Y>250</Y>
27
                <W>3775</W>
28
                <H>450</H>
29
                <Ln>1</Ln>
30
                <CalcData><![CDATA[8788888]]></CalcData>
31
                <Data>
32
                    <Object>
33
                        <DataType>5</DataType>
34
                        <Default><![CDATA[212]]></Default>
35
                        <SrcField SrcFieldName="i am source name 1"/>
36
                    </Object>
37
                    <Object Index="1">
38
                        <DataType>5</DataType>
39
                        <Default><![CDATA[1310]]></Default>
40
                        <SrcField SrcFieldName="i am source name 2"/>
41
                    </Object>
42
                </Data>
43
                <Text>
44
                    <Font>
45
                        <Face><![CDATA[i am font face]]></Face>
46
                        <Pitch>5</Pitch>
47
                    </Font>
48
                </Text>
49
                <Orientation>90</Orientation>
50
            </Field>'
51
        );
52
    }
53
54
    /**
55
     * @return FieldParserFixedText
56
     */
57
    protected function getParser()
58
    {
59
        if (!$this->parser) {
60
            $this->parser = new FieldParserFixedText();
61
        }
62
63
        return $this->parser;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parser returns the type Graze\CiffRenderer\Parse...er\FieldParserFixedText which is incompatible with the return type mandated by Graze\CiffRenderer\Test\...ParserTest::getParser() of Graze\CiffRenderer\Test\...er\FieldParserInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
64
    }
65
66
    public function testGetFontSize()
67
    {
68
        $expected = 21; // pitch * FieldParserFixedText::FONT_SIZE_MULTIPLIER
69
        $this->assertEquals($expected, $this->getParser()->getFontSize());
70
    }
71
72
    public function testGetFontFace()
73
    {
74
        $face = 'i am font face';
75
        $this->assertEquals($face, $this->getParser()->getFontFace());
76
    }
77
78
    public function testGetOrientation()
79
    {
80
        $orientation = 90;
81
        $this->assertEquals($orientation, $this->getParser()->getOrientation());
82
    }
83
84
    public function testGetText()
85
    {
86
        $fieldMergeSource1 = m::mock(FieldParserFixedText::class)
87
            ->shouldReceive('getText')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getText'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
            ->/** @scrutinizer ignore-call */ shouldReceive('getText')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
88
            ->andReturn('i am text 1 ')
89
            ->once()
90
            ->getMock();
91
        $fieldMergeSource2 = m::mock(FieldParserFixedText::class)
92
            ->shouldReceive('getText')
93
            ->andReturn('and i am text 2')
94
            ->once()
95
            ->getMock();
96
97
        $this->fieldParserRegistry
98
            ->shouldReceive('getParser')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\CiffRenderer\Parser\FieldParserRegistry. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
            ->/** @scrutinizer ignore-call */ 
99
              shouldReceive('getParser')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
            ->with('i am source name 1')
100
            ->andReturn($fieldMergeSource1)
101
            ->once()
102
            ->shouldReceive('getParser')
103
            ->with('i am source name 2')
104
            ->andReturn($fieldMergeSource2)
105
            ->once()
106
            ->getMock();
107
108
        $expected = 'i am text 1 and i am text 2';
109
        $this->assertEquals($expected, $this->getParser()->getText());
110
    }
111
}
112