Skip to content

Commit

Permalink
add testing for debouncing from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
zackAJ committed Feb 6, 2025
1 parent ff4d284 commit 3e261b2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/Feature/DebounceCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Queue;
use Zackaj\LaravelDebounce\Commands\DebounceConsoleCommand;
use Zackaj\LaravelDebounce\DebounceCommand;
use Zackaj\LaravelDebounce\Facades\Debounce;
use Zackaj\LaravelDebounce\Tests\BaseCase;
Expand Down Expand Up @@ -57,6 +58,44 @@ public function test_debounce_command_is_fired()

$this->assertTrue(DCommand::$fired);
}

public function test_debounce_from_cli_is_debounced_and_fired()
{
Queue::fake();
Artisan::registerCommand(new NormalCommand);
Artisan::registerCommand(new DCommand);
Artisan::registerCommand(new DebounceConsoleCommand);
$commands = [
['signature' => 'test:test', 'class' => NormalCommand::class],
['signature' => 'dtest:test', 'class' => DCommand::class],
];

foreach ($commands as $key => $cmd) {
//for future tests
$args = [
'command' => $cmd['signature'],
'delay' => 0,
'uniqueKey' => 'key',
'parameters' => [
'word' => 'hello',
],
];

$commandString = sprintf(
'debounce:command %s %s %s %s',
$args['delay'],
$args['uniqueKey'],
$args['command'],
$args['parameters']['word'],
);

$this->artisan($commandString)->assertSuccessful();
$this->artisan($commandString)->assertSuccessful();
Queue::assertCount($key + 1);

$this->assertTrue($cmd['class']::$fired);
}
}
}

class NormalCommand extends Command
Expand Down

0 comments on commit 3e261b2

Please sign in to comment.