77use Doctrine \ORM \EntityManagerInterface ;
88use Doctrine \ORM \Tools \SchemaTool ;
99use Meilisearch \Bundle \Collection ;
10- use Meilisearch \Bundle \SearchableEntity ;
1110use Meilisearch \Bundle \SearchService ;
12- use Meilisearch \Bundle \Tests \Entity \Article ;
13- use Meilisearch \Bundle \Tests \Entity \Comment ;
14- use Meilisearch \Bundle \Tests \Entity \Image ;
15- use Meilisearch \Bundle \Tests \Entity \Link ;
16- use Meilisearch \Bundle \Tests \Entity \ObjectId \DummyObjectId ;
17- use Meilisearch \Bundle \Tests \Entity \Page ;
18- use Meilisearch \Bundle \Tests \Entity \Podcast ;
1911use Meilisearch \Bundle \Tests \Entity \Post ;
20- use Meilisearch \Bundle \Tests \Entity \Tag ;
2112use Meilisearch \Client ;
2213use Meilisearch \Exceptions \ApiException ;
2314use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
@@ -44,156 +35,16 @@ protected function setUp(): void
4435 $ this ->cleanUp ();
4536 }
4637
47- protected function createPost (? int $ id = null ): Post
38+ protected function createPost (): Post
4839 {
49- $ post = new Post ();
50- $ post ->setTitle ('Test Post ' );
51- $ post ->setContent ('Test content post ' );
52-
53- if (null !== $ id ) {
54- $ post ->setId ($ id );
55- }
40+ $ post = new Post ('Test Post ' , 'Test content post ' );
5641
5742 $ this ->entityManager ->persist ($ post );
5843 $ this ->entityManager ->flush ();
5944
6045 return $ post ;
6146 }
6247
63- protected function createPage (int $ id ): Page
64- {
65- $ page = new Page ();
66- $ page ->setTitle ('Test Page ' );
67- $ page ->setContent ('Test content page ' );
68- $ page ->setId (new DummyObjectId ($ id ));
69-
70- $ this ->entityManager ->persist ($ page );
71- $ this ->entityManager ->flush ();
72-
73- return $ page ;
74- }
75-
76- protected function createSearchablePost (): SearchableEntity
77- {
78- $ post = $ this ->createPost (random_int (100 , 300 ));
79-
80- return new SearchableEntity (
81- $ this ->getPrefix ().'posts ' ,
82- $ post ,
83- $ this ->get ('doctrine ' )->getManager ()->getClassMetadata (Post::class),
84- $ this ->get ('serializer ' )
85- );
86- }
87-
88- protected function createComment (?int $ id = null ): Comment
89- {
90- $ post = new Post (['title ' => 'What a post! ' ]);
91- $ comment = new Comment ();
92- $ comment ->setContent ('Comment content ' );
93- $ comment ->setPost ($ post );
94-
95- if (null !== $ id ) {
96- $ comment ->setId ($ id );
97- }
98-
99- $ this ->entityManager ->persist ($ post );
100- $ this ->entityManager ->persist ($ comment );
101- $ this ->entityManager ->flush ();
102-
103- return $ comment ;
104- }
105-
106- protected function createImage (?int $ id = null ): Image
107- {
108- $ image = new Image ();
109- $ image ->setUrl ('https://docs.meilisearch.com/logo.png ' );
110-
111- if (null !== $ id ) {
112- $ image ->setId ($ id );
113- }
114-
115- $ this ->entityManager ->persist ($ image );
116- $ this ->entityManager ->flush ();
117-
118- return $ image ;
119- }
120-
121- protected function createArticle (?int $ id = null ): Article
122- {
123- $ article = new Article ();
124- $ article ->setTitle ('Test Article ' );
125- if (null !== $ id ) {
126- $ article ->setId ($ id );
127- }
128-
129- $ this ->entityManager ->persist ($ article );
130- $ this ->entityManager ->flush ();
131-
132- return $ article ;
133- }
134-
135- protected function createPodcast (?int $ id = null ): Podcast
136- {
137- $ podcast = new Podcast ();
138- $ podcast ->setTitle ('Test Podcast ' );
139- if (null !== $ id ) {
140- $ podcast ->setId ($ id );
141- }
142-
143- $ this ->entityManager ->persist ($ podcast );
144- $ this ->entityManager ->flush ();
145-
146- return $ podcast ;
147- }
148-
149- protected function createSearchableImage (): SearchableEntity
150- {
151- $ image = $ this ->createImage (random_int (100 , 300 ));
152-
153- return new SearchableEntity (
154- $ this ->getPrefix ().'image ' ,
155- $ image ,
156- $ this ->get ('doctrine ' )->getManager ()->getClassMetadata (Image::class),
157- null
158- );
159- }
160-
161- protected function createTag (array $ properties = []): Tag
162- {
163- $ tag = new Tag ();
164- $ tag ->setName ('Meilisearch Test Tag ' );
165-
166- if (\count ($ properties ) > 0 ) {
167- foreach ($ properties as $ key => $ value ) {
168- $ method = 'set ' .ucfirst ($ key );
169- $ tag ->$ method ($ value );
170- }
171- }
172-
173- $ this ->entityManager ->persist ($ tag );
174- $ this ->entityManager ->flush ();
175-
176- return $ tag ;
177- }
178-
179- protected function createLink (array $ properties = []): Link
180- {
181- $ link = new Link ();
182- $ link ->setName ('Meilisearch Test Link ' );
183-
184- if (\count ($ properties ) > 0 ) {
185- foreach ($ properties as $ key => $ value ) {
186- $ method = 'set ' .ucfirst ($ key );
187- $ link ->$ method ($ value );
188- }
189- }
190-
191- $ this ->entityManager ->persist ($ link );
192- $ this ->entityManager ->flush ();
193-
194- return $ link ;
195- }
196-
19748 protected function getPrefix (): string
19849 {
19950 return $ this ->searchService ->getConfiguration ()->get ('prefix ' );
@@ -204,11 +55,6 @@ protected function get(string $id): ?object
20455 return self ::getContainer ()->get ($ id );
20556 }
20657
207- protected function getFileName (string $ indexName , string $ type ): string
208- {
209- return \sprintf ('%s/%s.json ' , $ indexName , $ type );
210- }
211-
21258 protected function waitForAllTasks (): void
21359 {
21460 $ firstTask = $ this ->client ->getTasks ()->getResults ()[0 ];
@@ -219,13 +65,10 @@ private function cleanUp(): void
21965 {
22066 (new Collection ($ this ->searchService ->getConfiguration ()->get ('indices ' )))
22167 ->each (function ($ item ): bool {
222- $ this ->cleanupIndex ($ this -> getPrefix (). $ item ['name ' ]);
68+ $ this ->cleanupIndex ($ item ['prefixed_name ' ]);
22369
22470 return true ;
22571 });
226-
227- $ this ->cleanupIndex ($ this ->getPrefix ().'indexA ' );
228- $ this ->cleanupIndex ($ this ->getPrefix ().'indexB ' );
22972 }
23073
23174 private function cleanupIndex (string $ indexName ): void
0 commit comments