SignupFormTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSignupWithoutCredentials() 0 6 1
A testSignupWithAlreadyExistUsername() 0 10 1
A testSignupWithAlreadyExistEmail() 0 11 1
A testSignupCorrect() 0 10 1
1
<?php
2
3
namespace yii2mod\user\tests\forms;
4
5
use yii2mod\user\models\SignupForm;
6
use yii2mod\user\models\UserModel;
7
use yii2mod\user\tests\TestCase;
8
9
/**
10
 * Class SignupFormTest
11
 *
12
 * @package yii2mod\user\tests\forms
13
 */
14
class SignupFormTest extends TestCase
15
{
16
    public function testSignupWithoutCredentials()
17
    {
18
        $model = new SignupForm();
19
20
        $this->assertNull($model->signup());
21
    }
22
23
    public function testSignupWithAlreadyExistUsername()
24
    {
25
        $model = new SignupForm();
26
        $model->email = '[email protected]';
27
        $model->password = 'password';
28
        $model->username = 'demo';
29
30
        $this->assertNull($model->signup());
31
        $this->assertArrayHasKey('username', $model->errors);
32
    }
33
34
    public function testSignupWithAlreadyExistEmail()
35
    {
36
        $model = new SignupForm();
37
        $model->email = '[email protected]';
38
        $model->password = 'password';
39
        $model->username = 'demo';
40
41
        $this->assertNull($model->signup());
42
        $this->assertNull($model->getUser());
43
        $this->assertArrayHasKey('email', $model->errors);
44
    }
45
46
    public function testSignupCorrect()
47
    {
48
        $model = new SignupForm();
49
        $model->email = '[email protected]';
50
        $model->password = 'password';
51
        $model->username = 'demo2';
52
53
        $this->assertInstanceOf(UserModel::class, $model->signup());
54
        $this->assertInstanceOf(UserModel::class, $model->getUser());
55
    }
56
}
57