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); }
/** * see https://github.com/voryx/PgAsync/issues/10 */ public function testBoolParam() { $client = new Client(["user" => $this::getDbUser(), "database" => $this::getDbName()]); $args = [false, 1]; $upd = 'UPDATE test_bool_param SET b = $1 WHERE id = $2 RETURNING *'; $completes = false; $client->executeStatement($upd, $args)->subscribe(new \Rx\Observer\CallbackObserver(function ($row) { $this->assertEquals($row, ['id' => '1', 'b' => false]); }, function ($e) use($client) { $client->closeNow(); $this->cancelCurrentTimeoutTimer(); throw $e; }, function () use(&$completes, $client) { $completes = true; $client->closeNow(); $this->cancelCurrentTimeoutTimer(); })); $this->runLoopWithTimeout(2); $this->assertTrue($completes); }
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); }
public function testClientReusesIdleConnection() { $client = new Client(["user" => $this->getDbUser(), "database" => $this::getDbName()], $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 () { $this->cancelCurrentTimeoutTimer(); // We should wait here for a moment for the connection state to return to ready $this->getLoop()->addTimer(0.1, function () { $this->stopLoop(); }); })); $this->runLoopWithTimeout(2); $this->assertEquals(1, $client->getConnectionCount()); $this->assertEquals(['hello' => 'Hello'], $hello); $conn = $client->getIdleConnection(); $this->assertEquals(1, $client->getConnectionCount()); $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 () { $this->cancelCurrentTimeoutTimer(); // We should wait here for a moment for the connection state to return to ready $this->getLoop()->addTimer(0.1, function () { $this->stopLoop(); }); })); $this->runLoopWithTimeout(2); $this->assertEquals(1, $client->getConnectionCount()); $this->assertEquals(['hello' => 'Hello'], $hello); $connNew = $client->getIdleConnection(); $this->assertSame($conn, $connNew); $this->assertEquals(1, $client->getConnectionCount()); $client->closeNow(); }