diff --git a/src/Endpoints/Collections.php b/src/Endpoints/Collections.php index 43e4a78..8e9d887 100644 --- a/src/Endpoints/Collections.php +++ b/src/Endpoints/Collections.php @@ -64,6 +64,19 @@ public function info(): Response ); } + /** + * # Collection exists + * Checks whether the specified collection exists. + * + * @throws InvalidArgumentException + */ + public function exists(): Response + { + return $this->client->execute( + $this->createRequest('GET', '/collections/' . $this->getCollectionName(). '/exists') + ); + } + /** * # Delete collection * Drop collection and all associated data @@ -121,4 +134,4 @@ public function cluster(): Cluster { return (new Cluster($this->client))->setCollectionName($this->collectionName); } -} \ No newline at end of file +} diff --git a/tests/Integration/Endpoints/CollectionsTest.php b/tests/Integration/Endpoints/CollectionsTest.php index b4af1ce..9c215b9 100644 --- a/tests/Integration/Endpoints/CollectionsTest.php +++ b/tests/Integration/Endpoints/CollectionsTest.php @@ -54,6 +54,24 @@ public function testCollections(): void $this->assertEquals('ok', $response['status']); } + /** + * @throws InvalidArgumentException + */ + public function testCollectionExits(): void + { + $collections = new Collections($this->client); + $collections->setCollectionName('sample-collection'); + + $response = $collections->create(self::sampleCollectionOption()); + $this->assertEquals('ok', $response['status']); + + $response = $collections->exists(); + $this->assertEquals(true, $response['result']['exists']); + + $response = $collections->setCollectionName('sample-collection-that-not-exists')->exists(); + $this->assertEquals(false, $response['result']['exists']); + } + public function testCollectionsCluster(): void { $collections = new Collections($this->client); @@ -185,4 +203,4 @@ protected function tearDown(): void $collections->setCollectionName('sample-collection')->delete(); $collections->setCollectionName('other-collection')->delete(); } -} \ No newline at end of file +}