Skip to content

Commit

Permalink
Add PDO::checkLiveness test
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnorris committed Aug 14, 2020
1 parent a4103c9 commit bd81322
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ext/pdo/tests/pdo_039.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
PDOStatement::checkLiveness()
--SKIPIF--
<?php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (!strncasecmp(getenv('PDOTEST_DSN'), 'oci', strlen('oci'))) die('skip cannot set wait_timeout equivalent');

$conn = PDOTest::factory();

try {
$conn->checkLiveness();
} catch (PDOException $e) {
die("skip driver doesn't support checkLiveness: " . $e->getMessage());
}

?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';

$conn = PDOTest::factory();

switch ($conn->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'mysql':
$conn->exec("SET SESSION wait_timeout = 1");
break;
case 'pgsql':
$conn->exec("SET SESSION idle_in_transaction_session_timeout = 1000");
break;
}

var_dump($conn->checkLiveness());
sleep(2);
var_dump($conn->checkLiveness());

?>
--EXPECTF--
bool(true)
bool(false)

0 comments on commit bd81322

Please sign in to comment.