@@ -11,12 +11,19 @@ public function testSimpleSelect()
1111 $ connection = new \React \MySQL \Connection ($ loop , $ this ->getConnectionOptions ());
1212 $ connection ->connect (function () {});
1313
14- $ connection ->query ('select * from book ' , function ($ command , $ conn ) use ($ loop ) {
14+ // re-create test "book" table
15+ $ connection ->query ('DROP TABLE IF EXISTS book ' );
16+ $ connection ->query ($ this ->getDataTable ());
17+ $ connection ->query ("insert into book (`name`) values ('foo') " );
18+ $ connection ->query ("insert into book (`name`) values ('bar') " );
19+
20+ $ connection ->query ('select * from book ' , function ($ command , $ conn ) {
1521 $ this ->assertEquals (false , $ command ->hasError ());
16- $ this ->assertEquals (2 , count ( $ command ->resultRows ) );
22+ $ this ->assertCount (2 , $ command ->resultRows );
1723 $ this ->assertInstanceOf ('React\MySQL\Connection ' , $ conn );
18- $ loop ->stop ();
1924 });
25+
26+ $ connection ->close ();
2027 $ loop ->run ();
2128 }
2229
@@ -29,38 +36,49 @@ public function testInvalidSelect()
2936 $ connection = new \React \MySQL \Connection ($ loop , $ options );
3037 $ connection ->connect (function () {});
3138
32- $ connection ->query ('select * from invalid_table ' , function ($ command , $ conn ) use ($ loop , $ db ) {
39+ $ connection ->query ('select * from invalid_table ' , function ($ command , $ conn ) use ($ db ) {
3340 $ this ->assertEquals (true , $ command ->hasError ());
3441 $ this ->assertEquals ("Table ' $ db.invalid_table' doesn't exist " , $ command ->getError ()->getMessage ());
35-
36- $ loop ->stop ();
3742 });
43+
44+ $ connection ->close ();
3845 $ loop ->run ();
3946 }
4047
4148 public function testEventSelect ()
4249 {
50+ $ this ->expectOutputString ('result.result.results.end. ' );
4351 $ loop = \React \EventLoop \Factory::create ();
4452
4553 $ connection = new \React \MySQL \Connection ($ loop , $ this ->getConnectionOptions ());
4654 $ connection ->connect (function () {});
4755
56+ // re-create test "book" table
57+ $ connection ->query ('DROP TABLE IF EXISTS book ' );
58+ $ connection ->query ($ this ->getDataTable ());
59+ $ connection ->query ("insert into book (`name`) values ('foo') " );
60+ $ connection ->query ("insert into book (`name`) values ('bar') " );
61+
4862 $ command = $ connection ->query ('select * from book ' );
4963 $ command ->on ('results ' , function ($ results , $ command , $ conn ) {
5064 $ this ->assertEquals (2 , count ($ results ));
5165 $ this ->assertInstanceOf ('React\MySQL\Commands\QueryCommand ' , $ command );
5266 $ this ->assertInstanceOf ('React\MySQL\Connection ' , $ conn );
67+ echo 'results. ' ;
5368 });
5469 $ command ->on ('result ' , function ($ result , $ command , $ conn ) {
5570 $ this ->assertArrayHasKey ('id ' , $ result );
5671 $ this ->assertInstanceOf ('React\MySQL\Commands\QueryCommand ' , $ command );
5772 $ this ->assertInstanceOf ('React\MySQL\Connection ' , $ conn );
73+ echo 'result. ' ;
5874 })
59- ->on ('end ' , function ($ command , $ conn ) use ( $ loop ) {
75+ ->on ('end ' , function ($ command , $ conn ) {
6076 $ this ->assertInstanceOf ('React\MySQL\Commands\QueryCommand ' , $ command );
6177 $ this ->assertInstanceOf ('React\MySQL\Connection ' , $ conn );
62- $ loop -> stop () ;
78+ echo ' end. ' ;
6379 });
80+
81+ $ connection ->close ();
6482 $ loop ->run ();
6583 }
6684
@@ -70,13 +88,14 @@ public function testSelectAfterDelay()
7088
7189 $ connection = new \React \MySQL \Connection ($ loop , $ this ->getConnectionOptions ());
7290
73- $ callback = function () use ($ connection, $ loop ) {
74- $ connection ->query ('select 1+1 ' , function ($ command , $ conn ) use ( $ loop ) {
91+ $ callback = function () use ($ connection ) {
92+ $ connection ->query ('select 1+1 ' , function ($ command , $ conn ) {
7593 $ this ->assertEquals (false , $ command ->hasError ());
7694 $ this ->assertEquals ([['1+1 ' => 2 ]], $ command ->resultRows );
77- $ loop ->stop ();
7895 });
96+ $ connection ->close ();
7997 };
98+
8099 $ timeoutCb = function () use ($ loop ) {
81100 $ loop ->stop ();
82101 $ this ->fail ('Test timeout ' );
@@ -85,7 +104,11 @@ public function testSelectAfterDelay()
85104 $ connection ->connect (function ($ err , $ conn ) use ($ callback , $ loop , $ timeoutCb ) {
86105 $ this ->assertEquals (null , $ err );
87106 $ loop ->addTimer (0.1 , $ callback );
88- $ loop ->addTimer (1 , $ timeoutCb );
107+
108+ $ timeout = $ loop ->addTimer (1 , $ timeoutCb );
109+ $ conn ->on ('close ' , function () use ($ loop , $ timeout ) {
110+ $ loop ->cancelTimer ($ timeout );
111+ });
89112 });
90113
91114 $ loop ->run ();
0 commit comments