File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -22,14 +22,16 @@ class Database
2222 */
2323 protected $ pollInterval = 0.01 ;
2424
25- public function __construct ($ credentials = null )
25+ public function __construct ($ credentials = null , $ loop = null )
2626 {
2727 if (!is_null ($ credentials ))
2828 {
2929 ConnectionFactory::init ($ credentials );
3030 }
3131
32- $ this ->loop = Factory::create ();
32+ // Use the provided loop, otherwise create one.
33+ $ this ->loop = $ loop ?: Factory::create ();
34+
3335 $ this ->initLoop ();
3436
3537 $ this ->pool = new ConnectionPool ();
Original file line number Diff line number Diff line change 22
33use DustinGraham \ReactMysql \Command ;
44use DustinGraham \ReactMysql \Database ;
5+ use React \EventLoop \Factory ;
56
67class DatabaseTest extends TestCase
78{
@@ -29,4 +30,16 @@ public function testForCoverage()
2930 {
3031 new Database ($ this ->getCredentials ());
3132 }
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+ }
3245}
You can’t perform that action at this time.
0 commit comments