Example #1
0
 public function testAutoDisconnect()
 {
     $client = new Client(["user" => $this->getDbUser(), "database" => $this::getDbName(), "auto_disconnect" => true], $this->getLoop());
     $hello = null;
     $client->executeStatement("SELECT 'Hello' AS Hello")->subscribe(new CallbackObserver(function ($x) use(&$hello) {
         $this->assertNull($hello);
         $hello = $x;
     }, function ($e) {
         $this->fail("Got an error");
         $this->cancelCurrentTimeoutTimer();
         $this->stopLoop();
     }, function () {
         // wait a bit for things to close down
         $this->getLoop()->addTimer(0.1, function () {
             $this->cancelCurrentTimeoutTimer();
         });
     }));
     $this->runLoopWithTimeout(2);
     $this->assertEquals(0, $client->getConnectionCount());
     $this->assertEquals(['hello' => 'Hello'], $hello);
 }