CreateUserCest::makeValidateFailItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 20
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 33
rs 9.6
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' => 'demo',
31
                    'password' => 'pass123',
32
                ],
33
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
34
            ],
35
            [
36
                'data' => [
37
                    'username' => 'demo-sdsdkj',
38
                    'email' => '[email protected]',
39
                    'password' => 'pass123',
40
                ],
41
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
42
            ],
43
            [
44
                'data' => [
45
                    'username' => 'demo-sdsdkj',
46
                    'email' => '[email protected]',
47
                    'password' => 'pass1',
48
                ],
49
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
50
            ],
51
            [
52
                'data' => [
53
                    'username' => 'demo-sdsdkj',
54
                    'password' => 'pass1',
55
                ],
56
                'code' => ErrorCodes::INVALID_ARGUMENT_ERROR
57
            ],
58
        ];
59
    }
60
61
    /**
62
     * @dataProvider makeValidateFailItems
63
     * @param ApiTester $I
64
     * @param Example $example
65
     */
66
    public function createUserViaAPIFail(ApiTester $I, Example $example)
67
    {
68
        $I->haveHttpHeader('content-type', 'application/json');
69
        $I->sendPOST('/join', $example['data']);
70
        $I->seeResponseCodeIs(HttpCode::OK); // 200
71
        $I->seeResponseIsJson();
72
        $I->seeResponseContainsJson(['code' => $example['code']]);
73
    }
74
75
    /**
76
     * @param ApiTester $I
77
     */
78
    public function createUser(ApiTester $I)
79
    {
80
        $I->haveHttpHeader('content-type', 'application/json');
81
        $I->sendPOST('/join', [
82
            'username' => 'demo',
83
            'email' => '[email protected]',
84
            'password' => 'pass123',
85
        ]);
86
        $I->seeResponseCodeIs(HttpCode::OK); // 200
87
        $I->seeResponseIsJson();
88
        $I->seeResponseContainsJson(['code' => 0]);
89
        $I->seeResponseJsonMatchesXpath('//data/username');
90
    }
91
}
92