-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathRunCommandTest.php
More file actions
129 lines (105 loc) · 4.11 KB
/
RunCommandTest.php
File metadata and controls
129 lines (105 loc) · 4.11 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Tests\Unit\Command;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
use Yiisoft\Queue\Command\RunCommand;
use Yiisoft\Queue\Provider\PredefinedQueueProvider;
use Yiisoft\Queue\Provider\QueueProviderInterface;
use Yiisoft\Queue\QueueInterface;
final class RunCommandTest extends TestCase
{
public function testExecuteWithSingleQueue(): void
{
$queue = $this->createMock(QueueInterface::class);
$queue->expects($this->once())
->method('run')
->with($this->equalTo(0))
->willReturn(5);
$queueProvider = new PredefinedQueueProvider([
'test-queue' => $queue,
]);
$input = new StringInput('test-queue');
$output = $this->createMock(OutputInterface::class);
$output->expects($this->once())
->method('write')
->with($this->equalTo('Processing queue test-queue... '));
$output->expects($this->once())
->method('writeln')
->with($this->equalTo('Messages processed: 5.'));
$command = new RunCommand($queueProvider);
$exitCode = $command->run($input, $output);
$this->assertEquals(0, $exitCode);
}
public function testExecuteWithMultipleQueues(): void
{
$queue1 = $this->createMock(QueueInterface::class);
$queue1->expects($this->once())
->method('run')
->with($this->equalTo(0))
->willReturn(3);
$queue2 = $this->createMock(QueueInterface::class);
$queue2->expects($this->once())
->method('run')
->with($this->equalTo(0))
->willReturn(7);
$queueProvider = new PredefinedQueueProvider([
'queue1' => $queue1,
'queue2' => $queue2,
]);
$output = $this->createMock(OutputInterface::class);
$output->expects($this->exactly(2))
->method('write');
$output->expects($this->exactly(2))
->method('writeln');
$input = new StringInput('queue1 queue2');
$command = new RunCommand($queueProvider);
$exitCode = $command->run($input, $output);
$this->assertEquals(0, $exitCode);
}
public function testExecuteWithMaximumOption(): void
{
$queue = $this->createMock(QueueInterface::class);
$queue->expects($this->once())
->method('run')
->with($this->equalTo(100))
->willReturn(10);
$queueProvider = new PredefinedQueueProvider([
'test-queue' => $queue,
]);
$input = new StringInput('test-queue --maximum=100');
$output = $this->createMock(OutputInterface::class);
$output->expects($this->once())
->method('write')
->with($this->equalTo('Processing queue test-queue... '));
$output->expects($this->once())
->method('writeln')
->with($this->equalTo('Messages processed: 10.'));
$command = new RunCommand($queueProvider);
$exitCode = $command->run($input, $output);
$this->assertEquals(0, $exitCode);
}
public function testExecuteWithDefaultQueues(): void
{
$queue = $this->createMock(QueueInterface::class);
$queue->expects($this->once())
->method('run')
->with($this->equalTo(0))
->willReturn(2);
$queueProvider = new PredefinedQueueProvider([
QueueProviderInterface::DEFAULT_QUEUE => $queue,
]);
$input = new StringInput('');
$output = $this->createMock(OutputInterface::class);
$output->expects($this->once())
->method('write')
->with($this->equalTo('Processing queue ' . QueueProviderInterface::DEFAULT_QUEUE . '... '));
$output->expects($this->once())
->method('writeln')
->with($this->equalTo('Messages processed: 2.'));
$command = new RunCommand($queueProvider);
$exitCode = $command->run($input, $output);
$this->assertEquals(0, $exitCode);
}
}