Completed
Push — master ( 674c45...3a5716 )
by John
02:35
created

FieldParserDateOffsetTest::getParser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 2
nop 0
dl 0
loc 25
rs 9.7
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\Parser\FieldParser\FieldParserDateOffset;
8
use \SimpleXMLElement;
9
use \DateTimeImmutable;
10
use Graze\CiffRenderer\DateFormatter\DateFormatterInterface;
11
use Graze\CiffRenderer\DateFormatter\DateFormatterFactory;
12
13
class FieldParserDateOffsetTest 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);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(DateTimeImmutable::class) of type Mockery\MockInterface is incompatible with the declared type DateTimeImmutable of property $dateTimeNow.

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

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...
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>OffsetDateText</FldType>
41
                <Displayed>1</Displayed>
42
                <X>4200</X>
43
                <Y>250</Y>
44
                <W>3775</W>
45
                <H>450</H>
46
                <Ln>1</Ln>
47
                <CalcData><![CDATA[31/07/18]]></CalcData>
48
                <Data>
49
                    <Object Static="0" Parse="1">
50
                        <DataType>3</DataType>
51
                        <Default><![CDATA[i am date format]]></Default>
52
                        <OffsetDate SrcOffset="lifetime"/>
53
                    </Object>
54
                </Data>
55
                <Text>
56
                    <Font>
57
                        <Pitch>10</Pitch>
58
                    </Font>
59
                </Text>
60
            </Field>'
61
        );
62
    }
63
64
    /**
65
     * @return FieldParserDateOffset
66
     */
67
    protected function getParser()
68
    {
69
        if (!$this->parser) {
70
            // we require a more complex header for this test as the DateOffset is used
71
            $xmlHeader = new SimpleXMLElement(
72
                '<Header>
73
                    <DateOffset Name="lifetime">
74
                        <DefaultOffset>
75
                            <Day>130</Day>
76
                        </DefaultOffset>
77
                    </DateOffset>
78
                </Header>'
79
            );
80
81
            $this->parser = new FieldParserDateOffset(
0 ignored issues
show
Documentation Bug introduced by
It seems like new Graze\CiffRenderer\P...lField(), $this->scale) of type Graze\CiffRenderer\Parse...r\FieldParserDateOffset is incompatible with the declared type Graze\CiffRenderer\Test\FieldParserInterface of property $parser.

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...
82
                $this->dateTimeNow,
83
                $this->dateFormatterFactory,
84
                $this->fieldParserRegistry,
85
                $xmlHeader,
86
                $this->getXmlField(),
87
                $this->scale
88
            );
89
        }
90
91
        return $this->parser;
92
    }
93
94
    public function testGetText()
95
    {
96
        $offsetFieldName = 'i am offset field name';
0 ignored issues
show
Unused Code introduced by
The assignment to $offsetFieldName is dead and can be removed.
Loading history...
97
        $offsetDays = 130;
98
        $offset = new \DateInterval('P' . $offsetDays . 'D');
99
100
        $dateOffset = m::mock(\DateTime::class);
101
        $this->dateTimeNow
102
            ->shouldReceive('add')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on DateTimeImmutable. ( Ignorable by Annotation )

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

102
            ->/** @scrutinizer ignore-call */ 
103
              shouldReceive('add')

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...
103
            ->with(equalTo($offset))
104
            ->andReturn($dateOffset)
105
            ->once()
106
            ->getMock();
107
108
        $dateFormat = 'i am date format';
109
110
        $text = 'i am text';
111
        $dateFormatter = m::mock(DateFormatterInterface::class)
112
            ->shouldReceive('format')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'format'. ( Ignorable by Annotation )

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

112
            ->/** @scrutinizer ignore-call */ shouldReceive('format')

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...
113
            ->with($dateOffset, $dateFormat)
114
            ->andReturn($text)
115
            ->once()
116
            ->getMock();
117
118
        $this->dateFormatterFactory
119
            ->shouldReceive('getFormatter')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\CiffRenderer\DateF...er\DateFormatterFactory. ( Ignorable by Annotation )

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

119
            ->/** @scrutinizer ignore-call */ 
120
              shouldReceive('getFormatter')

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...
120
            ->with($dateFormat)
121
            ->andReturn($dateFormatter)
122
            ->getMock();
123
124
        $this->assertEquals($text, $this->parser->getText());
125
    }
126
}
127