Passed
Push — master ( bb11e3...34e12f )
by michael
03:06
created

U2fUserTest::testKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 26
rs 9.6
c 0
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
The method getU2fKeys() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        $this->assertEquals($user->/** @scrutinizer ignore-call */ getU2fKeys()->count(), 0);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
25
        $key1 = $this->getMockForAbstractClass(U2fKey::class);
26
        $user->addU2fKey($key1);
0 ignored issues
show
Bug introduced by
The method addU2fKey() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        $user->/** @scrutinizer ignore-call */ 
27
               addU2fKey($key1);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
        $this->assertEquals($user->getU2fKeys()->count(), 1);
28
        $this->assertEquals($user->getU2fKeys()->first(), $key1);
29
        $this->assertEquals($key1->getUser(), $user);
0 ignored issues
show
Bug introduced by
The method getUser() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $this->assertEquals($key1->/** @scrutinizer ignore-call */ getUser(), $user);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method removeU2fKey() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        $user->/** @scrutinizer ignore-call */ 
39
               removeU2fKey($key1);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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