-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TokenPersistence with PSR-16 cache adapter
- Loading branch information
Showing
8 changed files
with
326 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Eljam\GuzzleJwt\Tests\Persistence; | ||
|
||
use Eljam\GuzzleJwt\JwtToken; | ||
use Eljam\GuzzleJwt\Persistence\NullTokenPersistence; | ||
use Eljam\GuzzleJwt\Persistence\SimpleCacheTokenPersistence; | ||
use Symfony\Component\Cache\Simple\FilesystemCache; | ||
|
||
/** | ||
* @author Nicolas Reynis (nreynis) | ||
*/ | ||
class TokenPersistenceTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* testNullTokenPersistence. | ||
*/ | ||
public function testNullTokenPersistence() | ||
{ | ||
$tokenPersistence = new NullTokenPersistence(); | ||
$token = new JwtToken('foo', new \DateTime('now')); | ||
|
||
$tokenPersistence->saveToken($token); | ||
|
||
$this->assertFalse($tokenPersistence->hasToken()); | ||
$this->assertNull($tokenPersistence->restoreToken()); | ||
} | ||
|
||
/** | ||
* testSimpleCacheTokenPersistence. | ||
*/ | ||
public function testSimpleCacheTokenPersistence() | ||
{ | ||
$simpleCache = new FilesystemCache(); | ||
$tokenPersistence = new SimpleCacheTokenPersistence($simpleCache); | ||
$token = new JwtToken('foo', new \DateTime('now')); | ||
|
||
$tokenPersistence->saveToken($token); | ||
|
||
$this->assertTrue($tokenPersistence->hasToken()); | ||
$this->assertEquals($tokenPersistence->restoreToken()->getToken(), $token->getToken()); | ||
|
||
$tokenPersistence->deleteToken(); | ||
|
||
$this->assertFalse($tokenPersistence->hasToken()); | ||
$this->assertNull($tokenPersistence->restoreToken()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Eljam\GuzzleJwt\Persistence; | ||
|
||
use Eljam\GuzzleJwt\JwtToken; | ||
|
||
/** | ||
* @author Sevastian Hübner <[email protected]> | ||
*/ | ||
class NullTokenPersistence implements TokenPersistenceInterface | ||
{ | ||
public function saveToken(JwtToken $token) | ||
{ | ||
return; | ||
} | ||
|
||
public function restoreToken() | ||
{ | ||
return null; | ||
} | ||
|
||
public function deleteToken() | ||
{ | ||
return; | ||
} | ||
|
||
public function hasToken() | ||
{ | ||
return false; | ||
} | ||
} |
Oops, something went wrong.