Skip to content

Commit 42e384d

Browse files
committed
[dbal] fix tests.
1 parent c202212 commit 42e384d

File tree

5 files changed

+30
-47
lines changed

5 files changed

+30
-47
lines changed

pkg/dbal/DbalConsumer.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ protected function receiveMessage(): ?DbalMessage
142142
if (empty($dbalMessage['time_to_live']) || ($dbalMessage['time_to_live'] / 1000) > microtime(true)) {
143143
return $this->convertMessage($dbalMessage);
144144
}
145+
146+
return null;
145147
} catch (\Exception $e) {
146148
$this->dbal->rollBack();
147149

@@ -186,7 +188,7 @@ private function fetchPrioritizedMessage(int $now): ?array
186188

187189
$sql = $query->getSQL().' '.$this->dbal->getDatabasePlatform()->getWriteLockSQL();
188190

189-
return $this->dbal->executeQuery(
191+
$result = $this->dbal->executeQuery(
190192
$sql,
191193
[
192194
'queue' => $this->queue->getQueueName(),
@@ -197,6 +199,8 @@ private function fetchPrioritizedMessage(int $now): ?array
197199
'delayedUntil' => Type::INTEGER,
198200
]
199201
)->fetch();
202+
203+
return $result ?: null;
200204
}
201205

202206
private function fetchMessage(int $now): ?array
@@ -214,7 +218,7 @@ private function fetchMessage(int $now): ?array
214218

215219
$sql = $query->getSQL().' '.$this->dbal->getDatabasePlatform()->getWriteLockSQL();
216220

217-
return $this->dbal->executeQuery(
221+
$result = $this->dbal->executeQuery(
218222
$sql,
219223
[
220224
'queue' => $this->queue->getQueueName(),
@@ -225,5 +229,7 @@ private function fetchMessage(int $now): ?array
225229
'delayedUntil' => Type::INTEGER,
226230
]
227231
)->fetch();
232+
233+
return $result ?: null;
228234
}
229235
}

pkg/dbal/DbalProducer.php

-9
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ public function send(PsrDestination $destination, PsrMessage $message): void
6969
}
7070

7171
$body = $message->getBody();
72-
if (is_scalar($body) || null === $body) {
73-
$body = (string) $body;
74-
} else {
75-
throw new InvalidMessageException(sprintf(
76-
'The message body must be a scalar or null. Got: %s',
77-
is_object($body) ? get_class($body) : gettype($body)
78-
));
79-
}
80-
8172
$uuid = Uuid::uuid1();
8273

8374
$publishedAt = null !== $message->getPublishedAt() ?

pkg/dbal/Tests/DbalConsumerTest.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -127,83 +127,83 @@ private function createContextMock()
127127

128128
class InvalidMessage implements PsrMessage
129129
{
130-
public function getBody()
130+
public function getBody(): string
131131
{
132132
}
133133

134-
public function setBody($body)
134+
public function setBody(string $body): void
135135
{
136136
}
137137

138-
public function setProperties(array $properties)
138+
public function setProperties(array $properties): void
139139
{
140140
}
141141

142-
public function getProperties()
142+
public function getProperties(): array
143143
{
144144
}
145145

146-
public function setProperty($name, $value)
146+
public function setProperty(string $name, $value): void
147147
{
148148
}
149149

150-
public function getProperty($name, $default = null)
150+
public function getProperty(string $name, $default = null)
151151
{
152152
}
153153

154-
public function setHeaders(array $headers)
154+
public function setHeaders(array $headers): void
155155
{
156156
}
157157

158-
public function getHeaders()
158+
public function getHeaders(): array
159159
{
160160
}
161161

162-
public function setHeader($name, $value)
162+
public function setHeader(string $name, $value): void
163163
{
164164
}
165165

166-
public function getHeader($name, $default = null)
166+
public function getHeader(string $name, $default = null)
167167
{
168168
}
169169

170-
public function setRedelivered($redelivered)
170+
public function setRedelivered(bool $redelivered): void
171171
{
172172
}
173173

174-
public function isRedelivered()
174+
public function isRedelivered(): bool
175175
{
176176
}
177177

178-
public function setCorrelationId($correlationId)
178+
public function setCorrelationId(string $correlationId = null): void
179179
{
180180
}
181181

182-
public function getCorrelationId()
182+
public function getCorrelationId(): ?string
183183
{
184184
}
185185

186-
public function setMessageId($messageId)
186+
public function setMessageId(string $messageId = null): void
187187
{
188188
}
189189

190-
public function getMessageId()
190+
public function getMessageId(): ?string
191191
{
192192
}
193193

194-
public function getTimestamp()
194+
public function getTimestamp(): ?int
195195
{
196196
}
197197

198-
public function setTimestamp($timestamp)
198+
public function setTimestamp(int $timestamp = null): void
199199
{
200200
}
201201

202-
public function setReplyTo($replyTo)
202+
public function setReplyTo(string $replyTo = null): void
203203
{
204204
}
205205

206-
public function getReplyTo()
206+
public function getReplyTo(): ?string
207207
{
208208
}
209209
}

pkg/dbal/Tests/DbalContextTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Interop\Queue\InvalidDestinationException;
1313
use Interop\Queue\PsrContext;
1414
use Interop\Queue\PsrDestination;
15+
use Interop\Queue\TemporaryQueueNotSupportedException;
1516

1617
class DbalContextTest extends \PHPUnit_Framework_TestCase
1718
{
@@ -139,8 +140,7 @@ public function testShouldThrowBadMethodCallExceptionOncreateTemporaryQueueCall(
139140
{
140141
$context = new DbalContext($connection = $this->createConnectionMock());
141142

142-
$this->expectException(\BadMethodCallException::class);
143-
$this->expectExceptionMessage('Dbal transport does not support temporary queues');
143+
$this->expectException(TemporaryQueueNotSupportedException::class);
144144

145145
$context->createTemporaryQueue();
146146
}

pkg/dbal/Tests/DbalProducerTest.php

-14
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace Enqueue\Dbal\Tests;
44

55
use Enqueue\Dbal\DbalContext;
6-
use Enqueue\Dbal\DbalDestination;
76
use Enqueue\Dbal\DbalMessage;
87
use Enqueue\Dbal\DbalProducer;
98
use Enqueue\Test\ClassExtensionTrait;
109
use Interop\Queue\InvalidDestinationException;
11-
use Interop\Queue\InvalidMessageException;
1210
use Interop\Queue\PsrDestination;
1311
use Interop\Queue\PsrProducer;
1412

@@ -26,18 +24,6 @@ public function testCouldBeConstructedWithRequiredArguments()
2624
new DbalProducer($this->createContextMock());
2725
}
2826

29-
public function testShouldThrowIfBodyOfInvalidType()
30-
{
31-
$this->expectException(InvalidMessageException::class);
32-
$this->expectExceptionMessage('The message body must be a scalar or null. Got: stdClass');
33-
34-
$producer = new DbalProducer($this->createContextMock());
35-
36-
$message = new DbalMessage(new \stdClass());
37-
38-
$producer->send(new DbalDestination(''), $message);
39-
}
40-
4127
public function testShouldThrowIfDestinationOfInvalidType()
4228
{
4329
$this->expectException(InvalidDestinationException::class);

0 commit comments

Comments
 (0)