Exemple #1
0
 public function testBools()
 {
     $client = new Client(["user" => $this::getDbUser(), "database" => $this::getDbName()]);
     $count = $client->query("SELECT * FROM thing");
     $trueCount = 0;
     $falseCount = 0;
     $nullCount = 0;
     $completes = false;
     $count->subscribe(new CallbackObserver(function ($x) use(&$trueCount, &$falseCount, &$nullCount) {
         if ($x['thing_in_stock'] === true) {
             $trueCount++;
         }
         if ($x['thing_in_stock'] === false) {
             $falseCount++;
         }
         if ($x['thing_in_stock'] === null) {
             $nullCount++;
         }
     }, function ($e) use($client) {
         $client->closeNow();
         $this->cancelCurrentTimeoutTimer();
         throw $e;
     }, function () use(&$completes, $client) {
         $completes = true;
         $client->closeNow();
         $this->cancelCurrentTimeoutTimer();
     }));
     $this->runLoopWithTimeout(2);
     $client->closeNow();
     $this->assertTrue($completes);
     $this->assertEquals(1, $trueCount);
     $this->assertEquals(1, $falseCount);
     $this->assertEquals(1, $nullCount);
 }
Exemple #2
0
 public function testNullPassword()
 {
     $client = new Client(["user" => $this::getDbUser(), "database" => $this::getDbName(), "password" => null]);
     $count = $client->query("SELECT count(*) AS the_count FROM thing");
     $theCount = -1;
     $count->subscribe(new CallbackObserver(function ($x) use(&$theCount) {
         $this->assertTrue($theCount == -1);
         $theCount = $x["the_count"];
     }, function ($e) use($client) {
         $client->closeNow();
         $this->cancelCurrentTimeoutTimer();
         $this->fail("onError");
     }, function () use($client) {
         $client->closeNow();
         $this->cancelCurrentTimeoutTimer();
     }));
     $this->runLoopWithTimeout(2);
     $this->assertEquals(3, $theCount);
 }
Exemple #3
0
 public function testSimpleQueryError()
 {
     $client = new Client(["user" => $this->getDbUser(), "database" => $this::getDbName()], $this->getLoop());
     $count = $client->query("SELECT count(*) abcdef AS the_count FROM thing WHERE thing_type = 'non-thing'");
     $theCount = -1;
     $count->subscribe(new CallbackObserver(function ($x) use($client) {
         $client->closeNow();
         $this->cancelCurrentTimeoutTimer();
         $this->fail("Should not get result");
     }, function ($e) use($client) {
         $client->closeNow();
         $this->cancelCurrentTimeoutTimer();
     }, function () use($client) {
         $client->closeNow();
         $this->cancelCurrentTimeoutTimer();
         $this->fail("Should not complete");
     }));
     $this->runLoopWithTimeout(2);
     $this->assertEquals(-1, $theCount);
 }