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

NodeBundle/Tests/unit/Entity/NodeVersionTest.php (1 issue)

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\Entity;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityRepository;
7
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
8
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
9
use Kunstmaan\NodeBundle\Entity\NodeVersion;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * Class NodeVersionTest
14
 */
15
class NodeVersionTest extends TestCase
16
{
17
    /**
18
     * @var NodeVersion
19
     */
20
    protected $object;
21
22
    /**
23
     * Sets up the fixture, for example, opens a network connection.
24
     * This method is called before a test is executed.
25
     */
26
    protected function setUp()
27
    {
28
        $this->object = new NodeVersion();
29
    }
30
31
    public function testSetGetNodeTranslation()
32
    {
33
        $nodeTrans = new NodeTranslation();
34
        $this->object->setNodeTranslation($nodeTrans);
35
        $this->assertEquals($nodeTrans, $this->object->getNodeTranslation());
36
    }
37
38
    public function testSetGetType()
39
    {
40
        $this->object->setType(NodeVersion::DRAFT_VERSION);
41
        $this->assertEquals(NodeVersion::DRAFT_VERSION, $this->object->getType());
42
    }
43
44
    public function testSetGetOwner()
45
    {
46
        $this->object->setOwner('owner');
47
        $this->assertEquals('owner', $this->object->getOwner());
48
    }
49
50
    public function testSetGetCreated()
51
    {
52
        $created = new \DateTime();
53
        $this->object->setCreated($created);
54
        $this->assertEquals($created, $this->object->getCreated());
55
    }
56
57
    public function testSetGetUpdated()
58
    {
59
        $updated = new \DateTime();
60
        $this->object->setUpdated($updated);
61
        $this->assertEquals($updated, $this->object->getUpdated());
62
    }
63
64
    public function testGetSetRef()
65
    {
66
        $entity = $this->createMock(HasNodeInterface::class);
67
        $entity->method('getId')->willReturn(1);
68
69
        $em = $this->getMockBuilder(EntityManager::class)
70
            ->disableOriginalConstructor()
71
            ->getMock();
72
73
        $repo = $this->getMockBuilder(EntityRepository::class)
74
            ->disableOriginalConstructor()
75
            ->getMock();
76
77
        $repo->expects($this->any())
78
            ->method('find')
79
            ->willReturn($entity);
80
81
        $em->expects($this->any())
82
            ->method('getRepository')
83
            ->willReturn($repo);
84
85
        $this->object->setRef($entity);
86
        $this->assertEquals(1, $this->object->getRefId());
87
        $this->assertEquals(\get_class($entity), $this->object->getRefEntityName());
88
        $this->assertInstanceOf(\get_class($entity), $this->object->getRef($em));
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManager>.

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...
89
    }
90
91
    public function testGetDefaultAdminType()
92
    {
93
        $this->assertNull($this->object->getDefaultAdminType());
94
    }
95
96
    public function testGetSetOrigin()
97
    {
98
        $entity = new NodeVersion();
99
        $this->object->setOrigin($entity);
100
        $this->assertInstanceOf(NodeVersion::class, $this->object->getOrigin());
101
    }
102
103
    public function testIsPublic()
104
    {
105
        $this->object->setType(NodeVersion::PUBLIC_VERSION);
106
        $this->assertTrue($this->object->isPublic());
107
    }
108
}
109