Author: uwendel
Date: 2008-01-08 18:08:06 +0100 (Tue, 08 Jan 2008)
New Revision: 1197
Added:
trunk/tests/ext/pdo/pdo_set_attribute.phpt
Log:
As usual there's not much you can test on the general PDO level as
there is no documentation about general vs. driver specific features/differences/etc.
Therefore its a very basic test...
Added: trunk/tests/ext/pdo/pdo_set_attribute.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_set_attribute.phpt (rev 0)
+++ trunk/tests/ext/pdo/pdo_set_attribute.phpt 2008-01-08 17:08:06 UTC (rev 1197)
@@ -0,0 +1,85 @@
+--TEST--
+PDO Common: PDO->setAttribute()
+--SKIPIF--
+<?php # vim:ft=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();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) .
'/../../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+$db = PDOTest::factory();
+
+if (false !== ($tmp = @$db->setAttribute()))
+ printf("[001] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp,
true));
+
+if (false !== ($tmp = @$db->setAttribute(1)))
+ printf("[002] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp,
true));
+
+$tmp = array();
+if (false !== ($tmp = @$db->setAttribute($tmp, 1)))
+ printf("[003] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp,
true));
+
+$valid_attributes = array(
+ 'PDO::ATTR_CASE' => array(
+ 'value' => PDO::ATTR_CASE,
+ 'options' => array(PDO::CASE_LOWER, PDO::CASE_NATURAL, PDO::CASE_UPPER),
+ ),
+ 'PDO::ATTR_ERRMODE' => array(
+ 'value' => PDO::ATTR_ERRMODE,
+ 'options' => array(PDO::ERRMODE_SILENT, PDO::ERRMODE_WARNING,
PDO::ERRMODE_EXCEPTION),
+ ),
+ 'PDO::ATTR_ORACLE_NULLS' => array(
+ 'value' => PDO::ATTR_ORACLE_NULLS,
+ 'options' => array(PDO::NULL_NATURAL, PDO::NULL_EMPTY_STRING, PDO::NULL_TO_STRING),
+ ),
+ 'PDO::ATTR_STRINGIFY_FETCHED' => array(
+ 'value' => PDO::ATTR_STRINGIFY_FETCHES,
+ 'options' => array(true, false),
+ ),
+);
+
+// check for duplicates
+$attr = array();
+
+foreach ($valid_attributes as $attr_name => $attr_data) {
+ try {
+
+ printf("Testing %s...\n", $attr_name);
+
+ if (!isset($attr[$attr_data['value']]))
+ $attr[$attr_data['value']] = array($attr_name);
+ else
+ $attr[$attr_data['value']][] = $attr_name;
+
+ // we don't check the actual impact, all we do is try to set the attribute
+ foreach ($attr_data['options'] as $k => $option)
+ if (!is_bool($tmp = $db->setAttribute($attr_data['value'], $option)))
+ printf("[004] Setting %s = %d, expecting boolean got %s/%s\n",
+ $attr_name, $option, gettype($tmp), var_export($tmp, true));
+
+ } catch (PDOException $e) {
+ printf("[005] Unexpected exception for attribute %s, %s, [%s] %s\n",
+ $attr_name,
+ $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
+ }
+
+}
+
+if (count($attr) != count($valid_attributes)) {
+ printf("[006] Some attribute constants seem to share the same value. Dumping list");
+ var_dump($attr);
+}
+
+print "done!";
+?>
+--EXPECTF--
+Testing PDO::ATTR_CASE...
+Testing PDO::ATTR_ERRMODE...
+Testing PDO::ATTR_ORACLE_NULLS...
+Testing PDO::ATTR_STRINGIFY_FETCHED...
+done!
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r1197 - trunk/tests/ext/pdo | uwendel | 8 Jan |