@@ -23,7 +23,67 @@ public function testConnect(): void
23
23
'user ' => 'user ' ,
24
24
'password ' => 'password ' ,
25
25
'port ' => 3306 ,
26
- 'platform ' => $ this ->createMock (AbstractPlatform::class),
26
+ 'dama.keep_static ' => true ,
27
+ 'dama.connection_name ' => 'foo ' ,
28
+ 'some_closure ' => function (): void {},
29
+ ];
30
+
31
+ /** @var StaticConnection $connection1 */
32
+ $ connection1 = $ driver ->connect (['dama.connection_name ' => 'foo ' ] + $ params );
33
+ /** @var StaticConnection $connection2 */
34
+ $ connection2 = $ driver ->connect (['dama.connection_name ' => 'bar ' ] + $ params );
35
+
36
+ $ this ->assertInstanceOf (StaticConnection::class, $ connection1 );
37
+ $ this ->assertNotSame ($ connection1 ->getWrappedConnection (), $ connection2 ->getWrappedConnection ());
38
+
39
+ $ driver = new StaticDriver (new MockDriver ());
40
+
41
+ /** @var StaticConnection $connectionNew1 */
42
+ $ connectionNew1 = $ driver ->connect (['dama.connection_name ' => 'foo ' ] + $ params );
43
+ /** @var StaticConnection $connectionNew2 */
44
+ $ connectionNew2 = $ driver ->connect (['dama.connection_name ' => 'bar ' ] + $ params );
45
+
46
+ $ this ->assertSame ($ connection1 ->getWrappedConnection (), $ connectionNew1 ->getWrappedConnection ());
47
+ $ this ->assertSame ($ connection2 ->getWrappedConnection (), $ connectionNew2 ->getWrappedConnection ());
48
+
49
+ /** @var StaticConnection $connection1 */
50
+ $ connection1 = $ driver ->connect ($ params );
51
+ /** @var StaticConnection $connection2 */
52
+ $ connection2 = $ driver ->connect ($ params );
53
+ $ this ->assertSame ($ connection1 ->getWrappedConnection (), $ connection2 ->getWrappedConnection ());
54
+
55
+ /** @var StaticConnection $connection3 */
56
+ $ connection3 = $ driver ->connect (['host ' => 'bar ' ] + $ params );
57
+ $ this ->assertNotSame ($ connection1 ->getWrappedConnection (), $ connection3 ->getWrappedConnection ());
58
+ }
59
+
60
+ public function testConnectWithPlatform (): void
61
+ {
62
+ $ driver = new StaticDriver (new MockDriver ());
63
+
64
+ $ driver ::setKeepStaticConnections (true );
65
+
66
+ $ platform = $ this ->createMock (AbstractPlatform::class);
67
+ $ platform
68
+ ->expects (self ::exactly (7 ))
69
+ ->method ('supportsSavepoints ' )
70
+ ->willReturn (true )
71
+ ;
72
+ $ platform
73
+ ->expects (self ::exactly (7 ))
74
+ ->method ('supportsReleaseSavepoints ' )
75
+ ->willReturn (true )
76
+ ;
77
+
78
+ $ params = [
79
+ 'driver ' => 'pdo_mysql ' ,
80
+ 'charset ' => 'UTF8 ' ,
81
+ 'host ' => 'foo ' ,
82
+ 'dbname ' => 'doctrine_test_bundle ' ,
83
+ 'user ' => 'user ' ,
84
+ 'password ' => 'password ' ,
85
+ 'port ' => 3306 ,
86
+ 'platform ' => $ platform ,
27
87
'dama.keep_static ' => true ,
28
88
'dama.connection_name ' => 'foo ' ,
29
89
'some_closure ' => function (): void {},
0 commit comments