Completed
Push — master ( 178a08...5c0b6f )
by Oleg
05:22
created

InvalidateTokensCest::invalidateAllTokensSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
use Codeception\Util\HttpCode;
5
use SlayerBirden\DataFlowServer\Authentication\Entities\Grant;
6
use SlayerBirden\DataFlowServer\Authentication\Entities\Token;
7
use SlayerBirden\DataFlowServer\Domain\Entities\User;
8
9
class InvalidateTokensCest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    public function _before(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
12
    {
13
        $userId = $I->haveInRepository(User::class, [
14
            'first' => 'Tester2',
15
            'last' => 'Tester2',
16
            'email' => '[email protected]',
17
        ]);
18
19
        $user = $I->grabEntityFromRepository(User::class, ['id' => $userId]);
20
21
        $tokenId = $I->haveInRepository(Token::class, [
22
            'owner' => $user,
23
            'active' => true,
24
            'token' => 'yyy',
25
            'due' => new DateTime('+1 year'),
26
            'createdAt' => new DateTime(),
27
        ]);
28
29
        $token = $I->grabEntityFromRepository(Token::class, ['id' => $tokenId]);
30
31
        $I->haveInRepository(Grant::class, [
32
            'token' => $token,
33
            'resource' => 'invalidate_tokens',
34
        ]);
35
36
        $I->amBearerAuthenticated('yyy');
37
    }
38
39
    public function invalidateTokensSuccess(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
40
    {
41
        $I->wantTo('invalidate other user\'s token');
42
43
        $I->haveHttpHeader('Content-Type', 'application/json');
44
        $I->sendPost('/invalidatetokens', [
45
            'users' => [1]
46
        ]);
47
        $I->seeResponseCodeIs(HttpCode::OK);
48
        $I->seeResponseContainsJson([
49
            'success' => true,
50
            'data' => [
51
                'tokens' => [
52
                    [
53
                        'owner' => [
54
                            'email' => '[email protected]',
55
                        ],
56
                        'active' => 0,
57
                    ]
58
                ],
59
                'count' => 1
60
            ],
61
        ]);
62
    }
63
64
    public function invalidateAllTokensSuccess(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
65
    {
66
        $I->wantTo('invalidate all tokens');
67
68
        $I->haveHttpHeader('Content-Type', 'application/json');
69
        $I->sendPost('/invalidatetokens');
70
        $I->seeResponseCodeIs(HttpCode::OK);
71
        $I->seeResponseContainsJson([
72
            'success' => true,
73
            'data' => [
74
                'count' => 2
75
            ],
76
        ]);
77
    }
78
79
    public function invalidateTokesWrongUsers(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
80
    {
81
        $I->wantTo('invalidate wrong user\'s token');
82
83
        $I->haveHttpHeader('Content-Type', 'application/json');
84
        $I->sendPost('/invalidatetokens', [
85
            'users' => [10]
86
        ]);
87
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
88
        $I->seeResponseContainsJson([
89
            'success' => false,
90
            'data' => [
91
                'tokens' => [],
92
                'count' => 0
93
            ],
94
        ]);
95
    }
96
}
97