Skip to content

Commit 9bae9fe

Browse files
authored
Merge pull request #54 from yaroslavpopovic/patch-collection
2 parents 0ba31dc + b4983ca commit 9bae9fe

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/Endpoints/Collections.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ public function info(): Response
6464
);
6565
}
6666

67+
/**
68+
* # Collection exists
69+
* Checks whether the specified collection exists.
70+
*
71+
* @throws InvalidArgumentException
72+
*/
73+
public function exists(): Response
74+
{
75+
return $this->client->execute(
76+
$this->createRequest('GET', '/collections/' . $this->getCollectionName(). '/exists')
77+
);
78+
}
79+
6780
/**
6881
* # Delete collection
6982
* Drop collection and all associated data
@@ -121,4 +134,4 @@ public function cluster(): Cluster
121134
{
122135
return (new Cluster($this->client))->setCollectionName($this->collectionName);
123136
}
124-
}
137+
}

tests/Integration/Endpoints/CollectionsTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ public function testCollections(): void
5454
$this->assertEquals('ok', $response['status']);
5555
}
5656

57+
/**
58+
* @throws InvalidArgumentException
59+
*/
60+
public function testCollectionExits(): void
61+
{
62+
$collections = new Collections($this->client);
63+
$collections->setCollectionName('sample-collection');
64+
65+
$response = $collections->create(self::sampleCollectionOption());
66+
$this->assertEquals('ok', $response['status']);
67+
68+
$response = $collections->exists();
69+
$this->assertEquals(true, $response['result']['exists']);
70+
71+
$response = $collections->setCollectionName('sample-collection-that-not-exists')->exists();
72+
$this->assertEquals(false, $response['result']['exists']);
73+
}
74+
5775
public function testCollectionsCluster(): void
5876
{
5977
$collections = new Collections($this->client);
@@ -185,4 +203,4 @@ protected function tearDown(): void
185203
$collections->setCollectionName('sample-collection')->delete();
186204
$collections->setCollectionName('other-collection')->delete();
187205
}
188-
}
206+
}

0 commit comments

Comments
 (0)