@@ -31,6 +31,40 @@ public function testConnectWillUseGivenHostAndGivenPort()
31
31
$ factory ->createConnection ('127.0.0.1:1234 ' );
32
32
}
33
33
34
+ public function testConnectWillUseGivenUserInfoAsDatabaseCredentialsAfterUrldecoding ()
35
+ {
36
+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' ))->getMock ();
37
+ $ connection ->expects ($ this ->once ())->method ('write ' )->with ($ this ->stringContains ("user! \0" ));
38
+
39
+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
40
+ $ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
41
+ $ connector ->expects ($ this ->once ())->method ('connect ' )->with ('127.0.0.1:3306 ' )->willReturn (\React \Promise \resolve ($ connection ));
42
+
43
+ $ factory = new Factory ($ loop , $ connector );
44
+ $ promise =
$ factory->
createConnection (
'user%[email protected] ' );
45
+
46
+ $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
47
+
48
+ $ connection ->emit ('data ' , array ("\x33\0\0\0" . "\x0a" . "mysql \0" . str_repeat ("\0" , 44 )));
49
+ }
50
+
51
+ public function testConnectWillUseGivenPathAsDatabaseNameAfterUrldecoding ()
52
+ {
53
+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' ))->getMock ();
54
+ $ connection ->expects ($ this ->once ())->method ('write ' )->with ($ this ->stringContains ("test database \0" ));
55
+
56
+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
57
+ $ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
58
+ $ connector ->expects ($ this ->once ())->method ('connect ' )->with ('127.0.0.1:3306 ' )->willReturn (\React \Promise \resolve ($ connection ));
59
+
60
+ $ factory = new Factory ($ loop , $ connector );
61
+ $ promise = $ factory ->createConnection ('127.0.0.1/test%20database ' );
62
+
63
+ $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableNever ());
64
+
65
+ $ connection ->emit ('data ' , array ("\x33\0\0\0" . "\x0a" . "mysql \0" . str_repeat ("\0" , 44 )));
66
+ }
67
+
34
68
public function testConnectWithInvalidUriWillRejectWithoutConnecting ()
35
69
{
36
70
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
0 commit comments