Completed
Push — master ( 613542...01b9e4 )
by Yaroslav
03:27 queued 35s
created

TagControllerTest::createTagController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Harentius\BlogBundle\Tests\Unit\Controller;
6
7
use Harentius\BlogBundle\BreadCrumbsManager;
8
use Harentius\BlogBundle\Controller\TagController;
9
use Harentius\BlogBundle\Entity\ArticleRepository;
10
use Harentius\BlogBundle\Entity\Tag;
11
use Harentius\BlogBundle\Paginator;
12
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
13
use Knp\Component\Pager\PaginatorInterface;
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\DependencyInjection\Container;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Twig\Environment;
19
20
class TagControllerTest extends TestCase
21
{
22 View Code Duplication
    public function testInvoke(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        $slidingPagination = new SlidingPagination([]);
25
        $slidingPagination->setItemNumberPerPage(10);
26
        $tag = new Tag();
27
        $twig = $this->createMock(Environment::class);
28
        $twig
29
            ->expects($this->once())
30
            ->method('render')
31
            ->with('@HarentiusBlog/Blog/list.html.twig', [
32
                'articles' => $slidingPagination,
33
                'parent' => $tag,
34
                'noIndex' => true,
35
                'hasToPaginate' => false,
36
            ])
37
        ;
38
        $tagController = $this->createTagController($twig, $slidingPagination);
0 ignored issues
show
Documentation introduced by
$twig is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Twig\Environment>.

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...
39
        $request = new Request();
40
41
        $response = $tagController($request, $tag);
42
43
        $this->assertInstanceOf(Response::class, $response);
44
    }
45
46 View Code Duplication
    private function createTagController(Environment $twig, SlidingPagination $slidingPagination): TagController
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $articleRepository = $this->createMock(ArticleRepository::class);
49
        $breadCrumbsManager = $this->createMock(BreadCrumbsManager::class);
50
        $knpPaginator = $this->createMock(PaginatorInterface::class);
51
        $knpPaginator
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
52
            ->method('paginate')
53
            ->willReturn($slidingPagination)
54
        ;
55
56
        $paginator = new Paginator($knpPaginator, 123);
0 ignored issues
show
Documentation introduced by
$knpPaginator is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Knp\Component\Pager\PaginatorInterface>.

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...
57
        $controller = new TagController($articleRepository, $breadCrumbsManager, $paginator);
0 ignored issues
show
Documentation introduced by
$articleRepository is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBun...tity\ArticleRepository>.

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...
Documentation introduced by
$breadCrumbsManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBundle\BreadCrumbsManager>.

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...
58
        $container = new Container();
59
        $container->set('twig', $twig);
60
        $controller->setContainer($container);
61
62
        return $controller;
63
    }
64
}
65