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); |
|
|
|
|
58
|
|
|
$this->fieldParserFactory = m::mock(FieldParserFactory::class); |
|
|
|
|
59
|
|
|
$this->fieldParserRegistry = m::mock(fieldParserRegistry::class); |
|
|
|
|
60
|
|
|
$this->parserDocument = new ParserDocument( |
61
|
|
|
$this->fieldSorter, |
|
|
|
|
62
|
|
|
$this->fieldParserFactory, |
|
|
|
|
63
|
|
|
$this->fieldParserRegistry |
|
|
|
|
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') |
|
|
|
|
75
|
|
|
->with(equalTo($fields)) |
76
|
|
|
->once() |
77
|
|
|
->getMock(); |
78
|
|
|
|
79
|
|
|
$fieldParser = m::mock(FieldParserInterface::class) |
80
|
|
|
->shouldReceive('parse') |
|
|
|
|
81
|
|
|
->with($this->fieldParserRegistry, equalTo($field), equalTo($this->xml->Header), 22) |
82
|
|
|
->once() |
83
|
|
|
->getMock(); |
84
|
|
|
|
85
|
|
|
$this->fieldParserFactory |
86
|
|
|
->shouldReceive('getFieldParser') |
|
|
|
|
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
|
|
|
|
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..