66
77use Meilisearch \Bundle \Tests \BaseKernelTestCase ;
88use Meilisearch \Bundle \Tests \Entity \DummyCustomGroups ;
9+ use Meilisearch \Bundle \Tests \Entity \DynamicSettings ;
910use Meilisearch \Bundle \Tests \Entity \SelfNormalizable ;
1011use Meilisearch \Client ;
1112use Meilisearch \Endpoints \Indexes ;
@@ -77,9 +78,9 @@ public function testSearchImportAndClearAndDeleteWithoutIndices(): void
7778Importing for index Meilisearch\Bundle\Tests\Entity\Post
7879Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
7980Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
80- Settings updated.
81- Settings updated.
82- Settings updated.
81+ Settings updated of "sf_phpunit__posts" .
82+ Settings updated of "sf_phpunit__posts" .
83+ Settings updated of "sf_phpunit__posts" .
8384Importing for index Meilisearch\Bundle\Tests\Entity\Comment
8485Importing for index Meilisearch\Bundle\Tests\Entity\Tag
8586Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Tag entities into sf_phpunit__tags index (6 indexed since start)
@@ -89,6 +90,11 @@ public function testSearchImportAndClearAndDeleteWithoutIndices(): void
8990Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Page entities into sf_phpunit__pages index (6 indexed since start)
9091Importing for index Meilisearch\Bundle\Tests\Entity\SelfNormalizable
9192Importing for index Meilisearch\Bundle\Tests\Entity\DummyCustomGroups
93+ Importing for index Meilisearch\Bundle\Tests\Entity\DynamicSettings
94+ Settings updated of "sf_phpunit__dynamic_settings".
95+ Settings updated of "sf_phpunit__dynamic_settings".
96+ Settings updated of "sf_phpunit__dynamic_settings".
97+ Settings updated of "sf_phpunit__dynamic_settings".
9298Importing for index Meilisearch\Bundle\Tests\Entity\Post
9399Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
94100Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
@@ -114,6 +120,7 @@ public function testSearchImportAndClearAndDeleteWithoutIndices(): void
114120Cleared sf_phpunit__pages index of Meilisearch\Bundle\Tests\Entity\Page
115121Cleared sf_phpunit__self_normalizable index of Meilisearch\Bundle\Tests\Entity\SelfNormalizable
116122Cleared sf_phpunit__dummy_custom_groups index of Meilisearch\Bundle\Tests\Entity\DummyCustomGroups
123+ Cleared sf_phpunit__dynamic_settings index of Meilisearch\Bundle\Tests\Entity\DynamicSettings
117124Done!
118125
119126EOD, $ clearOutput );
@@ -132,6 +139,7 @@ public function testSearchImportAndClearAndDeleteWithoutIndices(): void
132139Deleted sf_phpunit__pages
133140Deleted sf_phpunit__self_normalizable
134141Deleted sf_phpunit__dummy_custom_groups
142+ Deleted sf_phpunit__dynamic_settings
135143Done!
136144
137145EOD, $ clearOutput );
@@ -325,12 +333,20 @@ public function testSearchCreateWithoutIndices(): void
325333
326334 $ this ->assertSame (<<<'EOD'
327335Creating index sf_phpunit__posts for Meilisearch\Bundle\Tests\Entity\Post
336+ Settings updated of "sf_phpunit__posts".
337+ Settings updated of "sf_phpunit__posts".
338+ Settings updated of "sf_phpunit__posts".
328339Creating index sf_phpunit__comments for Meilisearch\Bundle\Tests\Entity\Comment
329340Creating index sf_phpunit__tags for Meilisearch\Bundle\Tests\Entity\Tag
330341Creating index sf_phpunit__tags for Meilisearch\Bundle\Tests\Entity\Link
331342Creating index sf_phpunit__pages for Meilisearch\Bundle\Tests\Entity\Page
332343Creating index sf_phpunit__self_normalizable for Meilisearch\Bundle\Tests\Entity\SelfNormalizable
333344Creating index sf_phpunit__dummy_custom_groups for Meilisearch\Bundle\Tests\Entity\DummyCustomGroups
345+ Creating index sf_phpunit__dynamic_settings for Meilisearch\Bundle\Tests\Entity\DynamicSettings
346+ Settings updated of "sf_phpunit__dynamic_settings".
347+ Settings updated of "sf_phpunit__dynamic_settings".
348+ Settings updated of "sf_phpunit__dynamic_settings".
349+ Settings updated of "sf_phpunit__dynamic_settings".
334350Creating index sf_phpunit__aggregated for Meilisearch\Bundle\Tests\Entity\Post
335351Creating index sf_phpunit__aggregated for Meilisearch\Bundle\Tests\Entity\Tag
336352Done!
@@ -350,6 +366,9 @@ public function testSearchCreateWithIndices(): void
350366
351367 $ this ->assertSame (<<<'EOD'
352368Creating index sf_phpunit__posts for Meilisearch\Bundle\Tests\Entity\Post
369+ Settings updated of "sf_phpunit__posts".
370+ Settings updated of "sf_phpunit__posts".
371+ Settings updated of "sf_phpunit__posts".
353372Done!
354373
355374EOD, $ createOutput );
@@ -437,4 +456,55 @@ public function testImportsDummyWithCustomGroups(): void
437456 ],
438457 ], $ this ->client ->index ('sf_phpunit__dummy_custom_groups ' )->getDocuments ()->getResults ());
439458 }
459+
460+ /**
461+ * @testWith ["meili:create"]
462+ * ["meili:import"]
463+ */
464+ public function testImportWithDynamicSettings (string $ command ): void
465+ {
466+ for ($ i = 0 ; $ i <= 5 ; ++$ i ) {
467+ $ this ->entityManager ->persist (new DynamicSettings ($ i , "Dynamic $ i " ));
468+ }
469+
470+ $ this ->entityManager ->flush ();
471+
472+ $ importCommand = $ this ->application ->find ($ command );
473+ $ importCommandTester = new CommandTester ($ importCommand );
474+ $ importCommandTester ->execute (['--indices ' => 'dynamic_settings ' ]);
475+
476+ $ importOutput = $ importCommandTester ->getDisplay ();
477+
478+ if ('meili:import ' === $ command ) {
479+ $ this ->assertSame (<<<'EOD'
480+ Importing for index Meilisearch\Bundle\Tests\Entity\DynamicSettings
481+ Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\DynamicSettings entities into sf_phpunit__dynamic_settings index (6 indexed since start)
482+ Settings updated of "sf_phpunit__dynamic_settings".
483+ Settings updated of "sf_phpunit__dynamic_settings".
484+ Settings updated of "sf_phpunit__dynamic_settings".
485+ Settings updated of "sf_phpunit__dynamic_settings".
486+ Done!
487+
488+ EOD, $ importOutput );
489+ } else {
490+ $ this ->assertSame (<<<'EOD'
491+ Creating index sf_phpunit__dynamic_settings for Meilisearch\Bundle\Tests\Entity\DynamicSettings
492+ Settings updated of "sf_phpunit__dynamic_settings".
493+ Settings updated of "sf_phpunit__dynamic_settings".
494+ Settings updated of "sf_phpunit__dynamic_settings".
495+ Settings updated of "sf_phpunit__dynamic_settings".
496+ Done!
497+
498+ EOD, $ importOutput );
499+ }
500+
501+ $ settings = $ this ->get ('search.client ' )->index ('sf_phpunit__dynamic_settings ' )->getSettings ();
502+
503+ $ getSetting = static fn ($ value ) => $ value instanceof \IteratorAggregate ? iterator_to_array ($ value ) : $ value ;
504+
505+ self ::assertSame (['publishedAt ' , 'title ' ], $ getSetting ($ settings ['filterableAttributes ' ]));
506+ self ::assertSame (['title ' ], $ getSetting ($ settings ['searchableAttributes ' ]));
507+ self ::assertSame (['a ' , 'n ' , 'the ' ], $ getSetting ($ settings ['stopWords ' ]));
508+ self ::assertSame (['fantastic ' => ['great ' ], 'great ' => ['fantastic ' ]], $ getSetting ($ settings ['synonyms ' ]));
509+ }
440510}
0 commit comments