pdo_mysql_get_attribute.phpt [plain text]
--TEST--
MySQL PDO->getAttribute()
--SKIPIF--
<?php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
$db = MySQLPDOTest::factory();
if (false == MySQLPDOTest::detect_transactional_mysql_engine($db))
die("skip Transactional engine not found");
?>
--FILE--
<?php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$db = MySQLPDOTest::factory();
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
function find_invalid_int($valid_options) {
do {
$invalid = mt_rand(-10000, 10000);
} while (in_array($invalid, $valid_options));
return $invalid;
}
function set_and_get($offset, $db, $attribute, $value) {
$value_type = gettype($value);
try {
if (!$db->setAttribute($attribute, $value)) {
printf("[%03d] Cannot set attribute '%s' to value '%s'\n",
$offset, $attribute, var_export($tmp, true));
return false;
}
if (gettype($value) != $value_type) {
printf("[%03d] Call to PDO::setAttribute(int attribute, mixed value) has changed the type of value from %s to %s, test will not work properly\n",
$offset, $value_type, gettype($value));
return false;
}
$tmp = $db->getAttribute($attribute);
if ($tmp !== $value) {
printf("[%03d] Attribute '%s' was set to '%s'/%s but getAttribute() reports '%s'/%s\n",
$offset, $attribute, var_export($value, true), gettype($value), var_export($tmp, true), gettype($tmp));
return false;
}
} catch (PDOException $e) {
printf("[%03d] %s, [%s] %s\n",
$offset, $e->getMessage(),
$db->errorCode(), implode(' ', $db->errorInfo()));
return false;
}
return true;
}
set_and_get(1, $db, PDO::ATTR_AUTOCOMMIT, 1);
print "done!";
?>
--CLEAN--
<?php
require dirname(__FILE__) . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--EXPECTF--
[001] Call to PDO::setAttribute(int attribute, mixed value) has changed the type of value from integer to boolean, test will not work properly
done!