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

InvalidateTokenCest::_before()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
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 InvalidateTokenCest
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
    /**
12
     * @var int
13
     */
14
    private $tokenId;
15
16
    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...
17
    {
18
        $userId = $I->haveInRepository(User::class, [
19
            'first' => 'Tester2',
20
            'last' => 'Tester2',
21
            'email' => '[email protected]',
22
        ]);
23
24
        $user = $I->grabEntityFromRepository(User::class, ['id' => $userId]);
25
26
        $this->tokenId = $I->haveInRepository(Token::class, [
27
            'owner' => $user,
28
            'active' => true,
29
            'token' => 'yyy',
30
            'due' => new DateTime('+1 year'),
31
            'createdAt' => new DateTime(),
32
        ]);
33
34
        $token = $I->grabEntityFromRepository(Token::class, ['id' => $this->tokenId]);
35
36
        $I->haveInRepository(Grant::class, [
37
            'token' => $token,
38
            'resource' => 'invalidate_token',
39
        ]);
40
41
        $I->amBearerAuthenticated('yyy');
42
    }
43
44
    public function invalidateTokenSuccess(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...
45
    {
46
        $I->wantTo('invalidate my token');
47
48
        $I->haveHttpHeader('Content-Type', 'application/json');
49
        $I->sendPut('/invalidatetoken/' . (string)$this->tokenId);
50
        $I->seeResponseCodeIs(HttpCode::OK);
51
        $I->seeResponseContainsJson([
52
            'success' => true,
53
            'data' => [
54
                'token' => [
55
                    'owner' => [
56
                        'email' => '[email protected]',
57
                    ],
58
                    'active' => 0,
59
                ],
60
            ],
61
        ]);
62
    }
63
64
    public function invalidateTokenNoPermissions(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 someone elses token');
67
68
        $I->haveHttpHeader('Content-Type', 'application/json');
69
        $I->sendPut('/invalidatetoken/1');
70
        $I->seeResponseCodeIs(HttpCode::FORBIDDEN);
71
        $I->seeResponseContainsJson([
72
            'success' => false,
73
            'data' => [],
74
        ]);
75
    }
76
77
    public function invalidateTokenCanNotFindToken(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...
78
    {
79
        $I->wantTo('invalidate token that doesn\'t exist');
80
81
        $I->haveHttpHeader('Content-Type', 'application/json');
82
        $I->sendPut('/invalidatetoken/100');
83
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
84
        $I->seeResponseContainsJson([
85
            'success' => false,
86
            'data' => [
87
                'token' => null,
88
            ],
89
        ]);
90
    }
91
}
92