Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ A changelog of all notable changes made to this library.
----------------------


1.0.0-Alpha-5 May 9, 2021
---------------------------
- *FIX*: [#28](https://github.com/nepster-web/php-simple-queue/issues/28) - set format for datetime


1.0.0-Alpha-4 April 7, 2021
---------------------------
- *ENH*: [#22](https://github.com/nepster-web/php-simple-queue/issues/22) - implementation [Context](./src/Context.php) for jobs and processors
Expand Down
6 changes: 3 additions & 3 deletions src/Transport/DoctrineDbalTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function fetchMessage(array $queues = []): ?Message
->andWhere('exact_time <= :nowTime')
->addOrderBy('priority', 'asc')
->addOrderBy('created_at', 'asc')
->setParameter('redeliveredAt', new DateTimeImmutable('now'), Types::DATETIME_IMMUTABLE)
->setParameter('redeliveredAt', (new DateTimeImmutable('now'))->format('Y-m-d H:i:s'), Types::STRING)
->setParameter('statuses', [Status::NEW, Status::REDELIVERED], Connection::PARAM_STR_ARRAY)
->setParameter('nowTime', $nowTime, Types::INTEGER)
->setMaxResults(1);
Expand Down Expand Up @@ -94,7 +94,7 @@ public function send(Message $message): void
'id' => Uuid::uuid4()->toString(),
'status' => $message->getStatus(),
'created_at' => $message->getCreatedAt()->format('Y-m-d H:i:s'),
'redelivered_at' => $message->getRedeliveredAt(),
'redelivered_at' => $message->getRedeliveredAt() ? $message->getRedeliveredAt()->format('Y-m-d H:i:s') : null,
'attempts' => $message->getAttempts(),
'queue' => $message->getQueue(),
'event' => $message->getEvent(),
Expand Down Expand Up @@ -123,7 +123,7 @@ public function send(Message $message): void
throw new TransportException('The message was not enqueued. Dbal did not confirm that the record is inserted.');
}
} catch (Throwable $e) {
throw new TransportException('The transport fails to send the message due to some internal error.', 0, $e);
throw new TransportException(sprintf('The transport fails to send the message: %s', $e->getMessage()), 0, $e);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/ProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function testFailureSendMessage(): void
$transport = new DoctrineDbalTransport($connection);

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

$producer = new Producer($transport);
$producer->send(new Message('my_queue', ''));
Expand Down
29 changes: 29 additions & 0 deletions tests/Transport/DoctrineDbalTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Simple\Queue\Status;
use Simple\Queue\Message;
use Simple\Queue\Priority;
use Doctrine\DBAL\Types\Types;
use Doctrine\DBAL\Schema\Table;
use PHPUnit\Framework\TestCase;
use Simple\Queue\QueueException;
Expand Down Expand Up @@ -55,6 +56,19 @@ public function testSend(): void
self::assertEquals(Status::NEW, $connection::$data['insert']['data']['status']);
self::assertEquals(Priority::DEFAULT, $connection::$data['insert']['data']['priority']);
self::assertEquals(date('Y-m-d H:i:s'), $connection::$data['insert']['data']['created_at']);

self::assertEquals(Types::GUID, $connection::$data['insert']['types']['id']);
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['status']);
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['created_at']);
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['redelivered_at']);
self::assertEquals(Types::SMALLINT, $connection::$data['insert']['types']['attempts']);
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['queue']);
self::assertEquals(Types::STRING, $connection::$data['insert']['types']['event']);
self::assertEquals(Types::BOOLEAN, $connection::$data['insert']['types']['is_job']);
self::assertEquals(Types::TEXT, $connection::$data['insert']['types']['body']);
self::assertEquals(Types::SMALLINT, $connection::$data['insert']['types']['priority']);
self::assertEquals(Types::TEXT, $connection::$data['insert']['types']['error']);
self::assertEquals(Types::BIGINT, $connection::$data['insert']['types']['exact_time']);
}

public function testFetchMessageWithQueueList(): void
Expand Down Expand Up @@ -176,4 +190,19 @@ public function testDeleteMessage(): void

self::assertEquals($message->getId(), $connection::$data['delete']['criteria']['id']);
}

public function testSendWithRedeliveredAt(): void
{
$connection = new MockConnection(null, [
'insert' => 1,
]);
$transport = new DoctrineDbalTransport($connection);

$redeliveredAt = new DateTimeImmutable('now');
$message = (new Message('my_queue', ''))->changeRedeliveredAt($redeliveredAt);

$transport->send($message);

self::assertEquals($redeliveredAt->format('Y-m-d H:i:s'), $connection::$data['insert']['data']['redelivered_at']);
}
}