Skip to content

Commit 3d28bdc

Browse files
authored
[10.x] Allow pruning all cancelled and unfinished queue batches (#46833)
* Allow pruning all cancelled and unfinished batches * Apply fixes from StyleCI
1 parent 2b463dd commit 3d28bdc

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/Illuminate/Queue/Console/PruneBatchesCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function handle()
4646

4747
$this->components->info("{$count} entries deleted.");
4848

49-
if ($this->option('unfinished')) {
49+
if ($this->option('unfinished') !== null) {
5050
$count = 0;
5151

5252
if ($repository instanceof DatabaseBatchRepository) {
@@ -56,7 +56,7 @@ public function handle()
5656
$this->components->info("{$count} unfinished entries deleted.");
5757
}
5858

59-
if ($this->option('cancelled')) {
59+
if ($this->option('cancelled') !== null) {
6060
$count = 0;
6161

6262
if ($repository instanceof DatabaseBatchRepository) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Queue;
4+
5+
use Illuminate\Bus\BatchRepository;
6+
use Illuminate\Bus\DatabaseBatchRepository;
7+
use Illuminate\Container\Container;
8+
use Illuminate\Queue\Console\PruneBatchesCommand;
9+
use Mockery as m;
10+
use PHPUnit\Framework\TestCase;
11+
use Symfony\Component\Console\Input\ArrayInput;
12+
use Symfony\Component\Console\Output\NullOutput;
13+
14+
class PruneBatchesCommandTest extends TestCase
15+
{
16+
protected function tearDown(): void
17+
{
18+
m::close();
19+
}
20+
21+
public function testAllowPruningAllUnfinishedBatches()
22+
{
23+
$container = new Container;
24+
$container->instance(BatchRepository::class, $repo = m::spy(DatabaseBatchRepository::class));
25+
26+
$command = new PruneBatchesCommand;
27+
$command->setLaravel($container);
28+
29+
$command->run(new ArrayInput(['--unfinished' => 0]), new NullOutput());
30+
31+
$repo->shouldHaveReceived('pruneUnfinished')->once();
32+
}
33+
34+
public function testAllowPruningAllCancelledBatches()
35+
{
36+
$container = new Container;
37+
$container->instance(BatchRepository::class, $repo = m::spy(DatabaseBatchRepository::class));
38+
39+
$command = new PruneBatchesCommand;
40+
$command->setLaravel($container);
41+
42+
$command->run(new ArrayInput(['--cancelled' => 0]), new NullOutput());
43+
44+
$repo->shouldHaveReceived('pruneCancelled')->once();
45+
}
46+
}

0 commit comments

Comments
 (0)