Skip to content

Commit

Permalink
fix message finding with hex id in dbal transport
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Nov 14, 2020
1 parent 7984287 commit 4313ca1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Transport/Dbal/DbalReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public function all(int $limit = null): iterable
*/
public function find($id): ?Envelope
{
if (\preg_match('/^[0-9a-f]+$/i', $id)) {
$id = \hex2bin($id);
}

$deliveredMessage = $this->connection->createQueryBuilder()
->select('*')
->from($this->tableName)
Expand Down
22 changes: 22 additions & 0 deletions tests/Transport/Dbal/DbalTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,28 @@ public function testCreateTable(): void
$this->transport->createTable();
}

public function testFindWithHexId(): void
{
$connection = $this->connection->reveal();

$this->connection->getDatabasePlatform()->willReturn($this->prophesize(AbstractPlatform::class));
$this->connection->createQueryBuilder()
->will(function () use ($connection) { return new QueryBuilder($connection); });

$id = '0124dfeea3f56c';
$this->connection
->executeQuery('SELECT * FROM messenger WHERE id = :identifier LIMIT 1', [':identifier' => hex2bin($id)], [':identifier' => ParameterType::BINARY])
->willReturn(new ArrayStatement([
['id' => hex2bin($id), 'body' => '{}', 'headers' => '{"type":"stdClass"}'],
]));

$message = $this->transport->find('0124dfeea3f56c');
self::assertNotNull($message);

$stamp = $message->last(TransportMessageIdStamp::class);
self::assertEquals($id, $stamp->getId());
}

public function testReceive(): void
{
$this->connection->createQueryBuilder()
Expand Down

0 comments on commit 4313ca1

Please sign in to comment.