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

ShowControllerTest::testInvokeWithArticle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
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\BreadCrumbsManager;
8
use Harentius\BlogBundle\Controller\ShowController;
9
use Harentius\BlogBundle\Entity\Article;
10
use Harentius\BlogBundle\Entity\Page;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\DependencyInjection\Container;
13
use Symfony\Component\HttpFoundation\Response;
14
use Twig\Environment;
15
16
class ShowControllerTest extends TestCase
17
{
18 View Code Duplication
    public function testInvokeWithArticle(): 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
        $article = new Article();
21
        $twig = $this->createMock(Environment::class);
22
        $twig
23
            ->expects($this->once())
24
            ->method('render')
25
            ->with('@HarentiusBlog/Show/article.html.twig', [
26
                'entity' => $article,
27
            ])
28
        ;
29
        $showController = $this->createShowController($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...
30
        $response = $showController($article);
31
        $this->assertInstanceOf(Response::class, $response);
32
    }
33
34 View Code Duplication
    public function testInvokeWithPage(): 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...
35
    {
36
        $page = new Page();
37
        $twig = $this->createMock(Environment::class);
38
        $twig
39
            ->expects($this->once())
40
            ->method('render')
41
            ->with('@HarentiusBlog/Show/page.html.twig', [
42
                'entity' => $page,
43
            ])
44
        ;
45
        $showController = $this->createShowController($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...
46
        $response = $showController($page);
47
        $this->assertInstanceOf(Response::class, $response);
48
    }
49
50
    private function createShowController(Environment $twig): ShowController
51
    {
52
        $breadCrumbsManager = $this->createMock(BreadCrumbsManager::class);
53
        $controller = new ShowController($breadCrumbsManager);
0 ignored issues
show
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...
54
        $container = new Container();
55
        $container->set('twig', $twig);
56
        $controller->setContainer($container);
57
58
        return $controller;
59
    }
60
}
61