Skip to content

[DoctrineBridge] Add integration test for RememberMe with postgres connection #58528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Symfony\Bridge\Doctrine\Tests\Security\RememberMe;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\ORM\ORMSetup;
use Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider;

/**
* @requires extension pdo_pgsql
* @group integration
*/
class DoctrineTokenProviderPostgresTest extends DoctrineTokenProviderTest
{
public static function setUpBeforeClass(): void
{
if (!getenv('POSTGRES_HOST')) {
self::markTestSkipped('Missing POSTGRES_HOST env variable');
}
}

protected function bootstrapProvider()
{
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$connection = DriverManager::getConnection([
'driver' => 'pdo_pgsql',
'host' => getenv('POSTGRES_HOST'),
'user' => 'postgres',
'password' => 'password',
], $config);
$connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<<'SQL'
DROP TABLE IF EXISTS rememberme_token;
SQL
);

$connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<<'SQL'
CREATE TABLE rememberme_token (
series CHAR(88) UNIQUE PRIMARY KEY NOT NULL,
value VARCHAR(88) NOT NULL, -- CHAR(88) adds spaces at the end
lastUsed TIMESTAMP NOT NULL,
class VARCHAR(100) NOT NULL,
username VARCHAR(200) NOT NULL
);
SQL
);

return new DoctrineTokenProvider($connection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Security\RememberMe;
namespace Symfony\Bridge\Doctrine\Tests\Security\RememberMe;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
Expand Down Expand Up @@ -121,7 +121,7 @@ public function testVerifyOutdatedTokenAfterParallelRequestFailsAfter60Seconds()
/**
* @return DoctrineTokenProvider
*/
private function bootstrapProvider()
protected function bootstrapProvider()
{
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
Expand Down
Loading