Skip to content

Commit 0a8460d

Browse files
Small improvements + rebase
1 parent 9d9867f commit 0a8460d

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Enhancers/MemoryLimitReceiverTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public function testReceiverLogsMemoryExceededWhenLoggerIsGiven()
101101

102102
$logger = $this->createMock(LoggerInterface::class);
103103
$logger->expects($this->once())->method('info')
104-
->with($this->equalTo('Receiver stopped due to memory limit exceeded.'));
104+
->with(
105+
$this->equalTo('Receiver stopped due to memory limit of {limit} exceeded'),
106+
$this->equalTo(array('limit' => 64 * 1024 * 1024))
107+
);
105108

106109
$memoryResolver = function () {
107110
return 70 * 1024 * 1024;

src/Symfony/Component/Messenger/Transport/Enhancers/MemoryLimitReceiver.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public function receive(callable $handler): void
4646
$memoryResolver = $this->memoryResolver;
4747
if ($memoryResolver() >= $this->memoryLimit) {
4848
$this->stop();
49-
if ($this->logger) {
50-
$this->logger->info('Receiver stopped due to memory limit exceeded.');
49+
if (null !== $this->logger) {
50+
$this->logger->info('Receiver stopped due to memory limit of {limit} exceeded', array('limit' => $this->memoryLimit));
5151
}
5252
}
5353
});
@@ -62,14 +62,14 @@ private function convertToOctets(string $size): int
6262
{
6363
if (!\preg_match('/^(\d+)([G|M|K]*)$/', $size, $matches)) {
6464
throw new \InvalidArgumentException('Invalid memory limit given.');
65-
} else {
66-
if ('G' == $matches[2]) {
67-
$size = $matches[1] * 1024 * 1024 * 1024;
68-
} elseif ('M' == $matches[2]) {
69-
$size = $matches[1] * 1024 * 1024;
70-
} elseif ('K' == $matches[2]) {
71-
$size = $matches[1] * 1024;
72-
}
65+
}
66+
67+
if ('G' == $matches[2]) {
68+
$size = $matches[1] * 1024 * 1024 * 1024;
69+
} elseif ('M' == $matches[2]) {
70+
$size = $matches[1] * 1024 * 1024;
71+
} elseif ('K' == $matches[2]) {
72+
$size = $matches[1] * 1024;
7373
}
7474

7575
return $size;

0 commit comments

Comments
 (0)