Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle fetch mode deprecation of DBAL 2.11.
- Loading branch information
Showing
4 changed files
with
98 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
88 changes: 88 additions & 0 deletions
88
src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php
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,88 @@ | ||
<?php | ||
|
||
namespace Security\RememberMe; | ||
|
||
use Doctrine\DBAL\DriverManager; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider; | ||
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken; | ||
use Symfony\Component\Security\Core\Exception\TokenNotFoundException; | ||
|
||
class DoctrineTokenProviderTest extends TestCase | ||
{ | ||
public static function setUpBeforeClass() | ||
{ | ||
if (!\extension_loaded('pdo_sqlite')) { | ||
self::markTestSkipped('Extension pdo_sqlite is required.'); | ||
} | ||
if (\PHP_VERSION_ID >= 80000) { | ||
self::markTestSkipped('Doctrine DBAL 2.x is incompatible with PHP 8.'); | ||
} | ||
} | ||
|
||
public function testCreateNewToken() | ||
{ | ||
$provider = $this->bootstrapProvider(); | ||
|
||
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTime('2013-01-26T18:23:51')); | ||
$provider->createNewToken($token); | ||
|
||
$this->assertEquals($provider->loadTokenBySeries('someSeries'), $token); | ||
} | ||
|
||
public function testLoadTokenBySeriesThrowsNotFoundException() | ||
{ | ||
$provider = $this->bootstrapProvider(); | ||
|
||
$this->expectException(TokenNotFoundException::class); | ||
$provider->loadTokenBySeries('someSeries'); | ||
} | ||
|
||
public function testUpdateToken() | ||
{ | ||
$provider = $this->bootstrapProvider(); | ||
|
||
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTime('2013-01-26T18:23:51')); | ||
$provider->createNewToken($token); | ||
$provider->updateToken('someSeries', 'newValue', $lastUsed = new \DateTime('2014-06-26T22:03:46')); | ||
$token = $provider->loadTokenBySeries('someSeries'); | ||
|
||
$this->assertEquals('newValue', $token->getTokenValue()); | ||
$this->assertEquals($token->getLastUsed(), $lastUsed); | ||
} | ||
|
||
public function testDeleteToken() | ||
{ | ||
$provider = $this->bootstrapProvider(); | ||
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTime('2013-01-26T18:23:51')); | ||
$provider->createNewToken($token); | ||
$provider->deleteTokenBySeries('someSeries'); | ||
|
||
$this->expectException(TokenNotFoundException::class); | ||
|
||
$provider->loadTokenBySeries('someSeries'); | ||
} | ||
|
||
/** | ||
* @return DoctrineTokenProvider | ||
*/ | ||
private function bootstrapProvider() | ||
{ | ||
$connection = DriverManager::getConnection([ | ||
'driver' => 'pdo_sqlite', | ||
'url' => 'sqlite:///:memory:', | ||
]); | ||
$connection->executeUpdate(<<< 'SQL' | ||
CREATE TABLE rememberme_token ( | ||
series char(88) UNIQUE PRIMARY KEY NOT NULL, | ||
value char(88) NOT NULL, | ||
lastUsed datetime NOT NULL, | ||
class varchar(100) NOT NULL, | ||
username varchar(200) NOT NULL | ||
); | ||
SQL | ||
); | ||
|
||
return new DoctrineTokenProvider($connection); | ||
} | ||
} |
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