|
| 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