Completed
Pull Request — master (#20)
by John
05:37 queued 03:18
created

CiffRendererTest::getXmlPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Test\Unit;
4
5
use Mockery as m;
6
use Graze\CiffRenderer\Renderer\RendererDocument;
7
use Graze\CiffRenderer\CiffRenderer;
8
use Illuminate\Filesystem\Filesystem;
9
use Intervention\Image\Image;
10
11
class CiffRendererTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var string
15
     */
16
    private $xmlString = '<xml/>';
17
18
    /**
19
     * @var Image
20
     */
21
    private $imageExpected;
22
23
    /**
24
     * @var Filesystem
25
     */
26
    private $filesystem;
27
28
    /**
29
     * @var CiffRenderer
30
     */
31
    private $ciffRenderer;
32
33
    public function setUp()
34
    {
35
        $this->imageExpected = m::mock(Image::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Intervention\Image\Image::class) of type Mockery\MockInterface is incompatible with the declared type Intervention\Image\Image of property $imageExpected.

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...
36
        $this->filesystem = m::mock(Filesystem::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Illuminate...stem\Filesystem::class) of type Mockery\MockInterface is incompatible with the declared type Illuminate\Filesystem\Filesystem of property $filesystem.

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...
37
38
        $fontResolver = function () {}; // @codingStandardsIgnoreLine
39
        $graphicResolver = function () {}; // @codingStandardsIgnoreLine
40
        $argumentValidator = function (\SimpleXMLElement $xmlActual) {
41
            return (string) new \SimpleXMLElement($this->xmlString) == (string) $xmlActual;
42
        };
43
        $rendererDocument = m::mock(RendererDocument::class)
44
            ->shouldReceive('render')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'render'. ( Ignorable by Annotation )

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

44
            ->/** @scrutinizer ignore-call */ shouldReceive('render')

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...
45
            ->with(m::on($argumentValidator), $fontResolver, $graphicResolver)
46
            ->andReturn($this->imageExpected)
47
            ->once()
48
            ->getMock();
49
50
        $this->ciffRenderer = new CiffRenderer($this->filesystem, $rendererDocument);
0 ignored issues
show
Bug introduced by
$rendererDocument of type Mockery\MockInterface is incompatible with the type Graze\CiffRenderer\Renderer\RendererDocument expected by parameter $rendererDocument of Graze\CiffRenderer\CiffRenderer::__construct(). ( Ignorable by Annotation )

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

50
        $this->ciffRenderer = new CiffRenderer($this->filesystem, /** @scrutinizer ignore-type */ $rendererDocument);
Loading history...
Bug introduced by
$this->filesystem of type Mockery\MockInterface is incompatible with the type Illuminate\Filesystem\Filesystem expected by parameter $filesystem of Graze\CiffRenderer\CiffRenderer::__construct(). ( Ignorable by Annotation )

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

50
        $this->ciffRenderer = new CiffRenderer(/** @scrutinizer ignore-type */ $this->filesystem, $rendererDocument);
Loading history...
51
        $this->ciffRenderer->setFontResolver($fontResolver);
52
        $this->ciffRenderer->setGraphicResolver($graphicResolver);
53
    }
54
55
    public function testRenderFile()
56
    {
57
        $path = '/path/to/file';
58
        $this->filesystem
59
            ->shouldReceive('get')
60
            ->with($path)
61
            ->andReturn($this->xmlString)
62
            ->once()
63
            ->getMock();
64
65
        $imageActual = $this->ciffRenderer->renderFile($path);
66
        $this->assertSame($this->imageExpected, $imageActual);
67
    }
68
69
    public function testRenderString()
70
    {
71
        $imageActual = $this->ciffRenderer->renderString($this->xmlString);
72
        $this->assertSame($this->imageExpected, $imageActual);
73
    }
74
}
75