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 Graze\CiffRenderer\Test\SimpleXmlElementChainMocker; |
9
|
|
|
|
10
|
|
|
class FieldParserFixedTextTest extends AbstractFieldParserTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var FieldParserFixedText |
14
|
|
|
*/ |
15
|
|
|
private $parser; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @return FieldParserFixedText |
19
|
|
|
*/ |
20
|
|
|
protected function getParser() |
21
|
|
|
{ |
22
|
|
|
if (!$this->parser) { |
23
|
|
|
$this->parser = new FieldParserFixedText(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return $this->parser; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
public function testGetFontSize() |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$size = 3.4; |
32
|
|
|
SimpleXmlElementChainMocker::addChain(['xmlField', 'Text', 'Font', 'Pitch'], $size); |
33
|
|
|
|
34
|
|
|
$this->assertEquals($size, $this->getParser()->getFontSize()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function testGetFontFace() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$face = 'i am face'; |
40
|
|
|
SimpleXmlElementChainMocker::addChain(['xmlField', 'Text', 'Font', 'Face'], $face); |
41
|
|
|
|
42
|
|
|
$this->assertEquals($face, $this->getParser()->getFontFace()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function testGetOrientation() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$orientation = 90; |
48
|
|
|
SimpleXmlElementChainMocker::addChain(['xmlField', 'Orientation'], $orientation); |
49
|
|
|
|
50
|
|
|
$this->assertEquals($orientation, $this->getParser()->getOrientation()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testGetText() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$srcFieldName = 'i am source field'; |
56
|
|
|
$fieldMerge = SimpleXmlElementChainMocker::mock(['fieldMerge']); |
57
|
|
|
$fieldMerge |
|
|
|
|
58
|
|
|
->shouldReceive('__get') |
59
|
|
|
->with('SrcField') |
60
|
|
|
->andReturn($fieldMerge) |
61
|
|
|
->twice() |
62
|
|
|
->shouldReceive('attributes') |
63
|
|
|
->andReturn($fieldMerge) |
64
|
|
|
->once() |
65
|
|
|
->shouldReceive('__get') |
66
|
|
|
->with('SrcFieldName') |
67
|
|
|
->andReturn($srcFieldName) |
68
|
|
|
->once() |
69
|
|
|
->getMock(); |
70
|
|
|
|
71
|
|
|
$fieldMergeText = 'i am merge text'; |
72
|
|
|
$fieldMergeSource = m::mock(FieldParserFixedText::class) |
73
|
|
|
->shouldReceive('getText') |
74
|
|
|
->andReturn($fieldMergeText) |
75
|
|
|
->once() |
76
|
|
|
->getMock(); |
77
|
|
|
|
78
|
|
|
$this->fieldParserRegistry |
|
|
|
|
79
|
|
|
->shouldReceive('getParser') |
80
|
|
|
->with($srcFieldName) |
81
|
|
|
->andReturn($fieldMergeSource) |
82
|
|
|
->once() |
83
|
|
|
->getMock(); |
84
|
|
|
|
85
|
|
|
$fieldStandardText = 'i am standard text'; |
86
|
|
|
$fieldStandard = SimpleXmlElementChainMocker::mock(['fieldStandard']); |
87
|
|
|
SimpleXmlElementChainMocker::addChain(['fieldStandard', 'SrcField'], false); |
88
|
|
|
SimpleXmlElementChainMocker::addChain(['fieldStandard', 'Default'], $fieldStandardText); |
89
|
|
|
|
90
|
|
|
$objects = [$fieldMerge, $fieldStandard]; |
91
|
|
|
SimpleXmlElementChainMocker::addChain(['xmlField', 'Data', 'Object'], $objects); |
92
|
|
|
|
93
|
|
|
$this->assertEquals($fieldMergeText . $fieldStandardText, $this->getParser()->getText()); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.