|
| 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 | +} |
0 commit comments