Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

Tests/EventListener/CloneListenerTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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()
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
$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()
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
$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