Skip to content

Commit b8ba482

Browse files
committed
test: synonym & synonyms
1 parent 99a08a1 commit b8ba482

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/Feature/SynonymsTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
use Typesense\Exceptions\ObjectNotFound;
7+
8+
9+
class SynonymsTest extends TestCase
10+
{
11+
private $upsertResponse = null;
12+
private $synonyms = null;
13+
private $synonymData = [
14+
"synonyms" => ["blazer", "coat", "jacket"]
15+
];
16+
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
$this->setUpCollection('books');
21+
22+
$this->synonyms = $this->client()->collections['books']->synonyms;
23+
$this->upsertResponse = $this->synonyms->upsert('coat-synonyms', $this->synonymData);
24+
}
25+
26+
public function testCanUpsertASynonym(): void
27+
{
28+
$this->assertEquals('coat-synonyms', $this->upsertResponse['id']);
29+
$this->assertEquals($this->synonymData['synonyms'], $this->upsertResponse['synonyms']);
30+
}
31+
32+
public function testCanRetrieveASynonymById(): void
33+
{
34+
$returnData = $this->synonyms['coat-synonyms']->retrieve();
35+
$this->assertEquals('coat-synonyms', $returnData['id']);
36+
}
37+
38+
public function testCanDeleteASynonymById(): void
39+
{
40+
$returnData = $this->synonyms['coat-synonyms']->delete();
41+
$this->assertEquals('coat-synonyms', $returnData['id']);
42+
43+
$this->expectException(ObjectNotFound::class);
44+
$this->synonyms['coat-synonyms']->retrieve();
45+
}
46+
47+
public function testCanRetrieveAllSynonyms(): void
48+
{
49+
$returnData = $this->synonyms->retrieve();
50+
$this->assertEquals(1, count($returnData['synonyms']));
51+
}
52+
}

0 commit comments

Comments
 (0)