Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

UserTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
/**
12
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-04 at 16:54:04.
13
 */
14
class UserTest extends TestCase
15
{
16
    /**
17
     * @var User
18
     */
19
    protected $object;
20
21
    /**
22
     * Sets up the fixture, for example, opens a network connection.
23
     * This method is called before a test is executed.
24
     */
25
    protected function setUp()
26
    {
27
        $this->object = new User();
28
    }
29
30
    public function test__construct()
31
    {
32
        $object = new User();
33
        $object->setId(1);
34
        $this->assertEquals(1, $object->getId());
35
    }
36
37
    public function testGetSetId()
38
    {
39
        $this->object->setId(3);
40
        $this->assertEquals(3, $this->object->getId());
41
    }
42
43
    public function testGetGroupIds()
44
    {
45
        $group1 = $this->createMock('FOS\UserBundle\Model\GroupInterface');
46
        $group1
47
            ->expects($this->once())
48
            ->method('getId')
49
            ->will($this->returnValue(1));
50
51
        $group2 = $this->createMock('FOS\UserBundle\Model\GroupInterface');
52
        $group2
53
            ->expects($this->once())
54
            ->method('getId')
55
            ->will($this->returnValue(2));
56
57
        /* @var $group1 GroupInterface */
58
        $this->object->addGroup($group1);
59
        /* @var $group2 GroupInterface */
60
        $this->object->addGroup($group2);
61
62
        $this->assertEquals(array(1, 2), $this->object->getGroupIds());
63
    }
64
65 View Code Duplication
    public function testGetGroups()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        /* @var $group1 GroupInterface */
68
        $group1 = $this->createMock('FOS\UserBundle\Model\GroupInterface');
69
        /* @var $group2 GroupInterface */
70
        $group2 = $this->createMock('FOS\UserBundle\Model\GroupInterface');
71
        $this->object->addGroup($group1);
72
        $this->object->addGroup($group2);
73
74
        $collection = new ArrayCollection();
75
        $collection->add($group1);
76
        $collection->add($group2);
77
78
        $this->assertEquals($collection, $this->object->getGroups());
79
    }
80
81 View Code Duplication
    public function testHasRole()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        $this->object->addRole('ROLE_CUSTOM');
84
        $this->assertTrue($this->object->hasRole('ROLE_CUSTOM'));
85
86
        $this->object->removeRole('ROLE_CUSTOM');
87
        $this->assertFalse($this->object->hasRole('ROLE_CUSTOM'));
88
    }
89
90
    public function testGettersAndSetters()
91
    {
92
        $user = $this->object;
93
        $user->setAdminLocale('en');
94
        $user->setPasswordChanged(true);
95
        $user->setGoogleId('g0oGl3');
96
        $user->setEnabled(true);
97
98
        $this->assertEquals('en', $user->getAdminLocale());
99
        $this->assertEquals('g0oGl3', $user->getGoogleId());
100
        $this->assertTrue($user->isPasswordChanged());
101
        $this->assertTrue($user->isAccountNonLocked());
102
        $this->assertEquals('Kunstmaan\AdminBundle\Form\UserType', $user->getFormTypeClass());
103
    }
104
105
    public function testLoadValidatorMetadata()
106
    {
107
        $meta = new ClassMetadata(User::class);
108
        User::loadValidatorMetadata($meta);
109
        $this->assertEquals('Kunstmaan\AdminBundle\Entity\User', $meta->getClassName());
110
        $this->assertEquals('User', $meta->getDefaultGroup());
111
        $props = $meta->getConstrainedProperties();
112
        $this->assertCount(3, $props);
0 ignored issues
show
Documentation introduced by
$props is of type array<integer,integer>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
113
        $this->assertEquals('username', $props[0]);
114
        $this->assertEquals('plainPassword', $props[1]);
115
        $this->assertEquals('email', $props[2]);
116
    }
117
}
118