From b765c99cea137625a8b7a0de97d6df434cd8d480 Mon Sep 17 00:00:00 2001 From: ArtARTs36 Date: Thu, 20 Aug 2020 01:09:17 +0300 Subject: [PATCH] add action delete repository --- readme.md | 11 +++++++++++ src/Action.php | 10 ++++++++++ tests/ActionTest.php | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/readme.md b/readme.md index 8d313411..e4bdb7c3 100644 --- a/readme.md +++ b/readme.md @@ -126,3 +126,14 @@ $action = new \ArtARTs36\GitHandler\Action($git); $action->createFile('file.php', 'echo hello world'); $action->createFile('file.php', 'echo hello world', 'folder_name'); ``` + +#### delete repository: + +```php +use ArtARTs36\GitHandler\Git; + +$git = new Git('/var/web/project'); +$action = new \ArtARTs36\GitHandler\Action($git); + +$action->delete(); +``` diff --git a/src/Action.php b/src/Action.php index b79158d2..c1b46f7a 100644 --- a/src/Action.php +++ b/src/Action.php @@ -2,6 +2,8 @@ namespace ArtARTs36\GitHandler; +use ArtARTs36\GitHandler\Support\FileSystem; + /** * Class Action * @package ArtARTs36\GitHandler @@ -57,4 +59,12 @@ public function createFile(string $name, string $content, string $folder = null) return $path; } + + /** + * @return bool + */ + public function delete(): bool + { + return FileSystem::removeDir($this->git->getDir()); + } } diff --git a/tests/ActionTest.php b/tests/ActionTest.php index aeee60e7..18693939 100644 --- a/tests/ActionTest.php +++ b/tests/ActionTest.php @@ -58,6 +58,22 @@ public function testCreateFile(): void ); } + /** + * @covers \ArtARTs36\GitHandler\Action::delete + */ + public function testDelete(): void + { + $action = $this->mock(); + + self::assertFileExists($this->getTmpDir()); + + // + + $action->delete(); + + self::assertFileDoesNotExist($this->getTmpDir()); + } + private function mock(): Action { $dir = $this->getTmpDir();