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

ViewCountControllerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 86.96 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 6
dl 20
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testInvoke() 20 20 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Harentius\BlogBundle\Tests\Unit\Controller;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Harentius\BlogBundle\Controller\ViewCountController;
9
use Harentius\BlogBundle\Entity\Article;
10
use Harentius\BlogBundle\ViewsCounter;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
14
class ViewCountControllerTest extends TestCase
15
{
16 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...
17
    {
18
        $article = new Article();
19
        $viewsCounter = $this->createMock(ViewsCounter::class);
20
        $viewsCounter
21
            ->expects($this->once())
22
            ->method('processArticle')
23
            ->with($article)
24
        ;
25
        $entityManager = $this->createMock(EntityManagerInterface::class);
26
        $entityManager
27
            ->expects($this->once())
28
            ->method('flush')
29
        ;
30
        $viewCountController = new ViewCountController($viewsCounter, $entityManager);
0 ignored issues
show
Documentation introduced by
$viewsCounter is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBundle\ViewsCounter>.

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
$entityManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
31
32
        $response = $viewCountController($article);
33
34
        $this->assertInstanceOf(JsonResponse::class, $response);
35
    }
36
}
37