|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport; |
| 13 | + |
| 14 | +use Doctrine\DBAL\Connection; |
| 15 | +use Doctrine\DBAL\DriverManager; |
| 16 | +use Doctrine\DBAL\Schema\AbstractSchemaManager; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage; |
| 19 | +use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection; |
| 20 | + |
| 21 | +/** |
| 22 | + * @requires extension pdo_pgsql |
| 23 | + * @group integration |
| 24 | + */ |
| 25 | +class DoctrinePostgreSqlIntegrationTest extends TestCase |
| 26 | +{ |
| 27 | + /** @var Connection */ |
| 28 | + private $driverConnection; |
| 29 | + /** @var PostgreSqlConnection */ |
| 30 | + private $connection; |
| 31 | + |
| 32 | + protected function setUp(): void |
| 33 | + { |
| 34 | + if (!$host = getenv('POSTGRES_HOST')) { |
| 35 | + $this->markTestSkipped('Missing POSTGRES_HOST env variable'); |
| 36 | + } |
| 37 | + |
| 38 | + $this->driverConnection = DriverManager::getConnection(['url' => "pgsql://postgres:password@$host"]); |
| 39 | + $this->connection = new PostgreSqlConnection(['table_name' => 'queue_table'], $this->driverConnection); |
| 40 | + $this->connection->setup(); |
| 41 | + } |
| 42 | + |
| 43 | + protected function tearDown(): void |
| 44 | + { |
| 45 | + $this->createSchemaManager()->dropTable('queue_table'); |
| 46 | + $this->driverConnection->close(); |
| 47 | + } |
| 48 | + |
| 49 | + public function testPostgreSqlConnectionSendAndGet() |
| 50 | + { |
| 51 | + $this->connection->send('{"message": "Hi"}', ['type' => DummyMessage::class]); |
| 52 | + |
| 53 | + $encoded = $this->connection->get(); |
| 54 | + $this->assertEquals('{"message": "Hi"}', $encoded['body']); |
| 55 | + $this->assertEquals(['type' => DummyMessage::class], $encoded['headers']); |
| 56 | + |
| 57 | + $this->assertNull($this->connection->get()); |
| 58 | + } |
| 59 | + |
| 60 | + private function createSchemaManager(): AbstractSchemaManager |
| 61 | + { |
| 62 | + return method_exists($this->driverConnection, 'createSchemaManager') |
| 63 | + ? $this->driverConnection->createSchemaManager() |
| 64 | + : $this->driverConnection->getSchemaManager(); |
| 65 | + } |
| 66 | +} |
0 commit comments