Skip to content

Commit 9ebff7d

Browse files
committed
test: add test suite for synonym sets
1 parent 13bf6b5 commit 9ebff7d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/Feature/SynonymSetsTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)