Repository navigation
Expand file tree
/
Copy pathRetryBatchCommandTest.php
More file actions
82 lines (64 loc) · 2.84 KB
/
Copy pathRetryBatchCommandTest.php
File metadata and controls
82 lines (64 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Illuminate\Tests\Queue;
use Illuminate\Bus\BatchRepository;
use Illuminate\Console\Command;
use Illuminate\Console\CommandMutex;
use Illuminate\Foundation\Application;
use Illuminate\Queue\Console\RetryBatchCommand;
use Mockery;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
class RetryBatchCommandTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
}
public function testItFailsWhenTheBatchCannotBeFound()
{
$container = new Application;
$repository = Mockery::mock(BatchRepository::class);
$repository->shouldReceive('find')->with('missing-batch-id')->andReturnNull();
$container->instance(BatchRepository::class, $repository);
$command = new RetryBatchCommand;
$command->setLaravel($container);
$exitCode = $command->run(new ArrayInput(['id' => ['missing-batch-id']]), $output = new BufferedOutput);
$this->assertSame(Command::FAILURE, $exitCode);
$this->assertStringContainsString('Unable to find a batch with ID [missing-batch-id].', $output->fetch());
}
public function testItFailsWhenTheBatchHasNoFailedJobs()
{
$container = new Application;
$repository = Mockery::mock(BatchRepository::class);
$repository->shouldReceive('find')->with('batch-id')->andReturn(new class
{
public $failedJobIds = [];
});
$container->instance(BatchRepository::class, $repository);
$command = new RetryBatchCommand;
$command->setLaravel($container);
$exitCode = $command->run(new ArrayInput(['id' => ['batch-id']]), $output = new BufferedOutput);
$this->assertSame(Command::FAILURE, $exitCode);
$output = $output->fetch();
$this->assertStringContainsString('The batch with ID [batch-id] does not contain any failed jobs.', $output);
$this->assertStringNotContainsString('Pushing failed queue jobs of the batch', $output);
}
public function testItCanBeRunInIsolation()
{
$container = new Application;
$repository = Mockery::mock(BatchRepository::class);
$repository->shouldReceive('find')->with('batch-id')->andReturnNull();
$container->instance(BatchRepository::class, $repository);
$mutex = Mockery::mock(CommandMutex::class);
$mutex->shouldReceive('create')->andReturnTrue();
$mutex->shouldReceive('forget')->andReturnTrue();
$container->instance(CommandMutex::class, $mutex);
$command = new RetryBatchCommand;
$command->setLaravel($container);
$exitCode = $command->run(
new ArrayInput(['id' => ['batch-id'], '--isolated' => true]), new BufferedOutput
);
$this->assertSame(Command::FAILURE, $exitCode);
}
}