|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Feature; |
| 4 | + |
| 5 | +use Tests\TestCase; |
| 6 | +use Typesense\Exceptions\ObjectNotFound; |
| 7 | + |
| 8 | + |
| 9 | +class StopwordsTest extends TestCase |
| 10 | +{ |
| 11 | + private $stopwordsUpsertRes = null; |
| 12 | + |
| 13 | + protected function setUp(): void |
| 14 | + { |
| 15 | + parent::setUp(); |
| 16 | + |
| 17 | + $this->stopwordsUpsertRes = $this->client()->stopwords->put( |
| 18 | + [ |
| 19 | + "stopwords_name" => "stopword_set1", |
| 20 | + "stopwords_data" => ["Germany"], |
| 21 | + ] |
| 22 | + ); |
| 23 | + } |
| 24 | + |
| 25 | + protected function tearDown(): void |
| 26 | + { |
| 27 | + $stopwords = $this->client()->stopwords->getAll(); |
| 28 | + foreach ($stopwords['stopwords'] as $stopword) { |
| 29 | + $this->client()->stopwords->delete($stopword['id']); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + public function testCanUpsertAStopword(): void |
| 34 | + { |
| 35 | + $this->assertEquals("stopword_set1", $this->stopwordsUpsertRes['id']); |
| 36 | + $this->assertEquals(["Germany"], $this->stopwordsUpsertRes['stopwords']); |
| 37 | + } |
| 38 | + |
| 39 | + public function testCanRetrieveAStopword(): void |
| 40 | + { |
| 41 | + $returnData = $this->client()->stopwords->get("stopword_set1"); |
| 42 | + $this->assertEquals("stopword_set1", $returnData['stopwords']['id']); |
| 43 | + } |
| 44 | + |
| 45 | + public function testCanDeleteAStopword(): void |
| 46 | + { |
| 47 | + $returnData = $this->client()->stopwords->delete("stopword_set1"); |
| 48 | + $this->assertEquals("stopword_set1", $returnData['id']); |
| 49 | + |
| 50 | + $this->expectException(ObjectNotFound::class); |
| 51 | + $this->client()->stopwords->get("stopword_set1"); |
| 52 | + } |
| 53 | + |
| 54 | + public function testCanRetrieveAllStopwords(): void |
| 55 | + { |
| 56 | + $returnData = $this->client()->stopwords->getAll(); |
| 57 | + $this->assertEquals(1, count($returnData['stopwords'])); |
| 58 | + } |
| 59 | +} |
0 commit comments