Completed
Push — refactor-04-parser-tests ( 553ee6...bce951 )
by John
03:05 queued 47s
created

ParserDocumentTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Test\Unit\Parser;
4
5
use Mockery as m;
6
use Graze\CiffRenderer\SimpleXmlElement\SimpleXmlElementInterface;
7
use Graze\CiffRenderer\Test\SimpleXmlElementChainMocker;
8
use Graze\CiffRenderer\Parser\FieldSorter;
9
use Graze\CiffRenderer\Parser\FieldParser\FieldParserFactory;
0 ignored issues
show
Bug introduced by
The type Graze\CiffRenderer\Parse...rser\FieldParserFactory 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...
10
use Graze\CiffRenderer\Parser\FieldParserRegistry;
11
use Graze\CiffRenderer\Parser\ParserDocument;
12
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
13
14
class ParserDocumentTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @var FieldSorter
18
     */
19
    private $fieldSorter;
20
21
    /**
22
     * @var FieldParserFactory
23
     */
24
    private $fieldParserFactory;
25
26
    /**
27
     * @var FieldParserRegistry
28
     */
29
    private $fieldParserRegistry;
30
31
    /**
32
     * @var ParserDocument
33
     */
34
    private $parserDocument;
35
36
    public function setUp()
37
    {
38
        $this->fieldSorter = m::mock(FieldSorter::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...ser\FieldSorter::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Parser\FieldSorter of property $fieldSorter.

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...
39
        $this->fieldParserFactory = m::mock(FieldParserFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Graze\Ciff...ldParserFactory::class) of type Mockery\MockInterface is incompatible with the declared type Graze\CiffRenderer\Parse...rser\FieldParserFactory of property $fieldParserFactory.

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...
40
        $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...
41
        $this->parserDocument = new ParserDocument(
42
            $this->fieldSorter,
0 ignored issues
show
Bug introduced by
$this->fieldSorter of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Parser\FieldSorter expected by parameter $fieldSorter of Graze\CiffRenderer\Parse...Document::__construct(). ( Ignorable by Annotation )

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

42
            /** @scrutinizer ignore-type */ $this->fieldSorter,
Loading history...
43
            $this->fieldParserFactory,
44
            $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...Document::__construct(). ( Ignorable by Annotation )

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

44
            /** @scrutinizer ignore-type */ $this->fieldParserRegistry
Loading history...
45
        );
46
    }
47
48
    public function testGetFieldParsers()
49
    {
50
        // mock ->SubImage
51
        $field = m::mock(SimpleXmlElementInterface::class);
52
        $fields = [$field];
53
        $simpleXmlElement = SimpleXmlElementChainMocker::mock(['SubImage'], ['Field' => $fields]);
54
55
        // mock ->Header
56
        $header = m::mock(SimpleXmlElementInterface::class);
57
        SimpleXmlElementChainMocker::addChain($simpleXmlElement, ['Header'], $header);
58
59
        // mock ->SubImage->SubHeader->XRes
60
        $scale = 3;
61
        SimpleXmlElementChainMocker::addChain($simpleXmlElement, ['SubImage','SubHeader', 'XRes'], $scale);
62
63
        dump($simpleXmlElement->SubHeader);
0 ignored issues
show
Bug introduced by
Accessing SubHeader on the interface Mockery\MockInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Coding Style introduced by
The variable $SubHeader should be in camel caps format.
Loading history...
64
        die;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
65
        $this->fieldSorter
0 ignored issues
show
Unused Code introduced by
$this->fieldSorter->shou...lds)->once()->getMock() 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...
66
            ->shouldReceive('sort')
67
            ->with($fields)
68
            ->once()
69
            ->getMock();
70
71
        $fieldParser = m::mock(FieldParserInterface::class)
72
            ->shouldReceive('parse')
73
            ->with($this->fieldParserRegistry, $field, $header, $scale)
74
            ->once()
75
            ->getMock();
76
77
        $this->fieldParserFactory
78
            ->shouldReceive('getFieldParser')
79
            ->with($field)
80
            ->andReturn($fieldParser)
81
            ->once()
82
            ->getMock();
83
84
        $fieldParsers = $this->parserDocument->getFieldParsers($simpleXmlElement);
85
86
        $this->assertEquals([$fieldParser], $fieldParsers);
87
    }
88
}
89