|
| 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 SchemaListener; |
| 13 | + |
| 14 | +use Doctrine\DBAL\Connection; |
| 15 | +use Doctrine\DBAL\DriverManager; |
| 16 | +use PHPUnit\Framework\Attributes\RequiresPhpExtension; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use Symfony\Bridge\Doctrine\SchemaListener\AbstractSchemaListener; |
| 19 | + |
| 20 | +#[RequiresPhpExtension('pdo_sqlite')] |
| 21 | +class AbstractSchemaListenerTest extends TestCase |
| 22 | +{ |
| 23 | + public function testSameDatabaseChecker(): void |
| 24 | + { |
| 25 | + $connectionParams = [ |
| 26 | + 'dbname' => ':memory:', |
| 27 | + 'driver' => 'pdo_sqlite', |
| 28 | + ]; |
| 29 | + // Create two distinct in-memory SQLite databases |
| 30 | + $connection1 = DriverManager::getConnection($connectionParams); |
| 31 | + $connection2 = DriverManager::getConnection($connectionParams); |
| 32 | + |
| 33 | + self::assertTrue($this->getIsSameDatabaseChecker($connection1)($connection1->executeStatement(...))); |
| 34 | + self::assertFalse($this->getIsSameDatabaseChecker($connection1)($connection2->executeStatement(...))); |
| 35 | + } |
| 36 | + |
| 37 | + public function getIsSameDatabaseChecker(Connection $connection): \Closure |
| 38 | + { |
| 39 | + return (new class extends AbstractSchemaListener { |
| 40 | + public function postGenerateSchema($event): void |
| 41 | + { |
| 42 | + } |
| 43 | + |
| 44 | + public function getIsSameDatabaseChecker(Connection $connection): \Closure |
| 45 | + { |
| 46 | + return parent::getIsSameDatabaseChecker($connection); |
| 47 | + } |
| 48 | + })->getIsSameDatabaseChecker($connection); |
| 49 | + } |
| 50 | +} |
0 commit comments