forked from typesense/typesense-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSynonymSetItemsTest.php
More file actions
70 lines (57 loc) · 2.01 KB
/
SynonymSetItemsTest.php
File metadata and controls
70 lines (57 loc) · 2.01 KB
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
<?php
namespace Feature;
use Tests\TestCase;
use Exception;
class SynonymSetItemsTest extends TestCase
{
private $synonymSets = null;
private $synonymSetData = [
'items' => [
[
'id' => 'synonym-rule-1',
'synonyms' => ['foo', 'bar', 'baz'],
'root' => '',
],
],
];
protected function setUp(): void
{
parent::setUp();
if (!$this->isV30OrAbove()) {
$this->markTestSkipped('SynonymSetItems is only supported in Typesense v30+');
}
$this->synonymSets = $this->client()->synonymSets;
$this->synonymSets->upsert('test-synonym-set-items', $this->synonymSetData);
}
protected function tearDown(): void
{
try {
if ($this->synonymSets !== null) {
$this->synonymSets['test-synonym-set-items']->delete();
}
} catch (Exception $e) {
// Ignore cleanup errors
}
parent::tearDown();
}
public function testCanListItemsInASynonymSet(): void
{
$items = $this->synonymSets['test-synonym-set-items']->getItems()->retrieve();
$this->assertIsArray($items);
$this->assertGreaterThan(0, count($items));
$this->assertEquals('foo', $items[0]['synonyms'][0]);
}
public function testCanUpsertRetrieveAndDeleteAnItem(): void
{
$upserted = $this->synonymSets['test-synonym-set-items']->getItems()['synonym-rule-1']->upsert([
'id' => 'synonym-rule-1',
'synonyms' => ['red', 'crimson'],
'root' => '',
]);
$this->assertEquals('synonym-rule-1', $upserted['id']);
$fetched = $this->synonymSets['test-synonym-set-items']->getItems()['synonym-rule-1']->retrieve();
$this->assertEquals('red', $fetched['synonyms'][0]);
$deletion = $this->synonymSets['test-synonym-set-items']->getItems()['synonym-rule-1']->delete();
$this->assertEquals('synonym-rule-1', $deletion['id']);
}
}