1+ <?php
2+
3+ namespace Feature ;
4+
5+ use Tests \TestCase ;
6+ use Typesense \Exceptions \ObjectNotFound ;
7+ use Exception ;
8+
9+ class SynonymSetsTest extends TestCase
10+ {
11+ private $ upsertResponse = null ;
12+ private $ synonymSets = null ;
13+ private $ synonymSetData = [
14+ 'synonyms ' => [
15+ [
16+ 'id ' => 'dummy ' ,
17+ 'synonyms ' => ['foo ' , 'bar ' , 'baz ' ],
18+ 'root ' => '' ,
19+ ],
20+ ],
21+ ];
22+
23+ protected function setUp (): void
24+ {
25+ parent ::setUp ();
26+
27+ if (!$ this ->isV30OrAbove ()) {
28+ $ this ->markTestSkipped ('SynonymSets is only supported in Typesense v30+ ' );
29+ }
30+
31+ $ this ->synonymSets = $ this ->client ()->synonymSets ;
32+ $ this ->upsertResponse = $ this ->synonymSets ->upsert ('test-synonym-set ' , $ this ->synonymSetData );
33+ }
34+
35+
36+ public function testCanUpsertASynonymSet (): void
37+ {
38+ $ this ->assertEquals ($ this ->synonymSetData ['synonyms ' ], $ this ->upsertResponse ['synonyms ' ]);
39+ }
40+
41+ public function testCanRetrieveAllSynonymSets (): void
42+ {
43+ $ returnData = $ this ->synonymSets ->retrieve ();
44+ $ this ->assertCount (1 , $ returnData );
45+ }
46+
47+ public function testCanRetrieveASpecificSynonymSet (): void
48+ {
49+ $ returnData = $ this ->synonymSets ['test-synonym-set ' ]->retrieve ();
50+ $ this ->assertEquals ($ this ->synonymSetData ['synonyms ' ], $ returnData ['synonyms ' ]);
51+ }
52+
53+ public function testCanDeleteASynonymSet (): void
54+ {
55+ $ returnData = $ this ->synonymSets ['test-synonym-set ' ]->delete ();
56+ $ this ->assertEquals ('test-synonym-set ' , $ returnData ['name ' ]);
57+
58+ $ this ->expectException (ObjectNotFound::class);
59+ $ this ->synonymSets ['test-synonym-set ' ]->retrieve ();
60+ }
61+ }
0 commit comments