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

FieldParserBarcodeTest::testGetText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nc 1
nop 0
dl 0
loc 34
rs 9.504
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\BarcodeGenerator\BarcodeGeneratorFactory;
8
use Graze\CiffRenderer\BarcodeGenerator\BarcodeGeneratorInterface;
9
use Graze\CiffRenderer\Parser\FieldParser\FieldParserBarcode;
10
use \SimpleXMLElement;
11
12
class FieldParserBarcodeTest extends AbstractFieldParserTest
13
{
14
    /**
15
     * @var BarcodeGeneratorFactory
16
     */
17
    private $barcodeGeneratorFactory;
18
19
    /**
20
     * @var FieldParserBarcode
21
     */
22
    private $parser;
23
24
    public function setUp()
25
    {
26
        $this->barcodeGeneratorFactory = m::mock(BarcodeGeneratorFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...eneratorFactory::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Barco...BarcodeGeneratorFactory of property $barcodeGeneratorFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
        parent::setUp();
28
    }
29
30
    /**
31
     * @return SimpleXMLElement
32
     */
33
    protected function getXmlField()
34
    {
35
        return new SimpleXMLElement(
36
            '<Field Name="i am field name">
37
                <FldType>Barcode</FldType>
38
                <CLSID>{7A4AA4CF-F5CD-11D4-8DAE-0050DAFE8A9F}</CLSID>
39
                <Inverse>1</Inverse>
40
                <X>4200</X>
41
                <Y>250</Y>
42
                <W>3775</W>
43
                <H>450</H>
44
                <Ln>1</Ln>
45
                <CalcData><![CDATA[0501234567890]]></CalcData>
46
                <Data>
47
                    <Object>
48
                        <DataType>5</DataType>
49
                        <Default><![CDATA[30]]></Default>
50
                        <SrcField SrcFieldName="merge_field_name"/>
51
                    </Object>
52
                </Data>
53
                <Barcode>
54
                    <BcH>450</BcH>
55
                    <HR>
56
                        <HRFont>
57
                            <Family>DontCare</Family>
58
                            <Pitch>33</Pitch>
59
                        </HRFont>
60
                    </HR>
61
                    <CheckDigit>1</CheckDigit>
62
                    <EAN13/>
63
                </Barcode>
64
                <Orientation>90</Orientation>
65
            </Field>'
66
        );
67
    }
68
69
    /**
70
     * @return FieldParserBarcode
71
     */
72
    protected function getParser()
73
    {
74
        if (!$this->parser) {
75
            $this->parser = new FieldParserBarcode(
76
                $this->barcodeGeneratorFactory
77
            );
78
        }
79
80
        return $this->parser;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parser returns the type Graze\CiffRenderer\Parse...rser\FieldParserBarcode 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...
81
    }
82
83
    public function testGetFontSize()
84
    {
85
        $size = 33;
86
        $this->assertEquals($size, $this->getParser()->getFontSize());
87
    }
88
89
    public function testGetOrientation()
90
    {
91
        $orientation = 90;
92
        $this->assertEquals($orientation, $this->getParser()->getOrientation());
93
    }
94
95
    public function testGetText()
96
    {
97
        $mergedText = 'i am erged text';
98
        $barcodeText = 'i am barcode text';
99
100
        $barcodeGenerator = m::mock(BarcodeGeneratorInterface::class)
101
            ->shouldReceive('generate')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'generate'. ( Ignorable by Annotation )

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

101
            ->/** @scrutinizer ignore-call */ shouldReceive('generate')

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...
102
            ->with($mergedText)
103
            ->andReturn($barcodeText)
104
            ->once()
105
            ->getMock();
106
107
        $this->barcodeGeneratorFactory
108
            ->shouldReceive('getGenerator')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\CiffRenderer\Barco...BarcodeGeneratorFactory. ( Ignorable by Annotation )

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

108
            ->/** @scrutinizer ignore-call */ 
109
              shouldReceive('getGenerator')

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...
109
            ->andReturn($barcodeGenerator)
110
            ->once()
111
            ->getMock();
112
113
        // barcode is a merge field so text will be fetched from other parsers, mock them
114
        $parserMergeField = m::mock(FieldParserInterface::class)
0 ignored issues
show
Bug introduced by
The type Graze\CiffRenderer\Test\...er\FieldParserInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
115
            ->shouldReceive('getText')
116
            ->withNoArgs()
117
            ->andReturn($mergedText)
118
            ->once()
119
            ->getMock();
120
121
        $this->fieldParserRegistry
122
            ->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

122
            ->/** @scrutinizer ignore-call */ 
123
              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...
123
            ->with('merge_field_name')
124
            ->andReturn($parserMergeField)
125
            ->once()
126
            ->getMock();
127
128
        $this->assertEquals($barcodeText, $this->getParser()->getText());
129
    }
130
131
    public function testGetIsInverse()
132
    {
133
        $isInverse = true;
134
        $this->assertEquals($isInverse, $this->getParser()->getIsInverse());
135
    }
136
}
137