|
11 | 11 |
|
12 | 12 | namespace Symfony\AI\AiBundle\Tests\DependencyInjection; |
13 | 13 |
|
| 14 | +use MongoDB\Client as MongoDbClient; |
14 | 15 | use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; |
15 | 16 | use PHPUnit\Framework\Attributes\TestDox; |
16 | 17 | use PHPUnit\Framework\Attributes\TestWith; |
@@ -3087,6 +3088,69 @@ public function testMemoryMessageStoreCanBeConfiguredWithCustomKey() |
3087 | 3088 | $this->assertTrue($memoryMessageStoreDefinition->hasTag('ai.message_store')); |
3088 | 3089 | } |
3089 | 3090 |
|
| 3091 | + public function testMongoDbMessageStoreIsConfigured() |
| 3092 | + { |
| 3093 | + $container = $this->buildContainer([ |
| 3094 | + 'ai' => [ |
| 3095 | + 'message_store' => [ |
| 3096 | + 'mongodb' => [ |
| 3097 | + 'custom' => [ |
| 3098 | + 'collection' => 'foo', |
| 3099 | + 'database' => 'bar', |
| 3100 | + ], |
| 3101 | + ], |
| 3102 | + ], |
| 3103 | + ], |
| 3104 | + ]); |
| 3105 | + |
| 3106 | + $mongoDbMessageStoreDefinition = $container->getDefinition('ai.message_store.mongodb.custom'); |
| 3107 | + |
| 3108 | + $this->assertTrue($mongoDbMessageStoreDefinition->isLazy()); |
| 3109 | + $this->assertCount(4, $mongoDbMessageStoreDefinition->getArguments()); |
| 3110 | + $this->assertInstanceOf(Reference::class, $mongoDbMessageStoreDefinition->getArgument(0)); |
| 3111 | + $this->assertSame(MongoDbClient::class, (string) $mongoDbMessageStoreDefinition->getArgument(0)); |
| 3112 | + $this->assertSame('bar', $mongoDbMessageStoreDefinition->getArgument(1)); |
| 3113 | + $this->assertSame('foo', $mongoDbMessageStoreDefinition->getArgument(2)); |
| 3114 | + $this->assertInstanceOf(Reference::class, $mongoDbMessageStoreDefinition->getArgument(3)); |
| 3115 | + $this->assertSame('serializer', (string) $mongoDbMessageStoreDefinition->getArgument(3)); |
| 3116 | + |
| 3117 | + $this->assertTrue($mongoDbMessageStoreDefinition->hasTag('proxy')); |
| 3118 | + $this->assertSame([['interface' => MessageStoreInterface::class]], $mongoDbMessageStoreDefinition->getTag('proxy')); |
| 3119 | + $this->assertTrue($mongoDbMessageStoreDefinition->hasTag('ai.message_store')); |
| 3120 | + } |
| 3121 | + |
| 3122 | + public function testMongoDbMessageStoreIsConfiguredWithCustomClient() |
| 3123 | + { |
| 3124 | + $container = $this->buildContainer([ |
| 3125 | + 'ai' => [ |
| 3126 | + 'message_store' => [ |
| 3127 | + 'mongodb' => [ |
| 3128 | + 'custom' => [ |
| 3129 | + 'client' => 'custom', |
| 3130 | + 'collection' => 'foo', |
| 3131 | + 'database' => 'bar', |
| 3132 | + ], |
| 3133 | + ], |
| 3134 | + ], |
| 3135 | + ], |
| 3136 | + ]); |
| 3137 | + |
| 3138 | + $mongoDbMessageStoreDefinition = $container->getDefinition('ai.message_store.mongodb.custom'); |
| 3139 | + |
| 3140 | + $this->assertTrue($mongoDbMessageStoreDefinition->isLazy()); |
| 3141 | + $this->assertCount(4, $mongoDbMessageStoreDefinition->getArguments()); |
| 3142 | + $this->assertInstanceOf(Reference::class, $mongoDbMessageStoreDefinition->getArgument(0)); |
| 3143 | + $this->assertSame('custom', (string) $mongoDbMessageStoreDefinition->getArgument(0)); |
| 3144 | + $this->assertSame('bar', $mongoDbMessageStoreDefinition->getArgument(1)); |
| 3145 | + $this->assertSame('foo', $mongoDbMessageStoreDefinition->getArgument(2)); |
| 3146 | + $this->assertInstanceOf(Reference::class, $mongoDbMessageStoreDefinition->getArgument(3)); |
| 3147 | + $this->assertSame('serializer', (string) $mongoDbMessageStoreDefinition->getArgument(3)); |
| 3148 | + |
| 3149 | + $this->assertTrue($mongoDbMessageStoreDefinition->hasTag('proxy')); |
| 3150 | + $this->assertSame([['interface' => MessageStoreInterface::class]], $mongoDbMessageStoreDefinition->getTag('proxy')); |
| 3151 | + $this->assertTrue($mongoDbMessageStoreDefinition->hasTag('ai.message_store')); |
| 3152 | + } |
| 3153 | + |
3090 | 3154 | public function testPogocacheMessageStoreIsConfigured() |
3091 | 3155 | { |
3092 | 3156 | $container = $this->buildContainer([ |
@@ -3812,6 +3876,17 @@ private function getFullConfig(): array |
3812 | 3876 | 'index_name' => 'test', |
3813 | 3877 | ], |
3814 | 3878 | ], |
| 3879 | + 'mongodb' => [ |
| 3880 | + 'my_mongo_db_message_store' => [ |
| 3881 | + 'collection' => 'foo', |
| 3882 | + 'database' => 'bar', |
| 3883 | + ], |
| 3884 | + 'my_mongo_db_message_store_with_custom_client' => [ |
| 3885 | + 'client' => 'custom', |
| 3886 | + 'collection' => 'foo', |
| 3887 | + 'database' => 'bar', |
| 3888 | + ], |
| 3889 | + ], |
3815 | 3890 | 'pogocache' => [ |
3816 | 3891 | 'my_pogocache_message_store' => [ |
3817 | 3892 | 'endpoint' => 'http://127.0.0.1:9401', |
|
0 commit comments