Thanks to visit codestin.com
Credit goes to github.com

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
[Messenger] Fix get in Doctrine Transport
  • Loading branch information
vincenttouzet committed Mar 31, 2019
commit 27466498d02b4ed1f5ab397d88cfce8b40f46116
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of the symfony project.
*
* (c) Vincent Touzet <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

class DoctrineTransportTest extends TestCase
{
public function testItIsATransport()
{
$transport = $this->getTransport();

$this->assertInstanceOf(TransportInterface::class, $transport);
}

public function testReceivesMessages()
{
$transport = $this->getTransport(
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock()
);

$decodedMessage = new DummyMessage('Decoded.');

$doctrineEnvelope = [
'id' => '5',
'body' => 'body',
'headers' => ['my' => 'header'],
];

$serializer->method('decode')->with(['body' => 'body', 'headers' => ['my' => 'header']])->willReturn(new Envelope($decodedMessage));
$connection->method('get')->willReturn($doctrineEnvelope);

$envelopes = iterator_to_array($transport->get());
$this->assertSame($decodedMessage, $envelopes[0]->getMessage());
}

private function getTransport(SerializerInterface $serializer = null, Connection $connection = null)
{
$serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock();
$connection = $connection ?: $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();

return new DoctrineTransport($connection, $serializer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private function getSchema(): Schema
->setNotnull(true);
$table->addColumn('body', Type::TEXT)
->setNotnull(true);
$table->addColumn('headers', Type::STRING)
$table->addColumn('headers', Type::TEXT)
->setNotnull(true);
$table->addColumn('queue_name', Type::STRING)
->setNotnull(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(Connection $connection, SerializerInterface $seriali
*/
public function get(): iterable
{
($this->receiver ?? $this->getReceiver())->get();
return ($this->receiver ?? $this->getReceiver())->get();
}

/**
Expand Down