forked from ARCANEDEV/LogViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear all logs using the
log-viewer:clear
command (ARCANEDEV#251)
* basic setup for ClearLogs Command * Feature - Clear All logs using a command. php artisan log-viewer:clear * asks for confirmation on the execution of the command, and added the tests for it using mockey * updated readme with new log-viewer:clear command * Updating/Cleaning the PR ARCANEDEV#210
- Loading branch information
1 parent
126598d
commit f222557
Showing
13 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php namespace Arcanedev\LogViewer\Commands; | ||
|
||
/** | ||
* Class ClearCommand | ||
* | ||
* @package Arcanedev\LogViewer\Commands | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
class ClearCommand extends Command | ||
{ | ||
/* ----------------------------------------------------------------- | ||
| Properties | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'log-viewer:clear'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Clear all generated log files'; | ||
|
||
/* ----------------------------------------------------------------- | ||
| Main Methods | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
if ($this->confirm('This will delete all the log files, Do you wish to continue?')) { | ||
$this->logViewer->clear(); | ||
$this->info('Successfully cleared the logs!'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php namespace Arcanedev\LogViewer\Tests\Commands; | ||
|
||
use Mockery; | ||
use Arcanedev\LogViewer\Tests\TestCase; | ||
use Arcanedev\LogViewer\Contracts\LogViewer; | ||
use Arcanedev\LogViewer\Commands\ClearCommand; | ||
|
||
/** | ||
* Class ClearCommandTest | ||
* | ||
* @package Arcanedev\LogViewer\Tests\Commands | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
class ClearCommandTest extends TestCase | ||
{ | ||
/* ----------------------------------------------------------------- | ||
| Properties | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** @var \Arcanedev\LogViewer\LogViewer */ | ||
private $logViewer; | ||
|
||
/** @var string */ | ||
private $path; | ||
|
||
/* ----------------------------------------------------------------- | ||
| Main Methods | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->logViewer = $this->app->make(\Arcanedev\LogViewer\Contracts\LogViewer::class); | ||
$this->path = storage_path('logs-to-clear'); | ||
|
||
$this->setupForTests(); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
rmdir($this->path); | ||
unset($this->path); | ||
unset($this->logViewer); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/* ----------------------------------------------------------------- | ||
| Tests | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** @test */ | ||
|
||
public function it_can_delete_all_log_files() | ||
{ | ||
static::assertEquals(0, $this->logViewer->count()); | ||
|
||
static::createDummyLog(date('Y-m-d'), 'logs-to-clear'); | ||
|
||
static::assertEquals(1, $this->logViewer->count()); | ||
|
||
$this->artisan('log-viewer:clear') | ||
->expectsQuestion('This will delete all the log files, Do you wish to continue?', 'yes') | ||
->expectsOutput('Successfully cleared the logs!') | ||
->assertExitCode(0); | ||
|
||
static::assertEquals(0, $this->logViewer->count()); | ||
} | ||
|
||
/* ----------------------------------------------------------------- | ||
| Other Methods | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* Sets the log storage path temporarily to a new directory | ||
*/ | ||
private function setupForTests() | ||
{ | ||
if ( ! file_exists($this->path)) | ||
mkdir($this->path, 0777, true); | ||
|
||
$this->logViewer->setPath($this->path); | ||
$this->app['config']->set(['log-viewer.storage-path' => $this->path]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters