11
11
12
12
namespace Symfony \Component \Messenger \Bridge \Doctrine \Tests \Transport ;
13
13
14
+ use Doctrine \DBAL \Driver ;
15
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
16
+ use Doctrine \DBAL \Platforms \PostgreSQLPlatform ;
14
17
use Doctrine \DBAL \Schema \AbstractSchemaManager ;
15
18
use Doctrine \DBAL \Schema \SchemaConfig ;
16
19
use Doctrine \Persistence \ConnectionRegistry ;
22
25
use Symfony \Component \Messenger \Exception \TransportException ;
23
26
use Symfony \Component \Messenger \Transport \Serialization \SerializerInterface ;
24
27
28
+ // Doctrine DBAL 2 compatibility
29
+ class_exists (\Doctrine \DBAL \Platforms \PostgreSqlPlatform::class);
30
+
25
31
class DoctrineTransportFactoryTest extends TestCase
26
32
{
27
33
public function testSupports ()
@@ -40,7 +46,15 @@ public function testCreateTransport()
40
46
$ schemaManager = $ this ->createMock (AbstractSchemaManager::class);
41
47
$ schemaConfig = $ this ->createMock (SchemaConfig::class);
42
48
$ schemaManager ->method ('createSchemaConfig ' )->willReturn ($ schemaConfig );
49
+
50
+ $ platform = $ this ->createMock (AbstractPlatform::class);
51
+ $ driver = $ this ->createMock (Driver::class);
52
+ $ driver ->expects ($ this ->once ())
53
+ ->method ('getDatabasePlatform ' )
54
+ ->willReturn ($ platform );
55
+
43
56
$ driverConnection ->method ('getSchemaManager ' )->willReturn ($ schemaManager );
57
+ $ driverConnection ->method ('getDriver ' )->willReturn ($ driver );
44
58
$ registry = $ this ->createMock (ConnectionRegistry::class);
45
59
46
60
$ registry ->expects ($ this ->once ())
@@ -56,6 +70,36 @@ public function testCreateTransport()
56
70
);
57
71
}
58
72
73
+ public function testCreateTransportNotifyWithPostgreSQLPlatform ()
74
+ {
75
+ $ driverConnection = $ this ->createMock (\Doctrine \DBAL \Connection::class);
76
+ $ schemaManager = $ this ->createMock (AbstractSchemaManager::class);
77
+ $ schemaConfig = $ this ->createMock (SchemaConfig::class);
78
+ $ schemaManager ->method ('createSchemaConfig ' )->willReturn ($ schemaConfig );
79
+
80
+ $ platform = $ this ->createMock (PostgreSQLPlatform::class);
81
+ $ driver = $ this ->createMock (Driver::class);
82
+ $ driver ->expects ($ this ->once ())
83
+ ->method ('getDatabasePlatform ' )
84
+ ->willReturn ($ platform );
85
+
86
+ $ driverConnection ->method ('getSchemaManager ' )->willReturn ($ schemaManager );
87
+ $ driverConnection ->method ('getDriver ' )->willReturn ($ driver );
88
+ $ registry = $ this ->createMock (ConnectionRegistry::class);
89
+
90
+ $ registry ->expects ($ this ->once ())
91
+ ->method ('getConnection ' )
92
+ ->willReturn ($ driverConnection );
93
+
94
+ $ factory = new DoctrineTransportFactory ($ registry );
95
+ $ serializer = $ this ->createMock (SerializerInterface::class);
96
+
97
+ $ this ->assertEquals (
98
+ new DoctrineTransport (new PostgreSqlConnection (PostgreSqlConnection::buildConfiguration ('doctrine://default ' ), $ driverConnection ), $ serializer ),
99
+ $ factory ->createTransport ('doctrine://default ' , [], $ serializer )
100
+ );
101
+ }
102
+
59
103
public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound ()
60
104
{
61
105
$ this ->expectException (TransportException::class);
0 commit comments