Completed
Push — master ( 450ed3...cc0280 )
by michael
02:49
created

U2fPostAuthenticationEventTest::testName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 10
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\Event\Authentication;
13
14
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
15
use Mbarbey\U2fSecurityBundle\Model\User\U2fUser;
16
use Mbarbey\U2fSecurityBundle\Model\Key\U2fKey;
17
use Mbarbey\U2fSecurityBundle\Event\Authentication\U2fPostAuthenticationEvent;
18
19
class U2fPostAuthenticationEventTest extends TestCase
20
{
21
    private $event;
22
    private $user;
23
    private $key;
24
25
    public function testName()
26
    {
27
        $name = 'u2f.authentication.after';
28
29
        $this->assertEquals(U2fPostAuthenticationEvent::getName(), $name);
30
31
        $this->setUpSuccess();
32
        $this->assertEquals($this->event->getName(), $name);
33
34
        $this->setUpFailure();
35
        $this->assertEquals($this->event->getName(), $name);
36
    }
37
38
    public function testUser()
39
    {
40
        $this->setUpSuccess();
41
        $this->assertEquals($this->event->getUser(), $this->user);
42
43
        $this->setUpFailure();
44
        $this->assertEquals($this->event->getUser(), $this->user);
45
    }
46
47
    public function testKey()
48
    {
49
        $this->setUpSuccess();
50
        $this->assertEquals($this->event->getKey(), $this->key);
51
52
        $this->setUpFailure();
53
        $this->assertNull($this->event->getKey());
54
    }
55
56
    public function testIsSuccess()
57
    {
58
        $this->setUpSuccess();
59
        $this->assertTrue($this->event->isSuccess());
60
61
        $this->setUpFailure();
62
        $this->assertFalse($this->event->isSuccess());
63
    }
64
65
    private function setUpFailure()
66
    {
67
        $this->user = $this->getMockForAbstractClass(U2fUser::class);
68
        $this->key = null;
69
70
        $this->event = new U2fPostAuthenticationEvent($this->user);
71
    }
72
73
    private function setUpSuccess()
74
    {
75
        $this->user = $this->getMockForAbstractClass(U2fUser::class);
76
        $this->key = $this->getMockForAbstractClass(U2fKey::class);
77
78
        $this->event = new U2fPostAuthenticationEvent($this->user, $this->key);
79
    }
80
}
81