MemoryTest::testConstructCorrectInterface()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace OAuthTest\Unit\Common\Storage;
4
5
use OAuth\Common\Storage\Memory;
6
use PHPUnit\Framework\TestCase;
7
8
class MemoryTest extends TestCase
9
{
10
    /**
11
     * @covers \OAuth\Common\Storage\Memory::__construct
12
     */
13
    public function testConstructCorrectInterface(): void
14
    {
15
        $storage = new Memory();
16
17
        self::assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage);
18
    }
19
20
    /**
21
     * @covers \OAuth\Common\Storage\Memory::__construct
22
     * @covers \OAuth\Common\Storage\Memory::storeAccessToken
23
     */
24
    public function testStoreAccessToken(): void
25
    {
26
        $storage = new Memory();
27
28
        self::assertInstanceOf(
29
            '\\OAuth\\Common\\Storage\\Memory',
30
            $storage->storeAccessToken('foo', $this->createMock('\\OAuth\\Common\\Token\\TokenInterface'))
0 ignored issues
show
Documentation introduced by
$this->createMock('\\OAu...Token\\TokenInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Token\TokenInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
        );
32
    }
33
34
    /**
35
     * @covers \OAuth\Common\Storage\Memory::__construct
36
     * @covers \OAuth\Common\Storage\Memory::hasAccessToken
37
     * @covers \OAuth\Common\Storage\Memory::retrieveAccessToken
38
     * @covers \OAuth\Common\Storage\Memory::storeAccessToken
39
     */
40
    public function testRetrieveAccessTokenValid(): void
41
    {
42
        $storage = new Memory();
43
44
        $storage->storeAccessToken('foo', $this->createMock('\\OAuth\\Common\\Token\\TokenInterface'));
0 ignored issues
show
Documentation introduced by
$this->createMock('\\OAu...Token\\TokenInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Token\TokenInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
46
        self::assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $storage->retrieveAccessToken('foo'));
47
    }
48
49
    /**
50
     * @covers \OAuth\Common\Storage\Memory::__construct
51
     * @covers \OAuth\Common\Storage\Memory::hasAccessToken
52
     * @covers \OAuth\Common\Storage\Memory::retrieveAccessToken
53
     */
54
    public function testRetrieveAccessTokenThrowsExceptionWhenTokenIsNotFound(): void
55
    {
56
        $this->expectException('\\OAuth\\Common\\Storage\\Exception\\TokenNotFoundException');
57
58
        $storage = new Memory();
59
60
        $storage->retrieveAccessToken('foo');
61
    }
62
63
    /**
64
     * @covers \OAuth\Common\Storage\Memory::__construct
65
     * @covers \OAuth\Common\Storage\Memory::hasAccessToken
66
     * @covers \OAuth\Common\Storage\Memory::storeAccessToken
67
     */
68
    public function testHasAccessTokenTrue(): void
69
    {
70
        $storage = new Memory();
71
72
        $storage->storeAccessToken('foo', $this->createMock('\\OAuth\\Common\\Token\\TokenInterface'));
0 ignored issues
show
Documentation introduced by
$this->createMock('\\OAu...Token\\TokenInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Token\TokenInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
74
        self::assertTrue($storage->hasAccessToken('foo'));
75
    }
76
77
    /**
78
     * @covers \OAuth\Common\Storage\Memory::__construct
79
     * @covers \OAuth\Common\Storage\Memory::hasAccessToken
80
     */
81
    public function testHasAccessTokenFalse(): void
82
    {
83
        $storage = new Memory();
84
85
        self::assertFalse($storage->hasAccessToken('foo'));
86
    }
87
88
    /**
89
     * @covers \OAuth\Common\Storage\Memory::__construct
90
     * @covers \OAuth\Common\Storage\Memory::clearToken
91
     */
92
    public function testClearTokenIsNotSet(): void
93
    {
94
        $storage = new Memory();
95
96
        self::assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo'));
97
    }
98
99
    /**
100
     * @covers \OAuth\Common\Storage\Memory::__construct
101
     * @covers \OAuth\Common\Storage\Memory::clearToken
102
     * @covers \OAuth\Common\Storage\Memory::storeAccessToken
103
     */
104
    public function testClearTokenSet(): void
105
    {
106
        $storage = new Memory();
107
108
        $storage->storeAccessToken('foo', $this->createMock('\\OAuth\\Common\\Token\\TokenInterface'));
0 ignored issues
show
Documentation introduced by
$this->createMock('\\OAu...Token\\TokenInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Token\TokenInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
109
110
        self::assertTrue($storage->hasAccessToken('foo'));
111
        self::assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo'));
112
        self::assertFalse($storage->hasAccessToken('foo'));
113
    }
114
115
    /**
116
     * @covers \OAuth\Common\Storage\Memory::__construct
117
     * @covers \OAuth\Common\Storage\Memory::clearAllTokens
118
     * @covers \OAuth\Common\Storage\Memory::storeAccessToken
119
     */
120
    public function testClearAllTokens(): void
121
    {
122
        $storage = new Memory();
123
124
        $storage->storeAccessToken('foo', $this->createMock('\\OAuth\\Common\\Token\\TokenInterface'));
0 ignored issues
show
Documentation introduced by
$this->createMock('\\OAu...Token\\TokenInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Token\TokenInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
125
        $storage->storeAccessToken('bar', $this->createMock('\\OAuth\\Common\\Token\\TokenInterface'));
0 ignored issues
show
Documentation introduced by
$this->createMock('\\OAu...Token\\TokenInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Token\TokenInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
126
127
        self::assertTrue($storage->hasAccessToken('foo'));
128
        self::assertTrue($storage->hasAccessToken('bar'));
129
        self::assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearAllTokens());
130
        self::assertFalse($storage->hasAccessToken('foo'));
131
        self::assertFalse($storage->hasAccessToken('bar'));
132
    }
133
}
134