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

U2fPreRegistrationEventTest::testReason()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
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\Registration;
13
14
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
15
use Mbarbey\U2fSecurityBundle\Model\User\U2fUser;
16
use Mbarbey\U2fSecurityBundle\Event\Registration\U2fPreRegistrationEvent;
17
18
class U2fPreRegistrationEventTest extends TestCase
19
{
20
    private $appId;
21
    private $event;
22
    private $user;
23
    private $reason;
24
25
    public function testName()
26
    {
27
        $name = 'u2f.registration.before';
28
29
        $this->assertEquals(U2fPreRegistrationEvent::getName(), $name);
30
31
        $this->setUpAllowed();
32
        $this->assertEquals($this->event->getName(), $name);
33
34
        $this->setUpDeniedWithReason();
35
        $this->assertEquals($this->event->getName(), $name);
36
37
        $this->setUpDeniedWithoutReason();
38
        $this->assertEquals($this->event->getName(), $name);
39
    }
40
41
    public function testAppId()
42
    {
43
        $this->setUpAllowed();
44
        $this->assertEquals($this->event->getAppId(), $this->appId);
45
46
        $this->setUpDeniedWithReason();
47
        $this->assertEquals($this->event->getAppId(), $this->appId);
48
49
        $this->setUpDeniedWithoutReason();
50
        $this->assertEquals($this->event->getAppId(), $this->appId);
51
    }
52
53
    public function testUser()
54
    {
55
        $this->setUpAllowed();
56
        $this->assertEquals($this->event->getUser(), $this->user);
57
58
        $this->setUpDeniedWithReason();
59
        $this->assertEquals($this->event->getUser(), $this->user);
60
61
        $this->setUpDeniedWithoutReason();
62
        $this->assertEquals($this->event->getUser(), $this->user);
63
    }
64
65
    public function testIsAborted()
66
    {
67
        $this->setUpAllowed();
68
        $this->assertFalse($this->event->isAborted());
69
70
        $this->setUpDeniedWithReason();
71
        $this->assertTrue($this->event->isAborted());
72
73
        $this->setUpDeniedWithoutReason();
74
        $this->assertTrue($this->event->isAborted());
75
    }
76
77
    public function testReason()
78
    {
79
        $this->setUpAllowed();
80
        $this->assertNull($this->event->getReason());
81
82
        $this->setUpDeniedWithReason();
83
        $this->assertEquals($this->event->getReason(), $this->reason);
84
85
        $this->setUpDeniedWithoutReason();
86
        $this->assertNull($this->event->getReason());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->event->getReason() targeting Mbarbey\U2fSecurityBundl...ationEvent::getReason() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
87
    }
88
89
    private function setUpAllowed()
90
    {
91
        $this->user = $this->getMockForAbstractClass(U2fUser::class);
92
        $this->appId = random_bytes(8);
93
94
        $this->event = new U2fPreRegistrationEvent($this->appId, $this->user);
95
    }
96
97
    private function setUpDeniedWithReason()
98
    {
99
        $this->setUpAllowed();
100
101
        $this->reason = random_bytes(16);
102
        $this->event->abort($this->reason);
103
    }
104
105
    private function setUpDeniedWithoutReason()
106
    {
107
        $this->setUpAllowed();
108
109
        $this->event->abort();
110
    }
111
}
112