-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathMeilisearchCreateCommandTest.php
150 lines (122 loc) · 6.33 KB
/
MeilisearchCreateCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
declare(strict_types=1);
namespace Meilisearch\Bundle\Tests\Integration\Command;
use Meilisearch\Bundle\Tests\BaseKernelTestCase;
use Meilisearch\Bundle\Tests\Entity\DynamicSettings;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
final class MeilisearchCreateCommandTest extends BaseKernelTestCase
{
protected Application $application;
protected function setUp(): void
{
parent::setUp();
$this->application = new Application(self::createKernel());
}
public function testExecuteIndexCreation(): void
{
$createCommand = $this->application->find('meilisearch:create');
$createCommandTester = new CommandTester($createCommand);
$createCommandTester->execute([]);
$this->assertSame($this->client->getTasks()->getResults()[0]['type'], 'indexCreation');
}
/**
* @testWith [false]
* [true]
*/
public function testWithoutIndices(bool $updateSettings): void
{
$createCommand = $this->application->find('meilisearch:create');
$createCommandTester = new CommandTester($createCommand);
$createCommandTester->execute($updateSettings ? [] : ['--no-update-settings' => true]);
$createOutput = $createCommandTester->getDisplay();
if ($updateSettings) {
$this->assertSame(<<<'EOD'
Creating index sf_phpunit__posts for Meilisearch\Bundle\Tests\Entity\Post
Setting "stopWords" updated of "sf_phpunit__posts".
Setting "filterableAttributes" updated of "sf_phpunit__posts".
Setting "searchCutoffMs" updated of "sf_phpunit__posts".
Setting "typoTolerance" updated of "sf_phpunit__posts".
Creating index sf_phpunit__comments for Meilisearch\Bundle\Tests\Entity\Comment
Creating index sf_phpunit__tags for Meilisearch\Bundle\Tests\Entity\Tag
Creating index sf_phpunit__tags for Meilisearch\Bundle\Tests\Entity\Link
Creating index sf_phpunit__discriminator_map for Meilisearch\Bundle\Tests\Entity\ContentItem
Creating index sf_phpunit__pages for Meilisearch\Bundle\Tests\Entity\Page
Creating index sf_phpunit__self_normalizable for Meilisearch\Bundle\Tests\Entity\SelfNormalizable
Creating index sf_phpunit__dummy_custom_groups for Meilisearch\Bundle\Tests\Entity\DummyCustomGroups
Creating index sf_phpunit__dynamic_settings for Meilisearch\Bundle\Tests\Entity\DynamicSettings
Setting "filterableAttributes" updated of "sf_phpunit__dynamic_settings".
Setting "searchableAttributes" updated of "sf_phpunit__dynamic_settings".
Setting "stopWords" updated of "sf_phpunit__dynamic_settings".
Setting "synonyms" updated of "sf_phpunit__dynamic_settings".
Creating index sf_phpunit__tickets for Meilisearch\Bundle\Tests\Entity\Ticket
Creating index sf_phpunit__aggregated for Meilisearch\Bundle\Tests\Entity\Post
Creating index sf_phpunit__aggregated for Meilisearch\Bundle\Tests\Entity\Tag
Done!
EOD, $createOutput);
} else {
$this->assertSame(<<<'EOD'
Creating index sf_phpunit__posts for Meilisearch\Bundle\Tests\Entity\Post
Creating index sf_phpunit__comments for Meilisearch\Bundle\Tests\Entity\Comment
Creating index sf_phpunit__tags for Meilisearch\Bundle\Tests\Entity\Tag
Creating index sf_phpunit__tags for Meilisearch\Bundle\Tests\Entity\Link
Creating index sf_phpunit__discriminator_map for Meilisearch\Bundle\Tests\Entity\ContentItem
Creating index sf_phpunit__pages for Meilisearch\Bundle\Tests\Entity\Page
Creating index sf_phpunit__self_normalizable for Meilisearch\Bundle\Tests\Entity\SelfNormalizable
Creating index sf_phpunit__dummy_custom_groups for Meilisearch\Bundle\Tests\Entity\DummyCustomGroups
Creating index sf_phpunit__dynamic_settings for Meilisearch\Bundle\Tests\Entity\DynamicSettings
Creating index sf_phpunit__tickets for Meilisearch\Bundle\Tests\Entity\Ticket
Creating index sf_phpunit__aggregated for Meilisearch\Bundle\Tests\Entity\Post
Creating index sf_phpunit__aggregated for Meilisearch\Bundle\Tests\Entity\Tag
Done!
EOD, $createOutput);
}
}
public function testWithIndices(): void
{
$createCommand = $this->application->find('meilisearch:create');
$createCommandTester = new CommandTester($createCommand);
$createCommandTester->execute([
'--indices' => 'posts',
]);
$createOutput = $createCommandTester->getDisplay();
$this->assertSame(<<<'EOD'
Creating index sf_phpunit__posts for Meilisearch\Bundle\Tests\Entity\Post
Setting "stopWords" updated of "sf_phpunit__posts".
Setting "filterableAttributes" updated of "sf_phpunit__posts".
Setting "searchCutoffMs" updated of "sf_phpunit__posts".
Setting "typoTolerance" updated of "sf_phpunit__posts".
Done!
EOD, $createOutput);
}
public function testWithDynamicSettings(): void
{
for ($i = 0; $i <= 5; ++$i) {
$this->entityManager->persist(new DynamicSettings($i, "Dynamic $i"));
}
$this->entityManager->flush();
$importCommand = $this->application->find('meilisearch:create');
$importCommandTester = new CommandTester($importCommand);
$importCommandTester->execute(['--indices' => 'dynamic_settings']);
$importOutput = $importCommandTester->getDisplay();
$this->assertSame(<<<'EOD'
Creating index sf_phpunit__dynamic_settings for Meilisearch\Bundle\Tests\Entity\DynamicSettings
Setting "filterableAttributes" updated of "sf_phpunit__dynamic_settings".
Setting "searchableAttributes" updated of "sf_phpunit__dynamic_settings".
Setting "stopWords" updated of "sf_phpunit__dynamic_settings".
Setting "synonyms" updated of "sf_phpunit__dynamic_settings".
Done!
EOD, $importOutput);
$settings = $this->get('meilisearch.client')->index('sf_phpunit__dynamic_settings')->getSettings();
$getSetting = static fn ($value) => $value instanceof \IteratorAggregate ? iterator_to_array($value) : $value;
self::assertSame(['publishedAt', 'title'], $getSetting($settings['filterableAttributes']));
self::assertSame(['title'], $getSetting($settings['searchableAttributes']));
self::assertSame(['a', 'n', 'the'], $getSetting($settings['stopWords']));
self::assertSame(['fantastic' => ['great'], 'great' => ['fantastic']], $getSetting($settings['synonyms']));
}
public function testAlias(): void
{
$command = $this->application->find('meilisearch:create');
self::assertSame(['meili:create'], $command->getAliases());
}
}