diff --git a/docs/schema-collections.md b/docs/schema-collections.md index f0584f4..6200a7d 100644 --- a/docs/schema-collections.md +++ b/docs/schema-collections.md @@ -81,6 +81,7 @@ Delete a collection ``` $arangoClient->schema()->deleteCollection('users'); ``` + ### deleteAllCollections(): bool This method deletes all non-system collections available on the current database. diff --git a/docs/schema-views.md b/docs/schema-views.md index ab11cc1..21ca0bd 100644 --- a/docs/schema-views.md +++ b/docs/schema-views.md @@ -64,3 +64,10 @@ $arangoClient->schema()->updateView('pages', [ $arangoClient->schema()->deleteView('testViewBasics'); ``` +### deleteAllViews(): bool +This method deletes all views available on the current database. + +``` +$arangoClient->schema()->deleteAllViews(); +``` + diff --git a/src/Schema/ManagesViews.php b/src/Schema/ManagesViews.php index 8fa494c..ace5459 100644 --- a/src/Schema/ManagesViews.php +++ b/src/Schema/ManagesViews.php @@ -47,6 +47,20 @@ public function deleteView(string $name): bool return (bool) $this->arangoClient->request('delete', $uri); } + /** + * @throws ArangoException + */ + public function deleteAllViews(): bool + { + $views = $this->getViews(); + + foreach ($views as $view) { + $this->deleteView($view->name); + } + + return true; + } + /** * @see https://www.arangodb.com/docs/stable/http/views-arangosearch.html#list-all-views * diff --git a/tests/SchemaManagerViewsTest.php b/tests/SchemaManagerViewsTest.php index 5ed96ad..2934092 100644 --- a/tests/SchemaManagerViewsTest.php +++ b/tests/SchemaManagerViewsTest.php @@ -89,3 +89,25 @@ $deleted = $this->schemaManager->deleteView($view['name']); expect($deleted)->toBeTrue(); }); + +test('deleteAllViews', function () { + $view1 = [ + 'name' => 'view1', + ]; + $view2 = [ + 'name' => 'view2', + ]; + $this->schemaManager->createView($view1); + $this->schemaManager->createView($view2); + + + $createdViews = $this->schemaManager->getViews(); + + $result = $this->schemaManager->deleteAllViews(); + + $finalViews = $this->schemaManager->getViews(); + + expect($result)->toBeTrue(); + expect(count($createdViews))->toBe(3); + expect(count($finalViews))->toBe(0); +});