diff --git a/docs/schema-collections.md b/docs/schema-collections.md index 4c7fc1c..f0584f4 100644 --- a/docs/schema-collections.md +++ b/docs/schema-collections.md @@ -81,4 +81,10 @@ Delete a collection ``` $arangoClient->schema()->deleteCollection('users'); ``` +### deleteAllCollections(): bool +This method deletes all non-system collections available on the current database. + +``` +$arangoClient->schema()->deleteAllCollections(); +``` diff --git a/src/Schema/ManagesAnalyzers.php b/src/Schema/ManagesAnalyzers.php index 581d37f..d0ef3e0 100644 --- a/src/Schema/ManagesAnalyzers.php +++ b/src/Schema/ManagesAnalyzers.php @@ -71,9 +71,7 @@ public function deleteAllAnalyzers(): bool continue; } - $uri = '/_api/analyzer/' . $analyzer->name; - - $this->arangoClient->request('delete', $uri); + $this->deleteAnalyzer($analyzer->name); } return true; diff --git a/src/Schema/ManagesCollections.php b/src/Schema/ManagesCollections.php index ea2308c..db39948 100644 --- a/src/Schema/ManagesCollections.php +++ b/src/Schema/ManagesCollections.php @@ -214,4 +214,18 @@ public function deleteCollection(string $name): bool return (bool) $this->arangoClient->request('delete', $uri); } + + /** + * @throws ArangoException + */ + public function deleteAllCollections(): bool + { + $collections = $this->getCollections(true); + + foreach ($collections as $collection) { + $this->deleteCollection($collection->name); + } + + return true; + } } diff --git a/tests/SchemaManagerCollectionsTest.php b/tests/SchemaManagerCollectionsTest.php index f913ddd..a527bbf 100644 --- a/tests/SchemaManagerCollectionsTest.php +++ b/tests/SchemaManagerCollectionsTest.php @@ -192,3 +192,28 @@ $this->schemaManager->deleteCollection($collection); }); + +test('deleteAllCollections', function () { + $collection1 = 'collection1'; + $collection2 = 'collection2'; + + if (!$this->schemaManager->hasCollection($collection1)) { + $result = $this->schemaManager->createCollection($collection1, []); + expect($result->name)->toEqual($collection1); + } + + if (!$this->schemaManager->hasCollection($collection2)) { + $result = $this->schemaManager->createCollection($collection2, []); + expect($result->name)->toEqual($collection2); + } + + $createdCollections = $this->schemaManager->getCollections(true); + + $result = $this->schemaManager->deleteAllCollections(); + + $finalCollections = $this->schemaManager->getCollections(true); + + expect($result)->toBeTrue(); + expect(count($createdCollections))->toBe(2); + expect(count($finalCollections))->toBe(0); +});