OptionableViewTest::createViewMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Pagerfanta\Tests\View;
4
5
use Pagerfanta\View\OptionableView;
6
use PHPUnit\Framework\TestCase;
7
8
class OptionableViewTest extends TestCase
9
{
10
    private $pagerfanta;
11
    private $routeGenerator;
12
    private $rendered;
13
14
    protected function setUp()
15
    {
16
        $this->pagerfanta = $this->createPagerfantaMock();
17
        $this->routeGenerator = $this->createRouteGenerator();
18
    }
19
20
    private function createPagerfantaMock()
21
    {
22
        return $this->getMockBuilder('Pagerfanta\PagerfantaInterface')->getMock();
23
    }
24
25
    private function createRouteGenerator()
26
    {
27
        return function () {};
28
    }
29
30
    public function testRenderShouldDelegateToTheView()
31
    {
32
        $defaultOptions = array('foo' => 'bar', 'bar' => 'ups');
33
34
        $view = $this->createViewMock($defaultOptions);
35
        $optionable = new OptionableView($view, $defaultOptions);
0 ignored issues
show
Documentation introduced by
$view is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Pagerfanta\View\ViewInterface>.

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...
36
37
        $returned = $optionable->render($this->pagerfanta, $this->routeGenerator);
0 ignored issues
show
Documentation introduced by
$this->pagerfanta is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Pagerfanta\PagerfantaInterface>.

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...
38
        $this->assertSame($this->rendered, $returned);
39
    }
40
41
    public function testRenderShouldMergeOptions()
42
    {
43
        $defaultOptions = array('foo' => 'bar');
44
        $options = array('ups' => 'da');
45
        $expectedOptions = array_merge($defaultOptions, $options);
46
47
        $view = $this->createViewMock($expectedOptions);
48
        $optionable = new OptionableView($view, $defaultOptions);
0 ignored issues
show
Documentation introduced by
$view is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Pagerfanta\View\ViewInterface>.

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...
49
50
        $returned = $optionable->render($this->pagerfanta, $this->routeGenerator, $options);
0 ignored issues
show
Documentation introduced by
$this->pagerfanta is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Pagerfanta\PagerfantaInterface>.

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...
51
        $this->assertSame($this->rendered, $returned);
52
    }
53
54
    private function createViewMock($expectedOptions)
55
    {
56
        $view = $this->getMockBuilder('Pagerfanta\View\ViewInterface')->getMock();
57
        $view
58
            ->expects($this->once())
59
            ->method('render')
60
            ->with(
61
                $this->equalTo($this->pagerfanta),
62
                $this->equalTo($this->routeGenerator),
63
                $this->equalTo($expectedOptions)
64
            )
65
            ->will($this->returnValue($this->rendered));
66
67
        return $view;
68
    }
69
}
70