Skip to content

Commit

Permalink
Merge pull request #4 from Artistan/fix-last
Browse files Browse the repository at this point in the history
Fix to keep last file with option
  • Loading branch information
hedii committed Dec 5, 2017
2 parents fa3cb07 + 96a7edc commit 7fc9efb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
},
"laravel": {
"providers": [
"Hedii\\ArtisanLogCleaner\\ArtisanLogCleanerServiceProvider"
]
}
}
}
2 changes: 1 addition & 1 deletion src/ClearLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function handle()
{
$files = $this->getLogFiles();

if ($this->option('keep-last') && $files->count() > 1) {
if ($this->option('keep-last') && $files->count() >= 1) {
$files->shift();
}

Expand Down
11 changes: 11 additions & 0 deletions tests/ClearLogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public function test_it_should_keep_the_last_log_file_if_the_option_is_provided(
}
}

public function test_it_should_keep_the_last_log_file_if_the_option_is_with_only_one_file()
{
touch($this->logDirectory . '/file1.log', time() - 3600);

if (! $this->artisan('log:clear', ['--keep-last' => true])) {
$this->assertFileExists($this->logDirectory . '/file1.log');
} else {
$this->assertTrue(false, 'this test failed...');
}
}

public function test_it_should_return_zero_even_if_there_is_no_log_file()
{
$this->assertEquals(0, $this->artisan('log:clear'));
Expand Down

0 comments on commit 7fc9efb

Please sign in to comment.