Completed
Push — refactor-04-parser-tests ( bce951...3ac566 )
by John
02:51
created

FieldRendererFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFieldRendererGraphicPrimitive() 0 24 1
A dataProviderGetFieldRenderer() 0 10 1
A setUp() 0 4 1
A testGetFieldRenderer() 0 12 1
1
<?php
2
3
namespace Graze\CiffRenderer\Test\Unit\Renderer\FieldRenderer;
4
5
use Mockery as m;
6
use Graze\CiffRenderer\Renderer\FieldRenderer\GraphicPrimitive\GraphicPrimitiveFactory;
7
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererFactory;
8
use Graze\CiffRenderer\Parser\FieldType;
9
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
10
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererFixedText;
11
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererBarcode;
12
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererStaticGraphic;
13
14
class FieldRendererFactoryTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @var GraphicPrimitiveFactory
18
     */
19
    private $graphicPrimitiveFactory;
20
21
    /**
22
     * @var FieldRendererFactory
23
     */
24
    private $fieldRendererFactory;
25
26
    public function setUp()
27
    {
28
        $this->graphicPrimitiveFactory = m::mock(GraphicPrimitiveFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...rimitiveFactory::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Rende...GraphicPrimitiveFactory of property $graphicPrimitiveFactory.

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
        $this->fieldRendererFactory = new FieldRendererFactory($this->graphicPrimitiveFactory);
0 ignored issues
show
Bug introduced by
$this->graphicPrimitiveFactory of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Rende...GraphicPrimitiveFactory expected by parameter $graphicPrimitiveFactory of Graze\CiffRenderer\Rende...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

29
        $this->fieldRendererFactory = new FieldRendererFactory(/** @scrutinizer ignore-type */ $this->graphicPrimitiveFactory);
Loading history...
30
    }
31
32
    /**
33
     * @dataProvider dataProviderGetFieldRenderer
34
     * @param string $fieldType
35
     * @param string $rendererExpected
36
     */
37
    public function testGetFieldRenderer($fieldType, $rendererExpected)
38
    {
39
        $parser = m::mock(FieldParserInterface::class)
40
            ->shouldReceive('getFieldType')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getFieldType'. ( Ignorable by Annotation )

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

40
            ->/** @scrutinizer ignore-call */ shouldReceive('getFieldType')

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...
41
            ->withNoArgs()
42
            ->andReturn($fieldType)
43
            ->once()
44
            ->getMock();
45
46
        $rendererActual = $this->fieldRendererFactory->getFieldRenderer($parser);
0 ignored issues
show
Bug introduced by
$parser of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Parse...er\FieldParserInterface expected by parameter $parser of Graze\CiffRenderer\Rende...ory::getFieldRenderer(). ( Ignorable by Annotation )

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

46
        $rendererActual = $this->fieldRendererFactory->getFieldRenderer(/** @scrutinizer ignore-type */ $parser);
Loading history...
47
48
        $this->assertInstanceOf($rendererExpected, $rendererActual);
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function dataProviderGetFieldRenderer()
55
    {
56
        return [
57
            [FieldType::FIELD_BARCODE, FieldRendererBarcode::class],
58
            [FieldType::FIELD_STATIC_GRAPHIC, FieldRendererStaticGraphic::class],
59
            [FieldType::FIELD_FIXED_TEXT, FieldRendererFixedText::class],
60
            [FieldType::FIELD_COMPLEX_TEXT, FieldRendererFixedText::class],
61
            [FieldType::FIELD_DATE, FieldRendererFixedText::class],
62
            [FieldType::FIELD_OFFSET_DATE, FieldRendererFixedText::class],
63
            [FieldType::FIELD_MERGE_FIELD, FieldRendererFixedText::class],
64
            // FieldType::FIELD_GRAPHIC_PRIMITIVE is test in testGetFieldRendererGraphicPrimitive
65
        ];
66
    }
67
68
    public function testGetFieldRendererGraphicPrimitive()
69
    {
70
        $rendererExpected = m::mock(FieldRendererInterface::class);
0 ignored issues
show
Bug introduced by
The type Graze\CiffRenderer\Test\...\FieldRendererInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
71
        $shape = 'i am shape';
72
        $this->graphicPrimitiveFactory
73
            ->shouldReceive('getFieldRenderer')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\CiffRenderer\Rende...GraphicPrimitiveFactory. ( Ignorable by Annotation )

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

73
            ->/** @scrutinizer ignore-call */ 
74
              shouldReceive('getFieldRenderer')

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...
74
            ->with($shape)
75
            ->andReturn($rendererExpected)
76
            ->once()
77
            ->getMock();
78
79
        $parser = m::mock(FieldParserInterface::class)
80
            ->shouldReceive('getFieldType')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getFieldType'. ( Ignorable by Annotation )

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

80
            ->/** @scrutinizer ignore-call */ shouldReceive('getFieldType')

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...
81
            ->withNoArgs()
82
            ->andReturn(FieldType::FIELD_GRAPHIC_PRIMITIVE)
83
            ->once()
84
            ->shouldReceive('getShape')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Mockery\Expectation. ( Ignorable by Annotation )

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

84
            ->/** @scrutinizer ignore-call */ shouldReceive('getShape')

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...
85
            ->withNoArgs()
86
            ->andReturn($shape)
87
            ->once()
88
            ->getMock();
89
90
        $rendererActual = $this->fieldRendererFactory->getFieldRenderer($parser);
91
        $this->assertEquals($rendererExpected, $rendererActual);
92
    }
93
}
94