From cefc234a99158d74229b56b10ff58cef730d88ae Mon Sep 17 00:00:00 2001 From: yaroslavpopovic Date: Mon, 17 Jun 2024 10:20:23 +0200 Subject: [PATCH 1/2] Update Collections.php Added exists method --- src/Endpoints/Collections.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 +} From b4983ca9b5641d88a7d304868a8a39cb3425f5de Mon Sep 17 00:00:00 2001 From: yaroslavpopovic Date: Thu, 20 Jun 2024 17:12:28 +0200 Subject: [PATCH 2/2] Update CollectionsTest.php Add testCollectionExits --- .../Integration/Endpoints/CollectionsTest.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 +}