Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

testOnDeepCloneAndSaveWithAbstractEntity()   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
namespace Kunstmaan\AdminBundle\Tests\EventListener;
4
5
use Kunstmaan\AdminBundle\Entity\AbstractEntity;
6
use Kunstmaan\AdminBundle\Entity\DeepCloneInterface;
7
use Kunstmaan\AdminBundle\Event\DeepCloneAndSaveEvent;
8
use Kunstmaan\AdminBundle\EventListener\CloneListener;
9
use PHPUnit\Framework\TestCase;
10
11
class CloneListenerTest extends TestCase
12
{
13 View Code Duplication
    public function testOnDeepCloneAndSaveWithAbstractEntity()
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...
14
    {
15
        $listener = new CloneListener();
16
17
        /** @var AbstractEntity $entityMock */
18
        $entityMock = $this->getMockForAbstractClass(AbstractEntity::class);
19
        $entityMock->setId(747);
20
21
        $event = $this->createMock(DeepCloneAndSaveEvent::class);
22
        $event->expects($this->any())->method('getClonedEntity')->willReturn($entityMock);
23
24
        $listener->onDeepCloneAndSave($event);
0 ignored issues
show
Documentation introduced by
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...\DeepCloneAndSaveEvent>.

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...
25
        $this->assertNull($entityMock->getId());
26
    }
27
28 View Code Duplication
    public function testOnDeepCloneAndSaveWithDeepCloneInterface()
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...
29
    {
30
        $listener = new CloneListener();
31
32
        $deepCloneInterfaceMock = $this->createMock(DeepCloneInterface::class);
33
        $deepCloneInterfaceMock->expects($this->once())->method('deepClone');
34
35
        $event = $this->createMock(DeepCloneAndSaveEvent::class);
36
        $event->expects($this->any())->method('getClonedEntity')->willReturn($deepCloneInterfaceMock);
37
38
        $listener->onDeepCloneAndSave($event);
0 ignored issues
show
Documentation introduced by
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...\DeepCloneAndSaveEvent>.

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
    }
40
}
41