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

SidebarControllerTest::testCategories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Harentius\BlogBundle\Tests\Unit\Controller;
6
7
use Harentius\BlogBundle\Controller\SidebarController;
8
use Harentius\BlogBundle\Entity\CategoryRepository;
9
use Harentius\BlogBundle\Sidebar\Archive;
10
use Harentius\BlogBundle\Sidebar\Tags;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\DependencyInjection\Container;
13
use Symfony\Component\HttpFoundation\Response;
14
use Twig\Environment;
15
16
class SidebarControllerTest extends TestCase
17
{
18 View Code Duplication
    public function testCategories(): 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...
19
    {
20
        $twig = $this->createMock(Environment::class);
21
        $twig
22
            ->expects($this->once())
23
            ->method('render')
24
            ->with('@HarentiusBlog/Sidebar/categories.html.twig', [
25
                'categories' => 'categories',
26
            ])
27
        ;
28
        $sidebarController = $this->createSidebarController($twig);
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...
29
        $response = $sidebarController->categories();
30
        $this->assertInstanceOf(Response::class, $response);
31
    }
32
33 View Code Duplication
    public function testArchive(): 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...
34
    {
35
        $twig = $this->createMock(Environment::class);
36
        $twig
37
            ->expects($this->once())
38
            ->method('render')
39
            ->with('@HarentiusBlog/Sidebar/archive.html.twig', [
40
                'archivesList' => 'list',
41
            ])
42
        ;
43
        $sidebarController = $this->createSidebarController($twig);
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...
44
        $response = $sidebarController->archive();
45
        $this->assertInstanceOf(Response::class, $response);
46
    }
47
48 View Code Duplication
    public function testTags(): 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...
49
    {
50
        $twig = $this->createMock(Environment::class);
51
        $twig
52
            ->expects($this->once())
53
            ->method('render')
54
            ->with('@HarentiusBlog/Sidebar/tags.html.twig', [
55
                'tags' => 'list',
56
            ])
57
        ;
58
        $sidebarController = $this->createSidebarController($twig);
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...
59
        $response = $sidebarController->tags();
60
        $this->assertInstanceOf(Response::class, $response);
61
    }
62
63
    private function createSidebarController(Environment $twig): SidebarController
64
    {
65
        $categoryRepository = $this->createMock(CategoryRepository::class);
66
        $categoryRepository
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...
67
            ->method('notEmptyChildrenHierarchy')
68
            ->willReturn('categories')
69
        ;
70
        $archive = $this->createMock(Archive::class);
71
        $archive
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...
72
            ->method('getList')
73
            ->willReturn('list')
74
        ;
75
        $tags = $this->createMock(Tags::class);
76
        $tags
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...
77
            ->method('getList')
78
            ->willReturn('list')
79
        ;
80
81
        $controller = new SidebarController($categoryRepository, $archive, $tags);
0 ignored issues
show
Documentation introduced by
$categoryRepository is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBun...ity\CategoryRepository>.

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
$archive is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBundle\Sidebar\Archive>.

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
$tags is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBundle\Sidebar\Tags>.

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...
82
        $container = new Container();
83
        $container->set('twig', $twig);
84
        $controller->setContainer($container);
85
86
        return $controller;
87
    }
88
}
89