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

NodeBundle/Tests/unit/Event/NodeEventTest.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\NodeBundle\Tests\Event;
4
5
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
6
use Kunstmaan\NodeBundle\Entity\Node;
7
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
8
use Kunstmaan\NodeBundle\Entity\NodeVersion;
9
use Kunstmaan\NodeBundle\Event\NodeEvent;
10
use PHPUnit\Framework\TestCase;
11
use Symfony\Component\HttpFoundation\Response;
12
13
/**
14
 * Class NodeEventTest
15
 */
16
class NodeEventTest extends TestCase
17
{
18
    public function testGetSet()
19
    {
20
        /** @var Node $node */
21
        $node = $this->createMock(Node::class);
22
        /** @var NodeTranslation $nodeTranslation */
23
        $nodeTranslation = $this->createMock(NodeTranslation::class);
24
        /** @var NodeVersion $nodeVersion */
25
        $nodeVersion = $this->createMock(NodeVersion::class);
26
        $page = $this->createMock(HasNodeInterface::class);
27
28
        $event = new NodeEvent($node, $nodeTranslation, $nodeVersion, $page);
0 ignored issues
show
$page is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\NodeBun...ntity\HasNodeInterface>.

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
30
        $this->assertInstanceOf(Node::class, $event->getNode());
31
        $this->assertInstanceOf(NodeTranslation::class, $event->getNodeTranslation());
32
        $this->assertInstanceOf(\get_class($page), $event->getPage());
33
        $this->assertInstanceOf(NodeVersion::class, $event->getNodeVersion());
34
35
        $event->setNode($node);
36
        $event->setNodeTranslation($nodeTranslation);
37
        $event->setNodeVersion($nodeVersion);
38
        $event->setPage($page);
0 ignored issues
show
$page is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\NodeBun...ntity\HasNodeInterface>.

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
        $event->setResponse(new Response());
40
41
        $this->assertInstanceOf(Node::class, $event->getNode());
42
        $this->assertInstanceOf(NodeTranslation::class, $event->getNodeTranslation());
43
        $this->assertInstanceOf(\get_class($page), $event->getPage());
44
        $this->assertInstanceOf(NodeVersion::class, $event->getNodeVersion());
45
        $this->assertInstanceOf(Response::class, $event->getResponse());
46
    }
47
}
48