QrCodeWidgetTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidCall() 0 8 2
A testMissingLabel() 0 12 2
A testValid() 0 13 1
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-mfa
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\test\unit\mfa;
9
10
use Yii;
11
12
use vxm\mfa\QrCodeWidget;
13
14
/**
15
 * Class QrCodeWidgetTest
16
 *
17
 * @author Vuong Minh <[email protected]>
18
 * @since 1.0.0
19
 */
20
class QrCodeWidgetTest extends TestCase
21
{
22
23
    public function testInvalidCall()
24
    {
25
        try {
26
            QrCodeWidget::widget();
27
        } catch (\Throwable $throwable) {
28
            $this->assertTrue($throwable instanceof \yii\base\InvalidCallException);
29
        }
30
    }
31
32
    /**
33
     * @depends testInvalidCall
34
     */
35
    public function testMissingLabel()
36
    {
37
        $identity = Identity::findIdentity('user1');
38
        Yii::$app->user->login($identity);
39
        Yii::$app->user->switchIdentityLoggedIn();
40
41
        try {
42
            QrCodeWidget::widget();
43
        } catch (\Throwable $throwable) {
44
            $this->assertTrue($throwable instanceof \Assert\InvalidArgumentException);
45
        }
46
    }
47
48
    /**
49
     * @depends testMissingLabel
50
     */
51
    public function testValid()
52
    {
53
        $identity = Identity::findIdentity('user1');
54
        Yii::$app->user->login($identity);
55
        Yii::$app->user->switchIdentityLoggedIn();
56
57
        $result = QrCodeWidget::widget([
58
            'label' => 'vxm',
59
            'image' => 'https://abc.com',
60
            'issuer' => 'Test'
61
        ]);
62
        $this->assertNotEmpty($result);
63
    }
64
65
}
66