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\Entity; |
||
4 | |||
5 | use Doctrine\Common\Collections\ArrayCollection; |
||
6 | use FOS\UserBundle\Model\GroupInterface; |
||
7 | use Kunstmaan\AdminBundle\Entity\User; |
||
8 | use PHPUnit\Framework\TestCase; |
||
9 | use Symfony\Component\Validator\Mapping\ClassMetadata; |
||
10 | |||
11 | class UserTest extends TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @var User |
||
15 | */ |
||
16 | protected $object; |
||
17 | |||
18 | /** |
||
19 | * Sets up the fixture, for example, opens a network connection. |
||
20 | * This method is called before a test is executed. |
||
21 | */ |
||
22 | protected function setUp() |
||
23 | { |
||
24 | $this->object = new User(); |
||
25 | } |
||
26 | |||
27 | public function test__construct() |
||
28 | { |
||
29 | $object = new User(); |
||
30 | $object->setId(1); |
||
31 | $this->assertEquals(1, $object->getId()); |
||
32 | } |
||
33 | |||
34 | public function testGetSetId() |
||
35 | { |
||
36 | $this->object->setId(3); |
||
37 | $this->assertEquals(3, $this->object->getId()); |
||
38 | } |
||
39 | |||
40 | public function testGetGroupIds() |
||
41 | { |
||
42 | $group1 = $this->createMock('FOS\UserBundle\Model\GroupInterface'); |
||
43 | $group1 |
||
44 | ->expects($this->once()) |
||
45 | ->method('getId') |
||
46 | ->will($this->returnValue(1)); |
||
47 | |||
48 | $group2 = $this->createMock('FOS\UserBundle\Model\GroupInterface'); |
||
49 | $group2 |
||
50 | ->expects($this->once()) |
||
51 | ->method('getId') |
||
52 | ->will($this->returnValue(2)); |
||
53 | |||
54 | /* @var $group1 GroupInterface */ |
||
55 | $this->object->addGroup($group1); |
||
56 | /* @var $group2 GroupInterface */ |
||
57 | $this->object->addGroup($group2); |
||
58 | |||
59 | $this->assertEquals([1, 2], $this->object->getGroupIds()); |
||
60 | } |
||
61 | |||
62 | View Code Duplication | public function testGetGroups() |
|
63 | { |
||
64 | /* @var $group1 GroupInterface */ |
||
65 | $group1 = $this->createMock('FOS\UserBundle\Model\GroupInterface'); |
||
66 | /* @var $group2 GroupInterface */ |
||
67 | $group2 = $this->createMock('FOS\UserBundle\Model\GroupInterface'); |
||
68 | $this->object->addGroup($group1); |
||
69 | $this->object->addGroup($group2); |
||
70 | |||
71 | $collection = new ArrayCollection(); |
||
72 | $collection->add($group1); |
||
73 | $collection->add($group2); |
||
74 | |||
75 | $this->assertEquals($collection, $this->object->getGroups()); |
||
76 | } |
||
77 | |||
78 | View Code Duplication | public function testHasRole() |
|
79 | { |
||
80 | $this->object->addRole('ROLE_CUSTOM'); |
||
81 | $this->assertTrue($this->object->hasRole('ROLE_CUSTOM')); |
||
82 | |||
83 | $this->object->removeRole('ROLE_CUSTOM'); |
||
84 | $this->assertFalse($this->object->hasRole('ROLE_CUSTOM')); |
||
85 | } |
||
86 | |||
87 | public function testGettersAndSetters() |
||
88 | { |
||
89 | $user = $this->object; |
||
90 | $user->setAdminLocale('en'); |
||
91 | $user->setPasswordChanged(true); |
||
92 | $user->setGoogleId('g0oGl3'); |
||
93 | $user->setEnabled(true); |
||
94 | |||
95 | $this->assertEquals('en', $user->getAdminLocale()); |
||
96 | $this->assertEquals('g0oGl3', $user->getGoogleId()); |
||
97 | $this->assertTrue($user->isPasswordChanged()); |
||
98 | $this->assertTrue($user->isAccountNonLocked()); |
||
99 | $this->assertEquals('Kunstmaan\AdminBundle\Form\UserType', $user->getFormTypeClass()); |
||
100 | } |
||
101 | |||
102 | public function testLoadValidatorMetadata() |
||
103 | { |
||
104 | $meta = new ClassMetadata(User::class); |
||
105 | User::loadValidatorMetadata($meta); |
||
106 | $this->assertEquals('Kunstmaan\AdminBundle\Entity\User', $meta->getClassName()); |
||
107 | $this->assertEquals('User', $meta->getDefaultGroup()); |
||
108 | $props = $meta->getConstrainedProperties(); |
||
109 | $this->assertCount(3, $props); |
||
0 ignored issues
–
show
|
|||
110 | $this->assertEquals('username', $props[0]); |
||
111 | $this->assertEquals('plainPassword', $props[1]); |
||
112 | $this->assertEquals('email', $props[2]); |
||
113 | } |
||
114 | } |
||
115 |
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: