Skip to content

Commit 05a6a9f

Browse files
authored
Merge pull request #29 from nepster-web/close_28
close #28
2 parents 8170d61 + afbb9c3 commit 05a6a9f

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ A changelog of all notable changes made to this library.
2020
----------------------
2121

2222

23+
1.0.0-Alpha-5 May 9, 2021
24+
---------------------------
25+
- *FIX*: [#28](https://github.com/nepster-web/php-simple-queue/issues/28) - set format for datetime
26+
27+
2328
1.0.0-Alpha-4 April 7, 2021
2429
---------------------------
2530
- *ENH*: [#22](https://github.com/nepster-web/php-simple-queue/issues/22) - implementation [Context](./src/Context.php) for jobs and processors

src/Transport/DoctrineDbalTransport.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function fetchMessage(array $queues = []): ?Message
5656
->andWhere('exact_time <= :nowTime')
5757
->addOrderBy('priority', 'asc')
5858
->addOrderBy('created_at', 'asc')
59-
->setParameter('redeliveredAt', new DateTimeImmutable('now'), Types::DATETIME_IMMUTABLE)
59+
->setParameter('redeliveredAt', (new DateTimeImmutable('now'))->format('Y-m-d H:i:s'), Types::STRING)
6060
->setParameter('statuses', [Status::NEW, Status::REDELIVERED], Connection::PARAM_STR_ARRAY)
6161
->setParameter('nowTime', $nowTime, Types::INTEGER)
6262
->setMaxResults(1);
@@ -94,7 +94,7 @@ public function send(Message $message): void
9494
'id' => Uuid::uuid4()->toString(),
9595
'status' => $message->getStatus(),
9696
'created_at' => $message->getCreatedAt()->format('Y-m-d H:i:s'),
97-
'redelivered_at' => $message->getRedeliveredAt(),
97+
'redelivered_at' => $message->getRedeliveredAt() ? $message->getRedeliveredAt()->format('Y-m-d H:i:s') : null,
9898
'attempts' => $message->getAttempts(),
9999
'queue' => $message->getQueue(),
100100
'event' => $message->getEvent(),
@@ -123,7 +123,7 @@ public function send(Message $message): void
123123
throw new TransportException('The message was not enqueued. Dbal did not confirm that the record is inserted.');
124124
}
125125
} catch (Throwable $e) {
126-
throw new TransportException('The transport fails to send the message due to some internal error.', 0, $e);
126+
throw new TransportException(sprintf('The transport fails to send the message: %s', $e->getMessage()), 0, $e);
127127
}
128128
}
129129

tests/ProducerTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public function testFailureSendMessage(): void
106106
$transport = new DoctrineDbalTransport($connection);
107107

108108
$this->expectException(TransportException::class);
109-
$this->expectExceptionMessage('The transport fails to send the message due to some internal error.');
109+
$previousMessage = 'The message was not enqueued. Dbal did not confirm that the record is inserted.';
110+
$this->expectExceptionMessage(sprintf('The transport fails to send the message: %s', $previousMessage));
110111

111112
$producer = new Producer($transport);
112113
$producer->send(new Message('my_queue', ''));

tests/Transport/DoctrineDbalTransportTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Simple\Queue\Status;
1010
use Simple\Queue\Message;
1111
use Simple\Queue\Priority;
12+
use Doctrine\DBAL\Types\Types;
1213
use Doctrine\DBAL\Schema\Table;
1314
use PHPUnit\Framework\TestCase;
1415
use Simple\Queue\QueueException;
@@ -55,6 +56,19 @@ public function testSend(): void
5556
self::assertEquals(Status::NEW, $connection::$data['insert']['data']['status']);
5657
self::assertEquals(Priority::DEFAULT, $connection::$data['insert']['data']['priority']);
5758
self::assertEquals(date('Y-m-d H:i:s'), $connection::$data['insert']['data']['created_at']);
59+
60+
self::assertEquals(Types::GUID, $connection::$data['insert']['types']['id']);
61+
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['status']);
62+
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['created_at']);
63+
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['redelivered_at']);
64+
self::assertEquals(Types::SMALLINT, $connection::$data['insert']['types']['attempts']);
65+
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['queue']);
66+
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['event']);
67+
self::assertEquals(Types::BOOLEAN, $connection::$data['insert']['types']['is_job']);
68+
self::assertEquals(Types::TEXT, $connection::$data['insert']['types']['body']);
69+
self::assertEquals(Types::SMALLINT, $connection::$data['insert']['types']['priority']);
70+
self::assertEquals(Types::TEXT, $connection::$data['insert']['types']['error']);
71+
self::assertEquals(Types::BIGINT, $connection::$data['insert']['types']['exact_time']);
5872
}
5973

6074
public function testFetchMessageWithQueueList(): void
@@ -176,4 +190,19 @@ public function testDeleteMessage(): void
176190

177191
self::assertEquals($message->getId(), $connection::$data['delete']['criteria']['id']);
178192
}
193+
194+
public function testSendWithRedeliveredAt(): void
195+
{
196+
$connection = new MockConnection(null, [
197+
'insert' => 1,
198+
]);
199+
$transport = new DoctrineDbalTransport($connection);
200+
201+
$redeliveredAt = new DateTimeImmutable('now');
202+
$message = (new Message('my_queue', ''))->changeRedeliveredAt($redeliveredAt);
203+
204+
$transport->send($message);
205+
206+
self::assertEquals($redeliveredAt->format('Y-m-d H:i:s'), $connection::$data['insert']['data']['redelivered_at']);
207+
}
179208
}

0 commit comments

Comments
 (0)