1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminBundle\Tests\Entity; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\AdminBundle\Entity\AbstractEntity; |
6
|
|
|
use Kunstmaan\AdminBundle\Entity\AclChangeset; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class AclChangesetTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var AclChangeset |
13
|
|
|
*/ |
14
|
|
|
protected $object; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Sets up the fixture, for example, opens a network connection. |
18
|
|
|
* This method is called before a test is executed. |
19
|
|
|
*/ |
20
|
|
|
protected function setUp(): void |
21
|
|
|
{ |
22
|
|
|
$this->object = new AclChangeset(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function test__construct() |
26
|
|
|
{ |
27
|
|
|
$object = new AclChangeset(); |
28
|
|
|
$this->assertEquals(AclChangeset::STATUS_NEW, $object->getStatus()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testSetAndGetChangeset() |
32
|
|
|
{ |
33
|
|
|
$changeset = array('ROLE_ADMIN' => array('ADD' => array('VIEW', 'EDIT'), 'DEL' => 'PUBLISH')); |
34
|
|
|
$this->object->setChangeset($changeset); |
35
|
|
|
|
36
|
|
|
$this->assertEquals($changeset, $this->object->getChangeset()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSetAndGetCreated() |
40
|
|
|
{ |
41
|
|
|
$currentDate = new \DateTime('now'); |
42
|
|
|
$this->object->setCreated($currentDate); |
43
|
|
|
|
44
|
|
|
$this->assertEquals($currentDate, $this->object->getCreated()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testSetAndGetLastModified() |
48
|
|
|
{ |
49
|
|
|
$currentDate = new \DateTime('now'); |
50
|
|
|
$this->object->setLastModified($currentDate); |
51
|
|
|
|
52
|
|
|
$this->assertEquals($currentDate, $this->object->getLastModified()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testSetAndGetRef() |
56
|
|
|
{ |
57
|
|
|
$entity = $this->createMock(AbstractEntity::class); |
58
|
|
|
$entity->method('getId')->willReturn(1); |
59
|
|
|
$entity->method('setId')->willReturn(null); |
60
|
|
|
$entity->method('__toString')->willReturn('1'); |
61
|
|
|
|
62
|
|
|
$this->object->setRef($entity); |
|
|
|
|
63
|
|
|
$this->assertEquals(1, $this->object->getRefId()); |
64
|
|
|
$this->assertEquals(\get_class($entity), $this->object->getRefEntityName()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testSetAndGetStatus() |
68
|
|
|
{ |
69
|
|
|
$yesterday = new \DateTime('yesterday'); |
70
|
|
|
$this->object->setLastModified($yesterday); |
71
|
|
|
|
72
|
|
|
$this->assertEquals(AclChangeset::STATUS_NEW, $this->object->getStatus()); |
73
|
|
|
|
74
|
|
|
$this->object->setStatus(AclChangeset::STATUS_RUNNING); |
75
|
|
|
$this->assertNotEquals(AclChangeset::STATUS_NEW, $this->object->getStatus()); |
76
|
|
|
$this->assertEquals(AclChangeset::STATUS_RUNNING, $this->object->getStatus()); |
77
|
|
|
$this->assertNotEquals($yesterday, $this->object->getLastModified()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testSetAndGetPid() |
81
|
|
|
{ |
82
|
|
|
$this->object->setPid(10); |
83
|
|
|
$this->assertEquals(10, $this->object->getPid()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testSetAndGetUser() |
87
|
|
|
{ |
88
|
|
|
$user = new \Kunstmaan\AdminBundle\Entity\User(); |
89
|
|
|
$this->object->setUser($user); |
90
|
|
|
|
91
|
|
|
$this->assertEquals($user, $this->object->getUser()); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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: