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

FieldParserDateTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
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\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);
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>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;
0 ignored issues
show
Unused Code introduced by
return $this->xmlField is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
62
    }
63
64
    /**
65
     * @return FieldParserDate
66
     */
67
    protected function getParser()
68
    {
69
        if (!$this->parser) {
70
            $this->parser = new FieldParserDate(
0 ignored issues
show
Documentation Bug introduced by
It seems like new Graze\CiffRenderer\P...lField(), $this->scale) of type Graze\CiffRenderer\Parse...dParser\FieldParserDate 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...
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')
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

89
            ->/** @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...
90
            ->with($this->dateTimeNow, $dateFormat)
91
            ->andReturn($text)
92
            ->once()
93
            ->getMock();
94
        $this->dateFormatterFactory
95
            ->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

95
            ->/** @scrutinizer ignore-call */ 
96
              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...
96
            ->with($dateFormat)
97
            ->andReturn($dateFormatter)
98
            ->getMock();
99
100
        $this->assertEquals($text, $this->parser->getText());
101
    }
102
}
103