|
12 | 12 | namespace Symfony\Component\Messenger\Tests\Command;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Psr\Log\LoggerInterface; |
| 16 | +use Psr\Log\LoggerTrait; |
15 | 17 | use Symfony\Component\Console\Application;
|
16 | 18 | use Symfony\Component\Console\Exception\InvalidOptionException;
|
17 | 19 | use Symfony\Component\Console\Tester\CommandCompletionTester;
|
@@ -214,6 +216,50 @@ public function testRunWithTimeLimit()
|
214 | 216 | $this->assertStringContainsString('[OK] Consuming messages from transport "dummy-receiver"', $tester->getDisplay());
|
215 | 217 | }
|
216 | 218 |
|
| 219 | + public function testRunWithMemoryLimit() |
| 220 | + { |
| 221 | + $envelope = new Envelope(new \stdClass(), [new BusNameStamp('dummy-bus')]); |
| 222 | + |
| 223 | + $receiver = $this->createMock(ReceiverInterface::class); |
| 224 | + $receiver->method('get')->willReturn([$envelope]); |
| 225 | + |
| 226 | + $receiverLocator = $this->createMock(ContainerInterface::class); |
| 227 | + $receiverLocator->method('has')->with('dummy-receiver')->willReturn(true); |
| 228 | + $receiverLocator->method('get')->with('dummy-receiver')->willReturn($receiver); |
| 229 | + |
| 230 | + $bus = $this->createMock(MessageBusInterface::class); |
| 231 | + |
| 232 | + $busLocator = $this->createMock(ContainerInterface::class); |
| 233 | + $busLocator->method('has')->with('dummy-bus')->willReturn(true); |
| 234 | + $busLocator->method('get')->with('dummy-bus')->willReturn($bus); |
| 235 | + |
| 236 | + $logger = new class() implements LoggerInterface { |
| 237 | + use LoggerTrait; |
| 238 | + |
| 239 | + public array $logs = []; |
| 240 | + |
| 241 | + public function log(...$args): void |
| 242 | + { |
| 243 | + $this->logs[] = $args; |
| 244 | + } |
| 245 | + }; |
| 246 | + $command = new ConsumeMessagesCommand(new RoutableMessageBus($busLocator), $receiverLocator, new EventDispatcher(), $logger); |
| 247 | + |
| 248 | + $application = new Application(); |
| 249 | + $application->add($command); |
| 250 | + $tester = new CommandTester($application->get('messenger:consume')); |
| 251 | + $tester->execute([ |
| 252 | + 'receivers' => ['dummy-receiver'], |
| 253 | + '--memory-limit' => '1.5M', |
| 254 | + ]); |
| 255 | + |
| 256 | + $this->assertSame(0, $tester->getStatusCode()); |
| 257 | + $this->assertStringContainsString('[OK] Consuming messages from transport "dummy-receiver"', $tester->getDisplay()); |
| 258 | + $this->assertStringContainsString('The worker will automatically exit once it has exceeded 1.5M of memory', $tester->getDisplay()); |
| 259 | + |
| 260 | + $this->assertSame(1572864, $logger->logs[1][2]['limit']); |
| 261 | + } |
| 262 | + |
217 | 263 | /**
|
218 | 264 | * @dataProvider provideCompletionSuggestions
|
219 | 265 | */
|
|
0 commit comments