Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 812f2ba

Browse files
committed
Handle fetch mode deprecation of DBAL 2.11.
1 parent ce61bb0 commit 812f2ba

File tree

4 files changed

+95
-4
lines changed

4 files changed

+95
-4
lines changed

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function loadTokenBySeries($series)
6363
$paramValues = ['series' => $series];
6464
$paramTypes = ['series' => \PDO::PARAM_STR];
6565
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
66-
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
66+
$row = method_exists($stmt, 'fetchAssociative') ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC);
6767

6868
if ($row) {
6969
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['last_used']));
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Security\RememberMe;
4+
5+
use Doctrine\DBAL\DriverManager;
6+
use PHPUnit\Framework\TestCase;
7+
use Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider;
8+
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
9+
use Symfony\Component\Security\Core\Exception\TokenNotFoundException;
10+
11+
class DoctrineTokenProviderTest extends TestCase
12+
{
13+
public static function setUpBeforeClass()
14+
{
15+
if (\PHP_VERSION_ID >= 80000) {
16+
self::markTestSkipped('Doctrine DBAL 2.x is incompatible with PHP 8.');
17+
}
18+
}
19+
20+
public function testCreateNewToken()
21+
{
22+
$provider = $this->bootstrapProvider();
23+
24+
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTime('2013-01-26T18:23:51'));
25+
$provider->createNewToken($token);
26+
27+
$this->assertEquals($provider->loadTokenBySeries('someSeries'), $token);
28+
}
29+
30+
public function testLoadTokenBySeriesThrowsNotFoundException()
31+
{
32+
$provider = $this->bootstrapProvider();
33+
34+
$this->expectException(TokenNotFoundException::class);
35+
$provider->loadTokenBySeries('someSeries');
36+
}
37+
38+
public function testUpdateToken()
39+
{
40+
$provider = $this->bootstrapProvider();
41+
42+
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTime('2013-01-26T18:23:51'));
43+
$provider->createNewToken($token);
44+
$provider->updateToken('someSeries', 'newValue', $lastUsed = new \DateTime('2014-06-26T22:03:46'));
45+
$token = $provider->loadTokenBySeries('someSeries');
46+
47+
$this->assertEquals('newValue', $token->getTokenValue());
48+
$this->assertEquals($token->getLastUsed(), $lastUsed);
49+
}
50+
51+
public function testDeleteToken()
52+
{
53+
$provider = $this->bootstrapProvider();
54+
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTime('2013-01-26T18:23:51'));
55+
$provider->createNewToken($token);
56+
$provider->deleteTokenBySeries('someSeries');
57+
58+
$this->expectException(TokenNotFoundException::class);
59+
60+
$provider->loadTokenBySeries('someSeries');
61+
}
62+
63+
/**
64+
* @return DoctrineTokenProvider
65+
*/
66+
private function bootstrapProvider()
67+
{
68+
$connection = DriverManager::getConnection([
69+
'driver' => 'pdo_sqlite',
70+
'url' => 'sqlite:///:memory:',
71+
]);
72+
$connection->executeUpdate(<<< 'SQL'
73+
CREATE TABLE rememberme_token (
74+
series char(88) UNIQUE PRIMARY KEY NOT NULL,
75+
value char(88) NOT NULL,
76+
lastUsed datetime NOT NULL,
77+
class varchar(100) NOT NULL,
78+
username varchar(200) NOT NULL
79+
);
80+
SQL
81+
);
82+
83+
return new DoctrineTokenProvider($connection);
84+
}
85+
}

src/Symfony/Component/Cache/Tests/Traits/PdoPruneableTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ protected function isPruned($cache, $name)
2424
$getPdoConn = $o->getMethod('getConnection');
2525
$getPdoConn->setAccessible(true);
2626

27-
/** @var \Doctrine\DBAL\Statement $select */
27+
/** @var \Doctrine\DBAL\Statement|\PDOStatement $select */
2828
$select = $getPdoConn->invoke($cache)->prepare('SELECT 1 FROM cache_items WHERE item_id LIKE :id');
2929
$select->bindValue(':id', sprintf('%%%s', $name));
3030
$select->execute();
3131

32-
return 0 === \count($select->fetchAll(\PDO::FETCH_COLUMN));
32+
return 1 !== (int) (method_exists($select, 'fetchOne') ? $select->fetchOne() : $select->fetch(\PDO::FETCH_COLUMN));
3333
}
3434
}

src/Symfony/Component/Cache/Traits/PdoTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ protected function doFetch(array $ids)
177177
}
178178
$stmt->execute();
179179

180-
while ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
180+
if (method_exists($stmt, 'iterateNumeric')) {
181+
$stmt = $stmt->iterateNumeric();
182+
} else {
183+
$stmt->setFetchMode(\PDO::FETCH_NUM);
184+
}
185+
186+
foreach ($stmt as $row) {
181187
if (null === $row[1]) {
182188
$expired[] = $row[0];
183189
} else {

0 commit comments

Comments
 (0)