Passed
Branch master (17d5a9)
by michael
08:14
created

U2fUserTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
3
/*
4
 * This file is part of the U2F Security bundle.
5
 *
6
 * (c) Michael Barbey <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mbarbey\U2fSecurityBundle\Tests\Entity\User;
13
14
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
15
use Mbarbey\U2fSecurityBundle\Model\User\U2fUser;
16
use Mbarbey\U2fSecurityBundle\Model\Key\U2fKey;
17
18
class U2fUserTest extends TestCase
19
{
20
    public function testKeys()
21
    {
22
        $user = $this->getUser();
23
        $this->assertEquals($user->getU2fKeys()->count(), 0);
24
25
        $key1 = $this->getMockForAbstractClass(U2fKey::class);
26
        $user->addU2fKey($key1);
27
        $this->assertEquals($user->getU2fKeys()->count(), 1);
28
        $this->assertEquals($user->getU2fKeys()->first(), $key1);
29
        $this->assertEquals($key1->getUser(), $user);
30
31
        $key2 = $this->getMockForAbstractClass(U2fKey::class);
32
        $user->addU2fKey($key2);
33
        $this->assertEquals($user->getU2fKeys()->count(), 2);
34
        $this->assertEquals($user->getU2fKeys()->get(0), $key1);
35
        $this->assertEquals($user->getU2fKeys()->get(1), $key2);
36
        $this->assertEquals($key2->getUser(), $user);
37
38
        $user->removeU2fKey($key1);
39
        $this->assertNull($key1->getUser());
40
        $this->assertEquals($user->getU2fKeys()->count(), 1);
41
        $this->assertEquals($user->getU2fKeys()->first(), $key2);
42
43
        $user->removeU2fKey($key2);
44
        $this->assertNull($key2->getUser());
45
        $this->assertEquals($user->getU2fKeys()->count(), 0);
46
    }
47
48
    protected function getUser()
49
    {
50
        return $this->getMockForAbstractClass(U2fUser::class);
51
    }
52
}
53