Completed
Push — develop ( fbdd82...317691 )
by Mike
09:29
created

testIfRenderingFailsIfTemplateWasNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2015 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Application;
14
15
use League\Event\EmitterInterface;
16
use League\Flysystem\Filesystem;
17
use League\Flysystem\Memory\MemoryAdapter;
18
use League\Tactician\CommandBus;
19
use Mockery as m;
20
use phpDocumentor\Application\Render;
21
use phpDocumentor\Application\RenderHandler;
22
use phpDocumentor\DomainModel\Parser\Documentation;
23
use phpDocumentor\DomainModel\Renderer\Assets;
24
use phpDocumentor\Infrastructure\FileSystemFactory;
25
use phpDocumentor\DomainModel\Parser\Version\Number;
26
use phpDocumentor\DomainModel\Renderer\Template\Action;
27
use phpDocumentor\DomainModel\Renderer\RenderActionCompleted;
28
use phpDocumentor\DomainModel\Renderer\RenderingFinished;
29
use phpDocumentor\DomainModel\Renderer\RenderingStarted;
30
use phpDocumentor\DomainModel\Renderer\Template;
31
use phpDocumentor\DomainModel\Renderer\TemplateFactory;
32
33
/**
34
 * @coversDefaultClass phpDocumentor\Application\RenderHandler
35
 * @covers ::<private>
36
 */
37
final class RenderHandlerTest extends \PHPUnit_Framework_TestCase
38
{
39
    /** @var TemplateFactory|m\MockInterface */
40
    private $templateFactory;
41
42
    /** @var CommandBus|m\MockInterface */
43
    private $commandBus;
44
45
    /** @var FileSystemFactory|m\MockInterface */
46
    private $filesystemFactory;
47
48
    /** @var EmitterInterface|m\MockInterface */
49
    private $emitter;
50
51
    /** @var Assets|m\MockInterface */
52
    private $assets;
53
54
    /** @var RenderHandler|m\MockInterface */
55
    private $handler;
56
57
    public function setUp()
58
    {
59
        $this->templateFactory = m::mock(TemplateFactory::class);
60
        $this->commandBus = m::mock(CommandBus::class);
61
        $this->filesystemFactory = m::mock(FileSystemFactory::class);
62
        $this->emitter = m::mock(EmitterInterface::class);
63
        $this->assets = m::mock(Assets::class);
64
65
        $this->handler = new RenderHandler(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \phpDocumentor\Appli...emitter, $this->assets) of type object<phpDocumentor\Application\RenderHandler> is incompatible with the declared type object<Mockery\MockInterface> of property $handler.

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...
66
            $this->templateFactory,
67
            $this->commandBus,
68
            $this->filesystemFactory,
69
            $this->emitter,
70
            $this->assets
71
        );
72
    }
73
74
    /**
75
     * @covers ::__invoke
76
     */
77
    public function testIfTemplateActionsAreExecutedWhenRenderingATemplate()
78
    {
79
        $documentation = new Documentation(new Number('1.0'));
80
        $target = m::mock(Filesystem::class);
81
        $templates = [['name' => 'template']];
82
        $renderActionCommand = m::mock(Action::class);
83
84
        $command = new Render($documentation, $target, $templates);
0 ignored issues
show
Documentation introduced by
$templates is of type array<integer,array<stri..."name\":\"string\"}>"}>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
86
        $this->emitter->shouldReceive('emit')->once()->with(m::type(RenderActionCompleted::class));
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in League\Event\EmitterInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
87
        $this->emitter->shouldReceive('emit')->once()->with(m::type(RenderingStarted::class));
88
        $this->emitter->shouldReceive('emit')->once()->with(m::type(RenderingFinished::class));
89
90
        $this->filesystemFactory->shouldReceive('create')->andReturn(new Filesystem(new MemoryAdapter()));
91
        $this->templateFactory
92
            ->shouldReceive('createFromName')
93
            ->andReturn(new Template('name', [], [$renderActionCommand]));
0 ignored issues
show
Documentation introduced by
array($renderActionCommand) is of type array<integer,object<Moc...kery\\MockInterface>"}>, but the function expects a array<integer,object<php...derer\Template\Action>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
94
95
        $this->commandBus->shouldReceive('handle')->once()->with($renderActionCommand);
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in League\Tactician\CommandBus.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
96
97
        $this->handler->__invoke($command);
0 ignored issues
show
Bug introduced by
The method __invoke() does not seem to exist on object<Mockery\MockInterface>.

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...
98
    }
99
100
    /**
101
     * @covers ::__invoke
102
     */
103
    public function testIfRenderingFailsIfTemplateWasNotFound()
104
    {
105
        $this->setExpectedException(\InvalidArgumentException::class, 'The template "template" could not be found');
106
107
        $documentation = new Documentation(new Number('1.0'));
108
        $target = m::mock(Filesystem::class);
109
        $templates = [['name' => 'template']];
110
111
        $command = new Render($documentation, $target, $templates);
0 ignored issues
show
Documentation introduced by
$templates is of type array<integer,array<stri..."name\":\"string\"}>"}>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
112
113
        $this->emitter->shouldReceive('emit')->never()->with(m::type(RenderActionCompleted::class));
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in League\Event\EmitterInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
114
        $this->emitter->shouldReceive('emit')->once()->with(m::type(RenderingStarted::class));
115
        $this->emitter->shouldReceive('emit')->never()->with(m::type(RenderingFinished::class));
116
117
        $this->filesystemFactory->shouldReceive('create')->andReturn(new Filesystem(new MemoryAdapter()));
118
        $this->templateFactory
119
            ->shouldReceive('createFromName')
120
            ->andReturn(null);
121
122
        $this->commandBus->shouldReceive('handle')->never();
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in League\Tactician\CommandBus.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
123
124
        $this->handler->__invoke($command);
0 ignored issues
show
Bug introduced by
The method __invoke() does not seem to exist on object<Mockery\MockInterface>.

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...
125
    }
126
}
127