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\FieldParserDate; |
8
|
|
|
use \SimpleXMLElement; |
9
|
|
|
use \DateTimeImmutable; |
10
|
|
|
use Graze\CiffRenderer\DateFormatter\DateFormatterInterface; |
11
|
|
|
use Graze\CiffRenderer\DateFormatter\DateFormatterFactory; |
12
|
|
|
|
13
|
|
|
class FieldParserDateTest extends AbstractFieldParserTest |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var DateTimeImmutable |
17
|
|
|
*/ |
18
|
|
|
private $dateTimeNow; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var DateFormatterFactory |
22
|
|
|
*/ |
23
|
|
|
private $dateFormatterFactory; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->dateTimeNow = m::mock(DateTimeImmutable::class); |
|
|
|
|
28
|
|
|
$this->dateFormatterFactory = m::mock(DateFormatterFactory::class); |
|
|
|
|
29
|
|
|
|
30
|
|
|
parent::setUp(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return SimpleXMLElement |
35
|
|
|
*/ |
36
|
|
|
private function getXmlField() |
37
|
|
|
{ |
38
|
|
|
return new SimpleXMLElement( |
39
|
|
|
'<Field Name="i am field name"> |
40
|
|
|
<FldType>DateText</FldType> |
41
|
|
|
<Displayed>1</Displayed> |
42
|
|
|
<X>4200</X> |
43
|
|
|
<Y>250</Y> |
44
|
|
|
<W>3775</W> |
45
|
|
|
<H>450</H> |
46
|
|
|
<CalcData><![CDATA[212]]></CalcData> |
47
|
|
|
<Data> |
48
|
|
|
<Object Static="0" Parse="1"> |
49
|
|
|
<DataType>2</DataType> |
50
|
|
|
<Default><![CDATA[i am date format]]></Default> |
51
|
|
|
</Object> |
52
|
|
|
</Data> |
53
|
|
|
<Text> |
54
|
|
|
<Font> |
55
|
|
|
<Pitch>10</Pitch> |
56
|
|
|
</Font> |
57
|
|
|
</Text> |
58
|
|
|
</Field>' |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
return $this->xmlField; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return FieldParserDate |
66
|
|
|
*/ |
67
|
|
|
protected function getParser() |
68
|
|
|
{ |
69
|
|
|
if (!$this->parser) { |
70
|
|
|
$this->parser = new FieldParserDate( |
|
|
|
|
71
|
|
|
$this->dateTimeNow, |
72
|
|
|
$this->dateFormatterFactory, |
73
|
|
|
$this->fieldParserRegistry, |
74
|
|
|
$this->xmlHeader, |
75
|
|
|
$this->getXmlField(), |
76
|
|
|
$this->scale |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->parser; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGetText() |
84
|
|
|
{ |
85
|
|
|
$dateFormat = 'i am date format'; |
86
|
|
|
|
87
|
|
|
$text = 'i am text'; |
88
|
|
|
$dateFormatter = m::mock(DateFormatterInterface::class) |
89
|
|
|
->shouldReceive('format') |
|
|
|
|
90
|
|
|
->with($this->dateTimeNow, $dateFormat) |
91
|
|
|
->andReturn($text) |
92
|
|
|
->once() |
93
|
|
|
->getMock(); |
94
|
|
|
$this->dateFormatterFactory |
95
|
|
|
->shouldReceive('getFormatter') |
|
|
|
|
96
|
|
|
->with($dateFormat) |
97
|
|
|
->andReturn($dateFormatter) |
98
|
|
|
->getMock(); |
99
|
|
|
|
100
|
|
|
$this->assertEquals($text, $this->parser->getText()); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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..