Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [TwigBridge] foundation 5 layout: use form_label_content block for checkbox and radio labels
  [TwigBridge] Fix compat with Twig v3.9
  [Cache] Sync the Redis proxies with upstream
  [Doctrine Messenger] Fix support for pgsql + pgbouncer.
  [Mailer] Simplify fix
  Do not produce notice/warning when consuming from multiple transports and explicitly listed queues
  [FrameworkBundle] Check if the _route attribute exists on the request
  [Scheduler] fix documentation link
  [PropertyAccess] Fixes getValue() on an unitialized object property on a lazy ghost
  [HttpClient] Make retry strategy work again
  AssetMapper: Remove 'auto-generated' info
  [Mailer] Fix signed emails breaking the profiler
  [Mailer] [Mailgun] Fix expecting payload without tags or user variables
  [Validator] Update Spanish (es) translations
  Fix fetching data in `W3CReferenceTest` on AppVeyor
  Fix SQS visibility_timeout type
  [VarDumper] Fix serialization of stubs with null or uninitialized values
  • Loading branch information
nicolas-grekas committed Feb 15, 2024
2 parents 2e31535 + b6c31c4 commit 60b38fc
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 13 deletions.
13 changes: 13 additions & 0 deletions Tests/Fixtures/pgbouncer/pgbouncer.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[databases]
postgres = host=localhost port=5432 user=postgres dbname=postgres pool_mode=transaction

[pgbouncer]
logfile = /var/log/postgresql/pgbouncer.log
pidfile = /var/run/postgresql/pgbouncer.pid
listen_addr = localhost
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
max_client_conn = 20
default_pool_size = 20
1 change: 1 addition & 0 deletions Tests/Fixtures/pgbouncer/userlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"postgres" "md532e12f215ba27cb750c9e093ce4b5127"
98 changes: 98 additions & 0 deletions Tests/Transport/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,104 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
$connection->reject('dummy_id');
}

public function testSend()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();

$driverConnection->expects($this->once())
->method('createQueryBuilder')
->willReturn($queryBuilder);

$queryBuilder->expects($this->once())
->method('insert')
->willReturn($queryBuilder);

$queryBuilder->expects($this->once())
->method('values')
->with([
'body' => '?',
'headers' => '?',
'queue_name' => '?',
'created_at' => '?',
'available_at' => '?',
])
->willReturn($queryBuilder);

$queryBuilder->expects($this->once())
->method('getSQL')
->willReturn('INSERT');

$driverConnection->expects($this->once())
->method('beginTransaction');

$driverConnection->expects($this->once())
->method('executeStatement')
->with('INSERT')
->willReturn(1);

$driverConnection->expects($this->once())
->method('lastInsertId')
->willReturn('1');

$driverConnection->expects($this->once())
->method('commit');

$connection = new Connection([], $driverConnection);
$id = $connection->send('test', []);

self::assertSame('1', $id);
}

public function testSendLastInsertIdReturnsInteger()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();

$driverConnection->expects($this->once())
->method('createQueryBuilder')
->willReturn($queryBuilder);

$queryBuilder->expects($this->once())
->method('insert')
->willReturn($queryBuilder);

$queryBuilder->expects($this->once())
->method('values')
->with([
'body' => '?',
'headers' => '?',
'queue_name' => '?',
'created_at' => '?',
'available_at' => '?',
])
->willReturn($queryBuilder);

$queryBuilder->expects($this->once())
->method('getSQL')
->willReturn('INSERT');

$driverConnection->expects($this->once())
->method('beginTransaction');

$driverConnection->expects($this->once())
->method('executeStatement')
->with('INSERT')
->willReturn(1);

$driverConnection->expects($this->once())
->method('lastInsertId')
->willReturn(1);

$driverConnection->expects($this->once())
->method('commit');

$connection = new Connection([], $driverConnection);
$id = $connection->send('test', []);

self::assertSame('1', $id);
}

private function getDBALConnectionMock()
{
$driverConnection = $this->createMock(DBALConnection::class);
Expand Down
89 changes: 89 additions & 0 deletions Tests/Transport/DoctrinePostgreSqlPgbouncerIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Tools\DsnParser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection;

/**
* This tests using PostgreSqlConnection with PgBouncer between pgsql and the application.
*
* @requires extension pdo_pgsql
*
* @group integration
*/
class DoctrinePostgreSqlPgbouncerIntegrationTest extends TestCase
{
private Connection $driverConnection;
private PostgreSqlConnection $connection;

public function testSendAndGetWithAutoSetupEnabledAndNotSetupAlready()
{
$this->connection->send('{"message": "Hi"}', ['type' => DummyMessage::class]);

$encoded = $this->connection->get();
$this->assertSame('{"message": "Hi"}', $encoded['body']);
$this->assertSame(['type' => DummyMessage::class], $encoded['headers']);

$this->assertNull($this->connection->get());
}

public function testSendAndGetWithAutoSetupEnabledAndSetupAlready()
{
$this->connection->setup();

$this->connection->send('{"message": "Hi"}', ['type' => DummyMessage::class]);

$encoded = $this->connection->get();
$this->assertSame('{"message": "Hi"}', $encoded['body']);
$this->assertSame(['type' => DummyMessage::class], $encoded['headers']);

$this->assertNull($this->connection->get());
}

protected function setUp(): void
{
if (!$host = getenv('PGBOUNCER_HOST')) {
$this->markTestSkipped('Missing PGBOUNCER_HOST env variable');
}

$url = "pdo-pgsql://postgres:password@$host";
$params = class_exists(DsnParser::class) ? (new DsnParser())->parse($url) : ['url' => $url];
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$this->driverConnection = DriverManager::getConnection($params, $config);
$this->connection = new PostgreSqlConnection(['table_name' => 'queue_table'], $this->driverConnection);
}

protected function tearDown(): void
{
$this->createSchemaManager()->dropTable('queue_table');
$this->driverConnection->close();
}

private function createSchemaManager(): AbstractSchemaManager
{
return method_exists($this->driverConnection, 'createSchemaManager')
? $this->driverConnection->createSchemaManager()
: $this->driverConnection->getSchemaManager();
}
}
89 changes: 89 additions & 0 deletions Tests/Transport/DoctrinePostgreSqlRegularIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Tools\DsnParser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;

/**
* This tests a using Doctrine PostgreSql connection without using PostgreSqlConnection
* that gets used when use_notify is enabled.
*
* @requires extension pdo_pgsql
*
* @group integration
*/
class DoctrinePostgreSqlRegularIntegrationTest extends TestCase
{
private \Doctrine\DBAL\Connection $driverConnection;
private Connection $connection;

public function testSendAndGetWithAutoSetupEnabledAndNotSetupAlready()
{
$this->connection->send('{"message": "Hi"}', ['type' => DummyMessage::class]);

$encoded = $this->connection->get();
$this->assertSame('{"message": "Hi"}', $encoded['body']);
$this->assertSame(['type' => DummyMessage::class], $encoded['headers']);

$this->assertNull($this->connection->get());
}

public function testSendAndGetWithAutoSetupEnabledAndSetupAlready()
{
$this->connection->setup();

$this->connection->send('{"message": "Hi"}', ['type' => DummyMessage::class]);

$encoded = $this->connection->get();
$this->assertSame('{"message": "Hi"}', $encoded['body']);
$this->assertSame(['type' => DummyMessage::class], $encoded['headers']);

$this->assertNull($this->connection->get());
}

protected function setUp(): void
{
if (!$host = getenv('POSTGRES_HOST')) {
$this->markTestSkipped('Missing POSTGRES_HOST env variable');
}

$url = "pdo-pgsql://postgres:password@$host";
$params = class_exists(DsnParser::class) ? (new DsnParser())->parse($url) : ['url' => $url];
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$this->driverConnection = DriverManager::getConnection($params, $config);
$this->connection = new Connection(['table_name' => 'queue_table'], $this->driverConnection);
}

protected function tearDown(): void
{
$this->createSchemaManager()->dropTable('queue_table');
$this->driverConnection->close();
}

private function createSchemaManager(): AbstractSchemaManager
{
return method_exists($this->driverConnection, 'createSchemaManager')
? $this->driverConnection->createSchemaManager()
: $this->driverConnection->getSchemaManager();
}
}
Loading

0 comments on commit 60b38fc

Please sign in to comment.