StorageTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 59
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testStorage() 0 19 1
A testHasAccessToken() 0 10 1
A testStorageClears() 0 14 1
1
<?php
2
3
/**
4
 * @author     David Desberg <[email protected]>
5
 * @author     Hannes Van De Vreken <[email protected]>
6
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
7
 */
8
9
namespace OAuth\Unit\Common\Storage;
10
11
use OAuth\OAuth2\Token\StdOAuth2Token;
12
use PHPUnit\Framework\TestCase;
13
14
abstract class StorageTest extends TestCase
15
{
16
    protected $storage;
17
18
    /**
19
     * Check that the token gets properly stored.
20
     */
21
    public function testStorage(): void
22
    {
23
        // arrange
24
        $service_1 = 'Facebook';
25
        $service_2 = 'Foursquare';
26
27
        $token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, ['extra' => 'param']);
28
        $token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, ['extra' => 'param']);
29
30
        // act
31
        $this->storage->storeAccessToken($service_1, $token_1);
32
        $this->storage->storeAccessToken($service_2, $token_2);
33
34
        // assert
35
        $extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams();
36
        self::assertEquals('param', $extraParams['extra']);
37
        self::assertEquals($token_1, $this->storage->retrieveAccessToken($service_1));
38
        self::assertEquals($token_2, $this->storage->retrieveAccessToken($service_2));
39
    }
40
41
    /**
42
     * Test hasAccessToken.
43
     */
44
    public function testHasAccessToken(): void
45
    {
46
        // arrange
47
        $service = 'Facebook';
48
        $this->storage->clearToken($service);
49
50
        // act
51
        // assert
52
        self::assertFalse($this->storage->hasAccessToken($service));
53
    }
54
55
    /**
56
     * Check that the token gets properly deleted.
57
     */
58
    public function testStorageClears(): void
59
    {
60
        // arrange
61
        $service = 'Facebook';
62
        $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, ['extra' => 'param']);
63
64
        // act
65
        $this->storage->storeAccessToken($service, $token);
66
        $this->storage->clearToken($service);
67
68
        // assert
69
        $this->expectException('OAuth\Common\Storage\Exception\TokenNotFoundException');
70
        $this->storage->retrieveAccessToken($service);
71
    }
72
}
73