SignupActionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 24.49 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 12
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A runAction() 0 6 1
A testViewSignup() 0 5 1
A testSignupSuccess() 12 12 1
A testSignupError() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace yii2mod\user\tests\actions;
4
5
use Yii;
6
use yii2mod\user\actions\SignupAction;
7
use yii2mod\user\tests\TestCase;
8
9
/**
10
 * Class SignupActionTest
11
 *
12
 * @package yii2mod\user\tests\actions
13
 */
14
class SignupActionTest extends TestCase
15
{
16
    /**
17
     * Runs the action.
18
     *
19
     * @param array $config
20
     *
21
     * @return array|\yii\web\Response response
22
     */
23
    protected function runAction(array $config = [])
24
    {
25
        $action = new SignupAction('signup', $this->createController(), $config);
26
27
        return $action->run();
28
    }
29
30
    // Tests:
31
32
    public function testViewSignup()
33
    {
34
        $response = $this->runAction();
35
        $this->assertEquals('@vendor/yii2mod/yii2-user/views/signup', $response['view']);
36
    }
37
38 View Code Duplication
    public function testSignupSuccess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        Yii::$app->request->bodyParams = [
41
            'SignupForm' => [
42
                'email' => '[email protected]',
43
                'password' => 'password',
44
                'username' => 'test-user',
45
            ],
46
        ];
47
        $this->runAction();
48
        $this->assertFalse(Yii::$app->user->isGuest);
49
    }
50
51
    public function testSignupError()
52
    {
53
        Yii::$app->request->bodyParams = [
54
            'SignupForm' => [
55
                'email' => '[email protected]',
56
                'password' => 'failed-password',
57
            ],
58
        ];
59
        $response = $this->runAction();
60
        $this->assertFalse($response['params']['model']->validate());
61
    }
62
}
63