CreateUserCest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
c 1
b 0
f 0
dl 0
loc 98
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createUserViaAPIFail() 0 7 1
A _before() 0 2 1
A makeValidateFailItems() 0 50 1
A createUser() 0 13 1
1
<?php
2
3
namespace app\tests\api;
4
5
use ApiTester;
6
use app\core\exceptions\ErrorCodes;
7
use Codeception\Example;
8
use Codeception\Util\HttpCode;
9
10
class CreateUserCest
11
{
12
    /**
13
     * @codingStandardsIgnoreStart
14
     * @param ApiTester $I
15
     */
16
    public function _before(ApiTester $I)
0 ignored issues
show
Unused Code introduced by
The parameter $I is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

16
    public function _before(/** @scrutinizer ignore-unused */ ApiTester $I)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        // @codingStandardsIgnoreEnd
19
    }
20
21
    /**
22
     * @return array
23
     */
24
    public function makeValidateFailItems()
25
    {
26
        return [
27
            [
28
                'data' => [
29
                    'username' => 'demo',
30
                    'email' => '[email protected]',
31
                    'password' => 'pass123',
32
                    'base_currency_code' => 'CNS',
33
                ],
34
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
35
            ],
36
            [
37
                'data' => [
38
                    'username' => 'demo',
39
                    'email' => '[email protected]',
40
                    'password' => 'pass123',
41
                ],
42
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
43
            ],
44
            [
45
                'data' => [
46
                    'username' => 'demo',
47
                    'email' => 'demo',
48
                    'password' => 'pass123',
49
                ],
50
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
51
            ],
52
            [
53
                'data' => [
54
                    'username' => 'demo-sdsdkj',
55
                    'email' => '[email protected]',
56
                    'password' => 'pass123',
57
                ],
58
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
59
            ],
60
            [
61
                'data' => [
62
                    'username' => 'demo-sdsdkj',
63
                    'email' => '[email protected]',
64
                    'password' => 'pass1',
65
                ],
66
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
67
            ],
68
            [
69
                'data' => [
70
                    'username' => 'demo-sdsdkj',
71
                    'password' => 'pass1',
72
                ],
73
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
74
            ],
75
        ];
76
    }
77
78
    /**
79
     * @dataProvider makeValidateFailItems
80
     * @param ApiTester $I
81
     * @param Example $example
82
     */
83
    public function createUserViaAPIFail(ApiTester $I, Example $example)
84
    {
85
        $I->haveHttpHeader('content-type', 'application/json');
86
        $I->sendPOST('/join', $example['data']);
87
        $I->seeResponseCodeIs(HttpCode::OK); // 200
88
        $I->seeResponseIsJson();
89
        $I->seeResponseContainsJson(['code' => $example['code']]);
90
    }
91
92
    /**
93
     * @param ApiTester $I
94
     */
95
    public function createUser(ApiTester $I)
96
    {
97
        $I->haveHttpHeader('content-type', 'application/json');
98
        $I->sendPOST('/join', [
99
            'username' => 'demo',
100
            'email' => '[email protected]',
101
            'password' => 'pass123',
102
            'base_currency_code' => 'CNY',
103
        ]);
104
        $I->seeResponseCodeIs(HttpCode::OK); // 200
105
        $I->seeResponseIsJson();
106
        $I->seeResponseContainsJson(['code' => 0]);
107
        $I->seeResponseJsonMatchesXpath('//data/username');
108
    }
109
}
110