File tree 2 files changed +17
-2
lines changed
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -22,14 +22,16 @@ class Database
22
22
*/
23
23
protected $ pollInterval = 0.01 ;
24
24
25
- public function __construct ($ credentials = null )
25
+ public function __construct ($ credentials = null , $ loop = null )
26
26
{
27
27
if (!is_null ($ credentials ))
28
28
{
29
29
ConnectionFactory::init ($ credentials );
30
30
}
31
31
32
- $ this ->loop = Factory::create ();
32
+ // Use the provided loop, otherwise create one.
33
+ $ this ->loop = $ loop ?: Factory::create ();
34
+
33
35
$ this ->initLoop ();
34
36
35
37
$ this ->pool = new ConnectionPool ();
Original file line number Diff line number Diff line change 2
2
3
3
use DustinGraham \ReactMysql \Command ;
4
4
use DustinGraham \ReactMysql \Database ;
5
+ use React \EventLoop \Factory ;
5
6
6
7
class DatabaseTest extends TestCase
7
8
{
@@ -29,4 +30,16 @@ public function testForCoverage()
29
30
{
30
31
new Database ($ this ->getCredentials ());
31
32
}
33
+
34
+ public function testCustomLoop ()
35
+ {
36
+ // Custom Loop
37
+ $ loop = Factory::create ();
38
+ $ database = new Database ($ this ->getCredentials (), $ loop );
39
+ $ this ->assertSame ($ loop , $ database ->loop );
40
+
41
+ // No Custom Loop
42
+ $ databaseTwo = new Database ($ this ->getCredentials ());
43
+ $ this ->assertNotSame ($ loop , $ databaseTwo ->loop );
44
+ }
32
45
}
You can’t perform that action at this time.
0 commit comments