1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Eljam\GuzzleJwt\Tests\Persistence; |
4
|
|
|
|
5
|
|
|
use Eljam\GuzzleJwt\JwtToken; |
6
|
|
|
use Eljam\GuzzleJwt\Persistence\NullTokenPersistence; |
7
|
|
|
use Eljam\GuzzleJwt\Persistence\SimpleCacheTokenPersistence; |
8
|
|
|
use Kodus\Cache\MockCache; |
9
|
|
|
use Psr\SimpleCache\CacheInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Nicolas Reynis (nreynis) |
13
|
|
|
*/ |
14
|
|
|
class TokenPersistenceTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* testNullTokenPersistence. |
18
|
|
|
*/ |
19
|
|
|
public function testNullTokenPersistence() |
20
|
|
|
{ |
21
|
|
|
$tokenPersistence = new NullTokenPersistence(); |
22
|
|
|
$token = new JwtToken('foo', new \DateTime('now')); |
23
|
|
|
|
24
|
|
|
$tokenPersistence->saveToken($token); |
|
|
|
|
25
|
|
|
|
26
|
|
|
$this->assertFalse($tokenPersistence->hasToken()); |
27
|
|
|
$this->assertNull($tokenPersistence->restoreToken()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* testSimpleCacheTokenPersistenceInterface. |
32
|
|
|
* Makes sure we only use the interface methods. |
33
|
|
|
*/ |
34
|
|
|
public function testSimpleCacheTokenPersistenceInterface() |
35
|
|
|
{ |
36
|
|
|
$simpleCache = $this->getMock(CacheInterface::class); |
37
|
|
|
$tokenPersistence = new SimpleCacheTokenPersistence($simpleCache); |
38
|
|
|
$token = new JwtToken('foo', new \DateTime('now')); |
39
|
|
|
|
40
|
|
|
$this->assertNull($tokenPersistence->saveToken($token)); |
41
|
|
|
$this->assertNull($tokenPersistence->hasToken()); |
42
|
|
|
$this->assertNull($tokenPersistence->restoreToken()); |
43
|
|
|
$this->assertNull($tokenPersistence->deleteToken()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* testSimpleCacheTokenPersistence. |
48
|
|
|
*/ |
49
|
|
|
public function testSimpleCacheTokenPersistence() |
50
|
|
|
{ |
51
|
|
|
$simpleCache = new MockCache(); |
52
|
|
|
$tokenPersistence = new SimpleCacheTokenPersistence($simpleCache); |
53
|
|
|
$token = new JwtToken('foo', new \DateTime('now')); |
54
|
|
|
|
55
|
|
|
$tokenPersistence->saveToken($token); |
56
|
|
|
|
57
|
|
|
$this->assertTrue($tokenPersistence->hasToken()); |
58
|
|
|
$this->assertEquals($tokenPersistence->restoreToken()->getToken(), $token->getToken()); |
59
|
|
|
|
60
|
|
|
$tokenPersistence->deleteToken(); |
61
|
|
|
|
62
|
|
|
$this->assertFalse($tokenPersistence->hasToken()); |
63
|
|
|
$this->assertNull($tokenPersistence->restoreToken()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: