Skip to content

Commit a01d22e

Browse files
committed
fix tests
1 parent c537636 commit a01d22e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/chat/src/Bridge/Doctrine/DoctrineDbalMessageStore.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function setup(array $options = []): void
5454
}
5555

5656
$schemaManager = $this->dbalConnection->createSchemaManager();
57+
$currentSchema = $schemaManager->introspectSchema();
58+
59+
if ($currentSchema->hasTable($this->tableName)) {
60+
return;
61+
}
5762

5863
if (class_exists(ComparatorConfig::class)) {
5964
$comparator = $schemaManager->createComparator(new ComparatorConfig(false, false));
@@ -62,7 +67,6 @@ public function setup(array $options = []): void
6267
$comparator = $schemaManager->createComparator();
6368
}
6469

65-
$currentSchema = $schemaManager->introspectSchema();
6670
$migrations = $this->dbalConnection->getDatabasePlatform()->getAlterSchemaSQL($comparator->compareSchemas($currentSchema, $this->defineTableSchema($currentSchema)));
6771

6872
foreach ($migrations as $sql) {
@@ -126,10 +130,6 @@ private function defineTableSchema(Schema $currentSchema): Schema
126130
{
127131
$schema = clone $currentSchema;
128132

129-
if ($schema->hasTable($this->tableName)) {
130-
$schema->dropTable($this->tableName);
131-
}
132-
133133
$table = $schema->createTable($this->tableName);
134134
$table->addOption('_symfony_ai_chat_table_name', $this->tableName);
135135
$idColumn = $table->addColumn('id', Types::BIGINT)

src/chat/tests/Bridge/Doctrine/DoctrineDbalMessageStoreTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
use Doctrine\DBAL\Result;
1818
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1919
use Doctrine\DBAL\Schema\Column;
20+
use Doctrine\DBAL\Schema\Comparator;
2021
use Doctrine\DBAL\Schema\Schema;
22+
use Doctrine\DBAL\Schema\SchemaDiff;
2123
use Doctrine\DBAL\Schema\Table;
2224
use PHPUnit\Framework\TestCase;
2325
use Symfony\AI\Chat\Bridge\Doctrine\DoctrineDbalMessageStore;
@@ -76,15 +78,23 @@ public function testMessageStoreTableCanBeSetup()
7678
$schema = $this->createMock(Schema::class);
7779
$schema->expects($this->once())->method('hasTable')->willReturn(false);
7880
$schema->expects($this->once())->method('createTable')->with('foo')->willReturn($table);
79-
$schema->expects($this->once())->method('toSql')->with($platform)->willReturn([]);
8081

8182
$sqliteSchemaManager = $this->createMock(AbstractSchemaManager::class);
8283
$sqliteSchemaManager->expects($this->once())->method('introspectSchema')->willReturn($schema);
8384

85+
$comparator = $this->createMock(Comparator::class);
86+
$sqliteSchemaManager->expects($this->once())->method('createComparator')->willReturn($comparator);
87+
8488
$connection = $this->createMock(Connection::class);
8589
$connection->expects($this->once())->method('createSchemaManager')->willReturn($sqliteSchemaManager);
8690
$connection->expects($this->exactly(2))->method('getDatabasePlatform')->willReturn($platform);
8791

92+
$schemaDiff = $this->createMock(SchemaDiff::class);
93+
94+
$comparator->expects($this->once())->method('compareSchemas')->willReturn($schemaDiff);
95+
$platform->expects($this->once())->method('getAlterSchemaSQL')->willReturn(['SQL STATEMENT']);
96+
$connection->expects($this->once())->method('executeQuery')->with('SQL STATEMENT');
97+
8898
$messageStore = new DoctrineDbalMessageStore('foo', $connection);
8999
$messageStore->setup();
90100
}

0 commit comments

Comments
 (0)