LoginUserCest::userLogin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 13
rs 9.9332
1
<?php
2
3
namespace app\tests\api;
4
5
// @codingStandardsIgnoreLine
6
use ApiTester;
7
use app\core\exceptions\ErrorCodes;
8
use Codeception\Util\HttpCode;
9
10
class LoginUserCest
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
     * @param ApiTester $I
23
     */
24
    public function userLoginFail(ApiTester $I)
25
    {
26
        $I->haveHttpHeader('content-type', 'application/json');
27
        $I->sendPOST('/login', [
28
            'username' => 'demo',
29
            'password' => 'pass123456',
30
        ]);
31
        $I->seeResponseCodeIs(HttpCode::OK); // 200
32
        $I->seeResponseIsJson();
33
        $I->seeResponseContainsJson(['code' => ErrorCodes::INVALID_ARGUMENT_ERROR]);
34
    }
35
36
37
    /**
38
     * @param ApiTester $I
39
     * @param CreateUserCest $createUserCest
40
     */
41
    public function userLogin(ApiTester $I, CreateUserCest $createUserCest)
42
    {
43
        $createUserCest->createUser($I);
44
        $I->haveHttpHeader('content-type', 'application/json');
45
        $I->sendPOST('/login', [
46
            'username' => 'demo',
47
            'password' => 'pass123',
48
        ]);
49
        $I->seeResponseCodeIs(HttpCode::OK); // 200
50
        $I->seeResponseIsJson();
51
        $I->seeResponseContainsJson(['code' => 0]);
52
        $I->seeResponseJsonMatchesXpath('//data/token');
53
        $I->seeResponseJsonMatchesXpath('//data/user/username');
54
    }
55
}
56