TesterTrait::seePaginationHttpHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace roaresearch\yii2\roa\test;
4
5
trait TesterTrait
6
{
7
    /**
8
     * @var string[] pairs of user_name => oauth2_token for oauth2 auth.
9
     */
10
    protected static array $tokens = [];
11
12
    /**
13
     * @var string identificator for the auth/logged user.
14
     */
15
    protected string $loggedUsername;
16
17
    /**
18
     * Saves a token and user by an unique name.
19
     *
20
     * @param string $tokenName unique name to index the tokens and models
21
     * @param string $token oauth2 authorization token
22
     */
23
    public function storeToken(string $tokenName, string $token)
24
    {
25
        static::$tokens[$tokenName] = $token;
26
    }
27
28
    /**
29
     * Authenticates a user stored in `$tokens`
30
     *
31
     * @param string $tokenName
32
     */
33
    public function amAuthByToken(string $tokenName)
34
    {
35
        $this->amBearerAuthenticated(static::$tokens[$tokenName]);
0 ignored issues
show
Bug introduced by
It seems like amBearerAuthenticated() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

35
        $this->/** @scrutinizer ignore-call */ 
36
               amBearerAuthenticated(static::$tokens[$tokenName]);
Loading history...
36
    }
37
38
    /**
39
     * Checks over the HTTP pagination headers and (optionally) its values.
40
     */
41 2
    public function seePaginationHttpHeaders()
42
    {
43 2
        $this->seeHttpHeaderOnce('X-Pagination-Total-Count');
0 ignored issues
show
Bug introduced by
It seems like seeHttpHeaderOnce() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

43
        $this->/** @scrutinizer ignore-call */ 
44
               seeHttpHeaderOnce('X-Pagination-Total-Count');
Loading history...
44 2
        $this->seeHttpHeaderOnce('X-Pagination-Page-Count');
45 2
        $this->seeHttpHeaderOnce('X-Pagination-Current-Page');
46 2
        $this->seeHttpHeaderOnce('X-Pagination-Per-Page');
47
    }
48
49
    /**
50
     * Checks over the HTTP content type header value.
51
     */
52 10
    public function seeContentTypeHttpHeader(
53
        string $contentType = Tester::HAL_JSON_CONTENT_TYPE
54
    ) {
55 10
        $this->seeHttpHeader('Content-Type', $contentType);
0 ignored issues
show
Bug introduced by
It seems like seeHttpHeader() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

55
        $this->/** @scrutinizer ignore-call */ 
56
               seeHttpHeader('Content-Type', $contentType);
Loading history...
56
    }
57
}
58