Completed
Push — master ( 49a7fe...07d1f7 )
by Guillaume
02:11
created

testSimpleCacheTokenPersistence()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 Symfony\Component\Cache\Simple\FilesystemCache;
9
10
/**
11
 * @author Nicolas Reynis (nreynis)
12
 */
13
class TokenPersistenceTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * testNullTokenPersistence.
17
     */
18
    public function testNullTokenPersistence()
19
    {
20
        $tokenPersistence = new NullTokenPersistence();
21
        $token = new JwtToken('foo', new \DateTime('now'));
22
23
        $tokenPersistence->saveToken($token);
0 ignored issues
show
Unused Code introduced by
The call to the method Eljam\GuzzleJwt\Persiste...ersistence::saveToken() seems un-needed as the method has no side-effects.

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:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

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:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

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:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
24
25
        $this->assertFalse($tokenPersistence->hasToken());
26
        $this->assertNull($tokenPersistence->restoreToken());
27
    }
28
29
    /**
30
     * testSimpleCacheTokenPersistence.
31
     */
32
    public function testSimpleCacheTokenPersistence()
33
    {
34
        $simpleCache = new FilesystemCache();
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Cache\Simple\FilesystemCache has been deprecated with message: since Symfony 4.3, use FilesystemAdapter and type-hint for CacheInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
35
        $tokenPersistence = new SimpleCacheTokenPersistence($simpleCache);
36
        $token = new JwtToken('foo', new \DateTime('now'));
37
38
        $tokenPersistence->saveToken($token);
39
40
        $this->assertTrue($tokenPersistence->hasToken());
41
        $this->assertEquals($tokenPersistence->restoreToken()->getToken(), $token->getToken());
42
43
        $tokenPersistence->deleteToken();
44
45
        $this->assertFalse($tokenPersistence->hasToken());
46
        $this->assertNull($tokenPersistence->restoreToken());
47
    }
48
}
49