Skip to content

Commit cdce6a3

Browse files
committed
bug #30805 [Messenger] bug fixes in Doctrine Transport (vincenttouzet)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] bug fixes in Doctrine Transport | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Just tested the new Doctrine transport and I've see 3 bugs so far : - [x] The message is not return by the transport - [x] The headers column must be of type TEXT and not just STRING - [ ] When using the PhpSerializer the message is truncated (PR: symfony/symfony#30814) The body in database looks like this : ``` O:36:"Symfony\Component\Messenger\Envelope":2:{s:44:" ``` The body given by the serializer is the following : ``` O:36:"Symfony\Component\Messenger\Envelope":2:{s:44:"Symfony\Component\Messenger\Envelopestamps";a:3:{s:49:"Symfony\Component\Messenger\Stamp\SerializerStamp";a:1:{i:0;O:49:"Symfony\Component\Messenger\Stamp\SerializerStamp":1:{s:58:"Symfony\Component\Messenger\Stamp\SerializerStampcontext";a:0:{}}}s:46:"Symfony\Component\Messenger\Stamp\BusNameStamp";a:1:{i:0;O:46:"Symfony\Component\Messenger\Stamp\BusNameStamp":1:{s:55:"Symfony\Component\Messenger\Stamp\BusNameStampbusName";s:21:"messenger.bus.default";}}s:43:"Symfony\Component\Messenger\Stamp\SentStamp";a:1:{i:0;O:43:"Symfony\Component\Messenger\Stamp\SentStamp":2:{s:56:"Symfony\Component\Messenger\Stamp\SentStampsenderClass";s:64:"Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport";s:56:"Symfony\Component\Messenger\Stamp\SentStampsenderAlias";s:16:"environment.stop";}}}s:45:"Symfony\Component\Messenger\Envelopemessage";O:34:"App\Message\EnvironmentStopMessage":1:{s:51:"App\Message\AbstractEnvironmentMessageenvironment";O:22:"App\Entity\Environment":5:{s:26:"App\Entity\Environmentid";s:36:"3bade252-b7a9-4188-82bd-3e68129e0da7";s:37:"App\Entity\EnvironmentrepositoryUrl";s:6:"string";s:30:"App\Entity\Environmentbranch";s:6:"string";s:33:"App\Entity\EnvironmenthostNames";a:1:{i:0;N;}s:27:"App\Entity\Environmentenv";a:2:{s:7:"APP_ENV";s:4:"prod";s:7:"APP_VAR";s:13:"example value";}}}} ``` Commits ------- 27466498d0 [Messenger] Fix get in Doctrine Transport
2 parents 1c40f7f + 98e04bb commit cdce6a3

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the symfony project.
5+
*
6+
* (c) Vincent Touzet <vincent.touzet@dotsafe.fr>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Messenger\Envelope;
16+
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
17+
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
18+
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport;
19+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
20+
use Symfony\Component\Messenger\Transport\TransportInterface;
21+
22+
class DoctrineTransportTest extends TestCase
23+
{
24+
public function testItIsATransport()
25+
{
26+
$transport = $this->getTransport();
27+
28+
$this->assertInstanceOf(TransportInterface::class, $transport);
29+
}
30+
31+
public function testReceivesMessages()
32+
{
33+
$transport = $this->getTransport(
34+
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
35+
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock()
36+
);
37+
38+
$decodedMessage = new DummyMessage('Decoded.');
39+
40+
$doctrineEnvelope = [
41+
'id' => '5',
42+
'body' => 'body',
43+
'headers' => ['my' => 'header'],
44+
];
45+
46+
$serializer->method('decode')->with(['body' => 'body', 'headers' => ['my' => 'header']])->willReturn(new Envelope($decodedMessage));
47+
$connection->method('get')->willReturn($doctrineEnvelope);
48+
49+
$envelopes = iterator_to_array($transport->get());
50+
$this->assertSame($decodedMessage, $envelopes[0]->getMessage());
51+
}
52+
53+
private function getTransport(SerializerInterface $serializer = null, Connection $connection = null)
54+
{
55+
$serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock();
56+
$connection = $connection ?: $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
57+
58+
return new DoctrineTransport($connection, $serializer);
59+
}
60+
}

Transport/Doctrine/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private function getSchema(): Schema
230230
->setNotnull(true);
231231
$table->addColumn('body', Type::TEXT)
232232
->setNotnull(true);
233-
$table->addColumn('headers', Type::STRING)
233+
$table->addColumn('headers', Type::TEXT)
234234
->setNotnull(true);
235235
$table->addColumn('queue_name', Type::STRING)
236236
->setNotnull(true);

Transport/Doctrine/DoctrineTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(Connection $connection, SerializerInterface $seriali
3939
*/
4040
public function get(): iterable
4141
{
42-
($this->receiver ?? $this->getReceiver())->get();
42+
return ($this->receiver ?? $this->getReceiver())->get();
4343
}
4444

4545
/**

0 commit comments

Comments
 (0)