Skip to content

Commit f602e62

Browse files
committed
test(commands): Add ClearCommandTest
- Add ClearCommandTest to test the ClearCommand functionality - Set up the Soar facade to generate a log file - Check if the log file exists before clearing it - Assert that the log file no longer exists after clearing
1 parent 8b772d7 commit f602e62

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/Commands/ClearCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Guanguans\LaravelSoar\Commands;
1414

15-
use Guanguans\LaravelSoar\Soar;
15+
use Guanguans\LaravelSoar\Facades\Soar;
1616
use Illuminate\Console\Command;
1717
use Illuminate\Support\Facades\File;
1818

@@ -22,12 +22,11 @@ class ClearCommand extends Command
2222

2323
protected $description = 'Clear the Soar log file';
2424

25-
public function handle(Soar $soar): void
25+
public function handle(): void
2626
{
2727
$this->info('Clearing Soar log file...');
2828

29-
$logFile = config('soar.options.-log-output') ?: \dirname($soar->getSoarPath()).'/soar.log';
30-
File::delete($logFile);
29+
File::delete($logFile = Soar::getLogOutput(\dirname(Soar::getSoarPath()).\DIRECTORY_SEPARATOR.'soar.log'));
3130

3231
$this->info("The Soar log file($logFile) has been cleared.");
3332
}

tests/Commands/ClearCommandTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the guanguans/laravel-soar.
7+
*
8+
* (c) guanguans <ityaozm@gmail.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled.
11+
*/
12+
13+
namespace Tests\Facades;
14+
15+
use Guanguans\LaravelSoar\Commands\ClearCommand;
16+
use Guanguans\LaravelSoar\Facades\Soar;
17+
18+
use function Pest\Laravel\artisan;
19+
20+
it('can clear the Soar log file', function (): void {
21+
Soar::onlyVerbose()->scores('select * from foo');
22+
$logFile = Soar::getLogOutput(\dirname(Soar::getSoarPath()).\DIRECTORY_SEPARATOR.'soar.log');
23+
24+
expect($logFile)->toBeFile();
25+
artisan(ClearCommand::class)->expectsOutput('Clearing Soar log file...')->assertSuccessful();
26+
expect($logFile)->not->toBeFile();
27+
})->group(__DIR__, __FILE__);

0 commit comments

Comments
 (0)