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

ParserDocumentTest::testGetScale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Test\Unit\Parser;
4
5
use Mockery as m;
6
use \SimpleXMLElement;
7
use Graze\CiffRenderer\Parser\FieldSorter;
8
use Graze\CiffRenderer\Parser\FieldParserFactory;
9
use Graze\CiffRenderer\Parser\FieldParserRegistry;
10
use Graze\CiffRenderer\Parser\ParserDocument;
11
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
12
13
class ParserDocumentTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var SimpleXMLElement
17
     */
18
    private $xml;
19
20
    /**
21
     * @var FieldSorter
22
     */
23
    private $fieldSorter;
24
25
    /**
26
     * @var FieldParserFactory
27
     */
28
    private $fieldParserFactory;
29
30
    /**
31
     * @var FieldParserRegistry
32
     */
33
    private $fieldParserRegistry;
34
35
    /**
36
     * @var ParserDocument
37
     */
38
    private $parserDocument;
39
40
    public function setUp()
41
    {
42
        $this->xml = new SimpleXMLElement(
43
            '<ImageDesign>
44
                <Header>i am header</Header>
45
                <SubImage>
46
                    <SubHeader>
47
                        <XRes>22</XRes>
48
                        <ImageWidth>33</ImageWidth>
49
                        <ImageHeight>11</ImageHeight>
50
                    </SubHeader>
51
                    <Field>
52
                        <FldType>i am type</FldType>
53
                    </Field>
54
                </SubImage>
55
            </ImageDesign>'
56
        );
57
        $this->fieldSorter = m::mock(FieldSorter::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...ser\FieldSorter::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Parser\FieldSorter of property $fieldSorter.

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...
58
        $this->fieldParserFactory = m::mock(FieldParserFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...ldParserFactory::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Parser\FieldParserFactory of property $fieldParserFactory.

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...
59
        $this->fieldParserRegistry = m::mock(fieldParserRegistry::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...dParserRegistry::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Parser\FieldParserRegistry of property $fieldParserRegistry.

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...
60
        $this->parserDocument = new ParserDocument(
61
            $this->fieldSorter,
0 ignored issues
show
Bug introduced by
$this->fieldSorter of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Parser\FieldSorter expected by parameter $fieldSorter of Graze\CiffRenderer\Parse...Document::__construct(). ( Ignorable by Annotation )

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

61
            /** @scrutinizer ignore-type */ $this->fieldSorter,
Loading history...
62
            $this->fieldParserFactory,
0 ignored issues
show
Bug introduced by
$this->fieldParserFactory of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Parser\FieldParserFactory expected by parameter $fieldParserFactory of Graze\CiffRenderer\Parse...Document::__construct(). ( Ignorable by Annotation )

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

62
            /** @scrutinizer ignore-type */ $this->fieldParserFactory,
Loading history...
63
            $this->fieldParserRegistry
0 ignored issues
show
Bug introduced by
$this->fieldParserRegistry of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Parser\FieldParserRegistry expected by parameter $fieldParserRegistry of Graze\CiffRenderer\Parse...Document::__construct(). ( Ignorable by Annotation )

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

63
            /** @scrutinizer ignore-type */ $this->fieldParserRegistry
Loading history...
64
        );
65
    }
66
67
    public function testGetFieldParsers()
68
    {
69
        $subImage = (array) $this->xml->SubImage; // @codingStandardsIgnoreLine
70
        $field = $subImage['Field'];
71
        $fields = [$field];
72
73
        $this->fieldSorter
74
            ->shouldReceive('sort')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\CiffRenderer\Parser\FieldSorter. ( Ignorable by Annotation )

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

74
            ->/** @scrutinizer ignore-call */ 
75
              shouldReceive('sort')

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...
75
            ->with(equalTo($fields))
76
            ->once()
77
            ->getMock();
78
79
        $fieldParser = m::mock(FieldParserInterface::class)
80
            ->shouldReceive('parse')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'parse'. ( Ignorable by Annotation )

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

80
            ->/** @scrutinizer ignore-call */ shouldReceive('parse')

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...
81
            ->with($this->fieldParserRegistry, equalTo($field), equalTo($this->xml->Header), 22)
82
            ->once()
83
            ->getMock();
84
85
        $this->fieldParserFactory
86
            ->shouldReceive('getFieldParser')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\CiffRenderer\Parser\FieldParserFactory. ( Ignorable by Annotation )

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

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

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...
87
            ->with('i am type')
88
            ->andReturn($fieldParser)
89
            ->once()
90
            ->getMock();
91
92
        $fieldParsers = $this->parserDocument->getFieldParsers($this->xml);
93
94
        $this->assertEquals([$fieldParser], $fieldParsers);
95
    }
96
97
    public function testGetWidth()
98
    {
99
        $expected = 726; // scale * width
100
        $actual = $this->parserDocument->getWidth($this->xml);
101
        $this->assertEquals($expected, $actual);
102
    }
103
104
    public function testGetHeight()
105
    {
106
        $expected = 242; // scale * height
107
        $actual = $this->parserDocument->getHeight($this->xml);
108
        $this->assertEquals($expected, $actual);
109
    }
110
111
    public function testGetScale()
112
    {
113
        $expected = 22;
114
        $actual = $this->parserDocument->getScale($this->xml);
115
        $this->assertEquals($expected, $actual);
116
    }
117
}
118