Skip to content

Commit 69bef4c

Browse files
committed
move MessageTest.php to Unit
1 parent da403f7 commit 69bef4c

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/Adapter.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
final class Adapter implements AdapterInterface
1515
{
1616
public function __construct(
17-
private QueueProviderInterface $provider,
17+
private QueueProviderInterface $provider,
1818
private MessageSerializerInterface $serializer,
19-
private LoopInterface $loop,
20-
private int $timeout = 3
21-
) {
19+
private LoopInterface $loop,
20+
private int $timeout = 3
21+
)
22+
{
2223
}
2324

2425
public function runExisting(callable $handlerCallback): void
@@ -66,15 +67,18 @@ public function push(MessageInterface $message): MessageInterface
6667

6768
public function subscribe(callable $handlerCallback): void
6869
{
69-
while ($this->loop->canContinue()) {
70+
$continue = true;
71+
while ($continue) {
7072
$message = $this->reserve();
7173
if (null === $message) {
74+
$continue = $this->loop->canContinue();
7275
continue;
7376
}
7477

7578
$result = $handlerCallback($message);
76-
if ($result) {
77-
$this->provider->delete((string) $message->getId());
79+
$this->provider->delete((string) $message->getId());
80+
if (!$result) {
81+
$continue = false;
7882
}
7983
}
8084
}
@@ -99,4 +103,9 @@ private function reserve(): ?IdEnvelope
99103

100104
return $envelope;
101105
}
106+
107+
public function getChannelName(): string
108+
{
109+
return $this->provider->getChannelName();
110+
}
102111
}

src/QueueProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class QueueProvider implements QueueProviderInterface
1717
public function __construct(
1818
private \Redis $redis, //redis connection,
1919
private string $channelName = self::DEFAULT_CHANNEL_NAME
20-
) {
20+
)
21+
{
2122
}
2223

2324
/**
@@ -145,4 +146,9 @@ private function checkConnection(): void
145146
throw new NotConnectedRedisException('Redis is not connected.');
146147
}
147148
}
149+
150+
public function getChannelName(): string
151+
{
152+
return $this->channelName;
153+
}
148154
}

src/QueueProviderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public function existInWaiting(int $id): bool;
2020
public function existInReserved(int $id): bool;
2121

2222
public function withChannelName(string $channelName): self;
23+
24+
public function getChannelName(): string;
2325
}

0 commit comments

Comments
 (0)