-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathSimpleConsumeCommandTest.php
142 lines (116 loc) · 4.54 KB
/
SimpleConsumeCommandTest.php
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
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace Enqueue\Tests\Symfony\Client;
use Enqueue\Client\Config;
use Enqueue\Client\DelegateProcessor;
use Enqueue\Client\DriverInterface;
use Enqueue\Client\RouteCollection;
use Enqueue\Consumption\ChainExtension;
use Enqueue\Consumption\QueueConsumerInterface;
use Enqueue\NoEffect\NullQueue;
use Enqueue\Symfony\Client\ConsumeCommand;
use Enqueue\Symfony\Client\SimpleConsumeCommand;
use Enqueue\Test\ClassExtensionTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
class SimpleConsumeCommandTest extends TestCase
{
use ClassExtensionTrait;
public function testShouldBeSubClassOfConsumeCommand()
{
$this->assertClassExtends(ConsumeCommand::class, SimpleConsumeCommand::class);
}
public function testShouldNotBeFinal()
{
$this->assertClassNotFinal(SimpleConsumeCommand::class);
}
public function testCouldBeConstructedWithRequiredAttributes()
{
new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock());
}
public function testShouldHaveCommandName()
{
$command = new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock());
$this->assertEquals('enqueue:consume', $command->getName());
}
public function testShouldHaveExpectedOptions()
{
$command = new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock());
$options = $command->getDefinition()->getOptions();
$this->assertCount(9, $options);
$this->assertArrayHasKey('memory-limit', $options);
$this->assertArrayHasKey('message-limit', $options);
$this->assertArrayHasKey('time-limit', $options);
$this->assertArrayHasKey('receive-timeout', $options);
$this->assertArrayHasKey('niceness', $options);
$this->assertArrayHasKey('client', $options);
$this->assertArrayHasKey('logger', $options);
$this->assertArrayHasKey('skip', $options);
$this->assertArrayHasKey('setup-broker', $options);
}
public function testShouldHaveExpectedAttributes()
{
$command = new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock());
$arguments = $command->getDefinition()->getArguments();
$this->assertCount(1, $arguments);
$this->assertArrayHasKey('client-queue-names', $arguments);
}
public function testShouldBindDefaultQueueOnly()
{
$queue = new NullQueue('');
$routeCollection = new RouteCollection([]);
$processor = $this->createDelegateProcessorMock();
$consumer = $this->createQueueConsumerMock();
$consumer
->expects($this->once())
->method('bind')
->with($this->identicalTo($queue), $this->identicalTo($processor))
;
$consumer
->expects($this->once())
->method('consume')
->with($this->isInstanceOf(ChainExtension::class))
;
$driver = $this->createDriverStub($routeCollection);
$driver
->expects($this->once())
->method('createQueue')
->with('default', true)
->willReturn($queue)
;
$command = new SimpleConsumeCommand($consumer, $driver, $processor);
$tester = new CommandTester($command);
$tester->execute([]);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject|DelegateProcessor
*/
private function createDelegateProcessorMock()
{
return $this->createMock(DelegateProcessor::class);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject|QueueConsumerInterface
*/
private function createQueueConsumerMock()
{
return $this->createMock(QueueConsumerInterface::class);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject|DriverInterface
*/
private function createDriverStub(?RouteCollection $routeCollection = null): DriverInterface
{
$driverMock = $this->createMock(DriverInterface::class);
$driverMock
->expects($this->any())
->method('getRouteCollection')
->willReturn($routeCollection ?? new RouteCollection([]))
;
$driverMock
->expects($this->any())
->method('getConfig')
->willReturn(Config::create('aPrefix', 'anApp'))
;
return $driverMock;
}
}