10000 Merge branch '5.4' into 6.4 · symfonyaml/symfony@cb40d76 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb40d76

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: Update deprecations baseline drop existing schema if tests create it explicitly synchronize line numbers in deprecations baseline Add integration test for RememberMe with pg connection fix: DoctrineTokenProvider not oracle compatible
2 parents d7a5a09 + c6ab692 commit cb40d76

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ public function __construct(
5252

5353
public function loadTokenBySeries(string $series): PersistentTokenInterface
5454
{
55-
// the alias for lastUsed works around case insensitivity in PostgreSQL
56-
$sql = 'SELECT class, username, value, lastUsed AS last_used FROM rememberme_token WHERE series=:series';
55+
$sql = 'SELECT class, username, value, lastUsed FROM rememberme_token WHERE series=:series';
5756
$paramValues = ['series' => $series];
5857
$paramTypes = ['series' => ParameterType::STRING];
5958
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
60-
$row = $stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC);
59+
60+
// fetching numeric because column name casing depends on platform, eg. Oracle converts all not quoted names to uppercase
61+
$row = $stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchNumeric() : $stmt->fetch(\PDO::FETCH_NUM);
6162

6263
if ($row) {
63-
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTimeImmutable($row['last_used']));
64+
[$class, $username, $value, $last_used] = $row;
65+
return new PersistentToken($class, $username, $series, $value, new \DateTimeImmutable($last_used));
6466
}
6567

6668
throw new TokenNotFoundException('No token found.');
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Doctrine\Tests\Security\RememberMe;
4+
5+
use Doctrine\DBAL\Configuration;
6+
use Doctrine\DBAL\DriverManager;
7+
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
8+
use Doctrine\ORM\ORMSetup;
9+
use Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider;
10+
11+
/**
12+
* @requires extension pdo_pgsql
13+
* @group integration
14+
*/
15+
class DoctrineTokenProviderPostgresTest extends DoctrineTokenProviderTest
16+
{
17+
public static function setUpBeforeClass(): void
18+
{
19+
if (!getenv('POSTGRES_HOST')) {
20+
self::markTestSkipped('Missing POSTGRES_HOST env variable');
21+
}
22+
}
23+
24+
protected function bootstrapProvider()
25+
{
26+
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
27+
if (class_exists(DefaultSchemaManagerFactory::class)) {
28+
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
29+
}
30+
31+
$connection = DriverManager::getConnection([
32+
'driver' => 'pdo_pgsql',
33+
'host' => getenv('POSTGRES_HOST'),
34+
'user' => 'postgres',
35+
'password' => 'password',
36+
], $config);
37+
$connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<<'SQL'
38+
DROP TABLE IF EXISTS rememberme_token;
39+
SQL
40+
);
41+
42+
$connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<<'SQL'
43+
CREATE TABLE rememberme_token (
44+
series CHAR(88) UNIQUE PRIMARY KEY NOT NULL,
45+
value VARCHAR(88) NOT NULL, -- CHAR(88) adds spaces at the end
46+
lastUsed TIMESTAMP NOT NULL,
47+
class VARCHAR(100) NOT NULL,
48+
username VARCHAR(200) NOT NULL
49+
);
50+
SQL
51+
);
52+
53+
return new DoctrineTokenProvider($connection);
54+
}
55+
}

src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Security\RememberMe;
12+
namespace Symfony\Bridge\Doctrine\Tests\Security\RememberMe;
1313

1414
use Doctrine\DBAL\DriverManager;
1515
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
@@ -120,7 +120,7 @@ public function testVerifyOutdatedTokenAfterParallelRequestFailsAfter60Seconds()
120120
/**
121121
* @return DoctrineTokenProvider
122122
*/
123-
private function bootstrapProvider()
123+
protected function bootstrapProvider()
124124
{
125125
$config = ORMSetup::createConfiguration(true);
126126
if (class_exists(DefaultSchemaManagerFactory::class)) {

src/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterfac
4848

4949
public function testConfigureSchemaDecoratedDbalDriver()
5050
{
51+
if (file_exists(self::$dbFile)) {
52+
@unlink(self::$dbFile);
53+
}
54+
5155
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $this->getDbalConfig());
5256
if (!interface_exists(Middleware::class)) {
5357
$this->markTestSkipped('doctrine/dbal v2 does not support custom drivers using middleware');
@@ -73,6 +77,10 @@ public function testConfigureSchemaDecoratedDbalDriver()
7377

7478
public function testConfigureSchema()
7579
{
80+
if (file_exists(self::$dbFile)) {
81+
@unlink(self::$dbFile);
82+
}
83+
7684
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $this->getDbalConfig());
7785
$schema = new Schema();
7886

@@ -83,6 +91,10 @@ public function testConfigureSchema()
8391

8492
public function testConfigureSchemaDifferentDbalConnection()
8593
{
94+
if (file_exists(self::$dbFile)) {
95+
@unlink(self::$dbFile);
96+
}
97+
8698
$otherConnection = $this->createConnectionMock();
8799
$schema = new Schema();
88100

@@ -93,6 +105,10 @@ public function testConfigureSchemaDifferentDbalConnection()
93105

94106
public function testConfigureSchemaTableExists()
95107
{
108+
if (file_exists(self::$dbFile)) {
109+
@unlink(self::$dbFile);
110+
}
111+
96112
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $this->getDbalConfig());
97113
$schema = new Schema();
98114
$schema->createTable('cache_items');

0 commit comments

Comments
 (0)
0