Skip to content

Commit

Permalink
Fix the Doctrine transport to use the new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sroze committed Mar 31, 2019
1 parent 343d28e commit 75e3355
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport;
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;

class DoctrineTransportFactoryTest extends TestCase
{
public function testSupports()
{
$factory = new DoctrineTransportFactory(
$this->getMockBuilder(RegistryInterface::class)->getMock(),
null,
false
$this->getMockBuilder(RegistryInterface::class)->getMock()
);

$this->assertTrue($factory->supports('doctrine://default', []));
Expand All @@ -41,14 +40,12 @@ public function testCreateTransport()
->method('getConnection')
->willReturn($connection);

$factory = new DoctrineTransportFactory(
$registry,
null
);
$factory = new DoctrineTransportFactory($registry);
$serializer = $this->createMock(SerializerInterface::class);

$this->assertEquals(
new DoctrineTransport(new Connection(Connection::buildConfiguration('doctrine://default'), $connection), null),
$factory->createTransport('doctrine://default', [])
new DoctrineTransport(new Connection(Connection::buildConfiguration('doctrine://default'), $connection), $serializer),
$factory->createTransport('doctrine://default', [], $serializer)
);
}

Expand All @@ -65,11 +62,7 @@ public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound()
throw new \InvalidArgumentException();
}));

$factory = new DoctrineTransportFactory(
$registry,
null
);

$factory->createTransport('doctrine://default', []);
$factory = new DoctrineTransportFactory($registry);
$factory->createTransport('doctrine://default', [], $this->createMock(SerializerInterface::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Messenger\Transport\Doctrine;

use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\SetupableTransportInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
Expand All @@ -29,10 +28,10 @@ class DoctrineTransport implements TransportInterface, SetupableTransportInterfa
private $receiver;
private $sender;

public function __construct(Connection $connection, SerializerInterface $serializer = null)
public function __construct(Connection $connection, SerializerInterface $serializer)
{
$this->connection = $connection;
$this->serializer = $serializer ?? new PhpSerializer();
$this->serializer = $serializer;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
Expand All @@ -26,15 +25,13 @@
class DoctrineTransportFactory implements TransportFactoryInterface
{
private $registry;
private $serializer;

public function __construct(RegistryInterface $registry, SerializerInterface $serializer = null)
public function __construct(RegistryInterface $registry)
{
$this->registry = $registry;
$this->serializer = $serializer ?? new PhpSerializer();
}

public function createTransport(string $dsn, array $options): TransportInterface
public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
$configuration = Connection::buildConfiguration($dsn, $options);

Expand All @@ -46,7 +43,7 @@ public function createTransport(string $dsn, array $options): TransportInterface

$connection = new Connection($configuration, $driverConnection);

return new DoctrineTransport($connection, $this->serializer);
return new DoctrineTransport($connection, $serializer);
}

public function supports(string $dsn, array $options): bool
Expand Down

0 comments on commit 75e3355

Please sign in to comment.