8000 Merge branch '7.1' into 7.2 · symfony/symfony@789055e · GitHub
[go: up one dir, main page]

Skip to content

Commit 789055e

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: fix CS Update deprecations baseline [Mailer][MailJet] Fix parameters for TrackClicks and TrackOpens [Doctrine][Messenger] Oracle sequences are suffixed with `_seq` drop existing schema if tests create it explicitly synchronize line numbers in deprecations baseline [HttpClient] Fix class requirement message Add integration test for RememberMe with pg connection fix: DoctrineTokenProvider not oracle compatible
2 parents fed083a + f549ad4 commit 789055e

File tree

9 files changed

+106
-15
lines changed

9 files changed

+106
-15
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ public function __construct(
4848

4949
public function loadTokenBySeries(string $series): PersistentTokenInterface
5050
{
51-
// the alias for lastUsed works around case insensitivity in PostgreSQL
52-
$sql = 'SELECT class, username, value, lastUsed AS last_used FROM rememberme_token WHERE series=:series';
51+
$sql = 'SELECT class, username, value, lastUsed FROM rememberme_token WHERE series=:series';
5352
$paramValues = ['series' => $series];
5453
$paramTypes = ['series' => ParameterType::STRING];
5554
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
56-
$row = $stmt->fetchAssociative() ?: throw new TokenNotFoundException('No token found.');
5755

58-
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTimeImmutable($row['last_used']));
56+
// fetching numeric because column name casing depends on platform, eg. Oracle converts all not quoted names to uppercase
57+
$row = $stmt->fetchNumeric() ?: throw new TokenNotFoundException('No token found.');
58+
59+
[$class, $username, $value, $last_used] = $row;
60+
return new PersistentToken($class, $username, $series, $value, new \DateTimeImmutable($last_used));
5961
}
6062

6163
public function deleteTokenBySeries(string $series): void
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: 1 addition & 1 deletion
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;

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

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

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

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

@@ -84,6 +92,10 @@ public function testConfigureSchema()
8492

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

@@ -94,6 +106,10 @@ public function testConfigureSchemaDifferentDbalConnection()
94106

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

src/Symfony/Component/HttpClient/CachingHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
array $defaultOptions = [],
4545
) {
4646
if (!class_exists(HttpClientKernel::class)) {
47-
throw new \LogicException(\sprintf('Using "%s" requires that the HttpKernel component version 4.3 or higher is installed, try running "composer require symfony/http-kernel:^5.4".', __CLASS__));
47+
throw new \LogicException(\sprintf('Using "%s" requires the HttpKernel component, try running "composer require symfony/http-kernel".', __CLASS__));
4848
}
4949

5050
$kernel = new HttpClientKernel($client);

src/Symfony/Component/Mailer/Bridge/Mailjet/Tests/Transport/MailjetApiTransportTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ public function testHeaderToMessage()
369369
'CustomCampaign' => 'SendAPI_campaign',
370370
'DeduplicateCampaign' => true,
371371
'Priority' => 2,
372-
'TrackClick' => 'account_default',
373-
'TrackOpen' => 'account_default',
372+
'TrackClicks' => 'account_default',
373+
'TrackOpens' => 'account_default',
374374
],
375375
],
376376
'SandBoxMode' => false,
@@ -421,8 +421,8 @@ public function testHeaderToMessage()
421421
'CustomCampaign' => 'SendAPI_campaign',
422422
'DeduplicateCampaign' => true,
423423
'Priority' => 2,
424-
'TrackClick' => 'account_default',
425-
'TrackOpen' => 'account_default',
424+
'TrackClicks' => 'account_default',
425+
'TrackOpens' => 'account_default',
426426
],
427427
],
428428
'SandBoxMode' => true,

src/Symfony/Component/Mailer/Bridge/Mailjet/Transport/MailjetApiTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class MailjetApiTransport extends AbstractApiTransport
4747
'X-Mailjet-Campaign' => ['CustomCampaign', 'string'],
4848
'X-Mailjet-DeduplicateCampaign' => ['DeduplicateCampaign', 'bool'],
4949
'X-Mailjet-Prio' => ['Priority', 'int'],
50-
'X-Mailjet-TrackClick' => ['TrackClick', 'string'],
51-
'X-Mailjet-TrackOpen' => ['TrackOpen', 'string'],
50+
'X-Mailjet-TrackClick' => ['TrackClicks', 'string'],
51+
'X-Mailjet-TrackOpen' => ['TrackOpens', 'string'],
5252
];
5353

5454
public function __construct(

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,4 +752,21 @@ class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::c
752752
];
753753
}
754754
}
755+
756+
public function testConfigureSchemaOracleSequenceNameSuffixed()
757+
{
758+
$driverConnection = $this->createMock(DBALConnection::class);
759+
$driverConnection->method('getDatabasePlatform')->willReturn(new OraclePlatform());
760+
$schema = new Schema();
761+
762+
$connection = new Connection(['table_name' => 'messenger_messages'], $driverConnection);
763+
$connection->configureSchema($schema, $driverConnection, fn () => true);
764+
765+
$expectedSuffix = '_seq';
766+
$sequences = $schema->getSequences();
767+
$this->assertCount(1, $sequences);
768+
$sequence = array_pop($sequences);
769+
$sequenceNameSuffix = substr($sequence->getName(), -strlen($expectedSuffix));
770+
$this->assertSame($expectedSuffix, $sequenceNameSuffix);
771+
}
755772
}

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
class Connection implements ResetInterface
4242
{
43+
private const ORACLE_SEQUENCES_SUFFIX = '_seq';
4344
protected const TABLE_OPTION_NAME = '_symfony_messenger_table_name';
4445

4546
protected const DEFAULT_OPTIONS = [
@@ -454,7 +455,7 @@ private function executeInsert(string $sql, array $parameters = [], array $types
454455
throw new TransportException('no id was returned by PostgreSQL from RETURNING clause.');
455456
}
456457
} elseif ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
457-
$sequenceName = 'seq_'.$this->configuration['table_name'];
458+
$sequenceName = $this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX;
458459

459460
$this->driverConnection->executeStatement($sql, $parameters, $types);
460461

@@ -525,9 +526,9 @@ private function addTableToSchema(Schema $schema): void
525526

526527
// We need to create a sequence for Oracle and set the id column to get the correct nextval
527528
if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
528-
$idColumn->setDefault('seq_'.$this->configuration['table_name'].'.nextval');
529+
$idColumn->setDefault($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX.'.nextval');
529530

530-
$schema->createSequence('seq_'.$this->configuration['table_name']);
531+
$schema->createSequence($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX);
531532
}
532533
}
533534

< 32C6 /td>

0 commit comments

Comments
 (0)
0