Repository navigation
Expand file tree
/
Copy pathCollectionsTest.php
More file actions
83 lines (66 loc) · 2.46 KB
/
Copy pathCollectionsTest.php
File metadata and controls
83 lines (66 loc) · 2.46 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
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Typesense\Collection;
use Typesense\Exceptions\ObjectNotFound;
class CollectionsTest extends TestCase
{
private $createCollectionRes = null;
private ?Collection $testCollection = null;
protected function setUp(): void
{
parent::setUp();
$schema = $this->getSchema('books');
$this->createCollectionRes = $this->client()->collections->create($schema);
$this->testCollection = $this->client()->collections['books'];
}
public function testCanCreateACollection(): void
{
$this->assertEquals('books', $this->createCollectionRes['name']);
}
public function testCanRetrieveACollection(): void
{
$response = $this->testCollection->retrieve();
$this->assertEquals('books', $response['name']);
}
public function testCanUpdateACollection(): void
{
$update_schema = [
'fields' => [
[
'name' => 'isbn',
'drop' => true
]
]
];
$response = $this->testCollection->update($update_schema);
$this->assertEquals('isbn', $response['fields'][0]['name']);
$this->assertArrayHasKey('drop', $response['fields'][0]);
$response = $this->testCollection->retrieve();
$this->assertEquals(5, count($response['fields']));
}
public function testCanDeleteACollection(): void
{
$this->testCollection->delete();
$this->expectException(ObjectNotFound::class);
$this->testCollection->retrieve();
}
public function testCanRetrieveAllCollections(): void
{
$response = $this->client()->collections->retrieve();
$this->assertCount(1, $response);
}
public function testCanCloneACollectionSchema(): void
{
$response = $this->client()->collections->create(['name' => 'books_v2'], ["src_name" => "books"]);
$this->assertEquals('books_v2', $response['name']);
$this->assertEquals($this->createCollectionRes['fields'], $response['fields']);
}
public function testPrivateFieldNamesResolveToCollections(): void
{
$collections = $this->client()->collections;
$this->assertInstanceOf(Collection::class, $collections->apiCall);
$this->assertSame($collections['apiCall'], $collections->apiCall);
$this->assertSame($collections['typesenseCollections'], $collections->typesenseCollections);
}
}