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

Skip to content

Commit a9459c0

Browse files
committed
minor #30799 [Messenger] Fix the Doctrine transport to use the new interface (sroze)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] Fix the Doctrine transport to use the new interface | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29007 | License | MIT | Doc PR | ø Commits ------- 75e3355 Fix the Doctrine transport to use the new interface
2 parents 343d28e + 75e3355 commit a9459c0

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineTransportFactoryTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
1717
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport;
1818
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory;
19+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1920

2021
class DoctrineTransportFactoryTest extends TestCase
2122
{
2223
public function testSupports()
2324
{
2425
$factory = new DoctrineTransportFactory(
25-
$this->getMockBuilder(RegistryInterface::class)->getMock(),
26-
null,
27-
false
26+
$this->getMockBuilder(RegistryInterface::class)->getMock()
2827
);
2928

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

44-
$factory = new DoctrineTransportFactory(
45-
$registry,
46-
null
47-
);
43+
$factory = new DoctrineTransportFactory($registry);
44+
$serializer = $this->createMock(SerializerInterface::class);
4845

4946
$this->assertEquals(
50-
new DoctrineTransport(new Connection(Connection::buildConfiguration('doctrine://default'), $connection), null),
51-
$factory->createTransport('doctrine://default', [])
47+
new DoctrineTransport(new Connection(Connection::buildConfiguration('doctrine://default'), $connection), $serializer),
48+
$factory->createTransport('doctrine://default', [], $serializer)
5249
);
5350
}
5451

@@ -65,11 +62,7 @@ public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound()
6562
throw new \InvalidArgumentException();
6663
}));
6764

68-
$factory = new DoctrineTransportFactory(
69-
$registry,
70-
null
71-
);
72-
73-
$factory->createTransport('doctrine://default', []);
65+
$factory = new DoctrineTransportFactory($registry);
66+
$factory->createTransport('doctrine://default', [], $this->createMock(SerializerInterface::class));
7467
}
7568
}

src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransport.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Messenger\Transport\Doctrine;
1313

1414
use Symfony\Component\Messenger\Envelope;
15-
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
1615
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1716
use Symfony\Component\Messenger\Transport\SetupableTransportInterface;
1817
use Symfony\Component\Messenger\Transport\TransportInterface;
@@ -29,10 +28,10 @@ class DoctrineTransport implements TransportInterface, SetupableTransportInterfa
2928
private $receiver;
3029
private $sender;
3130

32-
public function __construct(Connection $connection, SerializerInterface $serializer = null)
31+
public function __construct(Connection $connection, SerializerInterface $serializer)
3332
{
3433
$this->connection = $connection;
35-
$this->serializer = $serializer ?? new PhpSerializer();
34+
$this->serializer = $serializer;
3635
}
3736

3837
/**

src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineTransportFactory.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Bridge\Doctrine\RegistryInterface;
1515
use Symfony\Component\Messenger\Exception\TransportException;
16-
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
1716
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1817
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
1918
use Symfony\Component\Messenger\Transport\TransportInterface;
@@ -26,15 +25,13 @@
2625
class DoctrineTransportFactory implements TransportFactoryInterface
2726
{
2827
private $registry;
29-
private $serializer;
3028

31-
public function __construct(RegistryInterface $registry, SerializerInterface $serializer = null)
29+
public function __construct(RegistryInterface $registry)
3230
{
3331
$this->registry = $registry;
34-
$this->serializer = $serializer ?? new PhpSerializer();
3532
}
3633

37-
public function createTransport(string $dsn, array $options): TransportInterface
34+
public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
3835
{
3936
$configuration = Connection::buildConfiguration($dsn, $options);
4037

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

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

49-
return new DoctrineTransport($connection, $this->serializer);
46+
return new DoctrineTransport($connection, $serializer);
5047
}
5148

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

0 commit comments

Comments
 (0)