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

dataProviderGetFieldParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Test\FieldParser;
4
5
use Mockery as m;
6
use Graze\CiffRenderer\Parser\FieldParserRegistry;
7
use \SimpleXMLElement;
8
use Graze\CiffRenderer\Parser\FieldParserFactory;
9
use Graze\CiffRenderer\Parser\FieldType;
10
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
11
use Graze\CiffRenderer\Parser\FieldParser\FieldParserFixedText;
12
use Graze\CiffRenderer\Parser\FieldParser\FieldParserBarcode;
13
use Graze\CiffRenderer\Parser\FieldParser\FieldParserDate;
14
use Graze\CiffRenderer\Parser\FieldParser\FieldParserDateOffset;
15
use Graze\CiffRenderer\Parser\FieldParser\FieldParserStaticGraphic;
16
use Graze\CiffRenderer\Parser\FieldParser\FieldParserGraphicPrimitive;
17
18
class FieldParserFactoryTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var FieldParserRegistry
22
     */
23
    private $fieldParserRegistry;
24
25
    /**
26
     * @var FieldParserFactory
27
     */
28
    private $fieldParserFactory;
29
30
    /**
31
     * @var SimpleXMLElement
32
     */
33
    private $xmlHeader;
34
35
    /**
36
     * @var float
37
     */
38
    private $scale;
39
40
    public function setUp()
41
    {
42
        $this->fieldParserRegistry = m::mock(FieldParserRegistry::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...dParserRegistry::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Parser\FieldParserRegistry of property $fieldParserRegistry.

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...
43
        $this->fieldParserFactory = new FieldParserFactory($this->fieldParserRegistry);
0 ignored issues
show
Bug introduced by
$this->fieldParserRegistry of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Parser\FieldParserRegistry expected by parameter $fieldParserRegistry of Graze\CiffRenderer\Parse...rFactory::__construct(). ( Ignorable by Annotation )

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

43
        $this->fieldParserFactory = new FieldParserFactory(/** @scrutinizer ignore-type */ $this->fieldParserRegistry);
Loading history...
44
        $this->xmlHeader = new SimpleXMLElement('<root/>');
45
        $this->scale = 1.5;
46
    }
47
48
    /**
49
     * @dataProvider dataProviderGetFieldParser
50
     * @param string $fieldType
51
     * @param string $parserExpected
52
     */
53
    public function testGetFieldParser($fieldType, $parserExpected)
54
    {
55
        $this->fieldParserRegistry
56
            ->shouldReceive('addParser')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\CiffRenderer\Parser\FieldParserRegistry. ( Ignorable by Annotation )

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

56
            ->/** @scrutinizer ignore-call */ 
57
              shouldReceive('addParser')

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...
57
            ->with(m::type(FieldParserInterface::class))
58
            ->once();
59
60
        $xml = sprintf('<root><FldType>%s</FldType></root>', $fieldType);
61
        $xmlField = new SimpleXMLElement($xml);
62
63
        $parser = $this->fieldParserFactory->getFieldParser(
64
            $this->xmlHeader,
65
            $xmlField,
66
            $this->scale
67
        );
68
69
        $this->assertInstanceOf($parserExpected, $parser);
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    public function dataProviderGetFieldParser()
76
    {
77
        return [
78
            [FieldType::FIELD_FIXED_TEXT, FieldParserFixedText::class],
79
            [FieldType::FIELD_COMPLEX_TEXT, FieldParserFixedText::class],
80
            [FieldType::FIELD_MERGE_FIELD, FieldParserFixedText::class],
81
            [FieldType::FIELD_BARCODE, FieldParserBarcode::class],
82
            [FieldType::FIELD_DATE, FieldParserDate::class],
83
            [FieldType::FIELD_OFFSET_DATE, FieldParserDateOffset::class],
84
            [FieldType::FIELD_STATIC_GRAPHIC, FieldParserStaticGraphic::class],
85
            [FieldType::FIELD_GRAPHIC_PRIMITIVE, FieldParserGraphicPrimitive::class],
86
        ];
87
    }
88
}
89