List:Commits« Previous MessageNext Message »
From:uwendel Date:March 3 2008 1:17pm
Subject:PHP mysqlnd svn commit: r1312 - trunk/tests/ext/pdo
View as plain text  
Author: uwendel
Date: 2008-03-03 14:17:05 +0100 (Mon, 03 Mar 2008)
New Revision: 1312

Added:
   trunk/tests/ext/pdo/pdo_stmt_errorinfo.phpt
Modified:
   trunk/tests/ext/pdo/pdo_stmt_errorcode.phpt
Log:
Simple PDOStatement::errorInfo() test. NOTE: its not portable, will pass only with
libmysql and fail e.g. with SQLite


Modified: trunk/tests/ext/pdo/pdo_stmt_errorcode.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_stmt_errorcode.phpt	2008-03-03 12:40:50 UTC (rev 1311)
+++ trunk/tests/ext/pdo/pdo_stmt_errorcode.phpt	2008-03-03 13:17:05 UTC (rev 1312)
@@ -1,5 +1,5 @@
 --TEST--
-PDO Common: PDOStatement->errorCount()
+PDO Common: PDOStatement->errorCode()
 --SKIPIF--
 <?php # vim:ft=php
 if (!extension_loaded('pdo')) die('skip');
@@ -21,7 +21,8 @@
 try {
 
 	$db = PDOTest::factory();
-	$stmt = $db->prepare('SELECT id FROM test WHERE id > ? ORDER BY id ASC');
+	$stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC');
+
 	if ('' !== ($tmp = $stmt->errorCode()))
 		printf("[002] Expecting empty string got %s\n", var_export($tmp, true));
 

Added: trunk/tests/ext/pdo/pdo_stmt_errorinfo.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_stmt_errorinfo.phpt	                        (rev 0)
+++ trunk/tests/ext/pdo/pdo_stmt_errorinfo.phpt	2008-03-03 13:17:05 UTC (rev 1312)
@@ -0,0 +1,83 @@
+--TEST--
+PDO Common: PDOStatement->errorInfo()
+--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();
+
+$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp
VARCHAR(10))');
+$db->exec('INSERT INTO test VALUES(1, \'A\', \'Group1\')');
+$db->exec('INSERT INTO test VALUES(2, \'B\', \'Group2\')');
+
+try {
+
+	$db = PDOTest::factory();
+	$stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC');
+
+	if (!is_array($tmp = $stmt->errorInfo()) || (count($tmp) != 3))
+		printf("[002] Expecting array with three elements got %s\n", var_export($tmp, true));
+
+	if (is_array($tmp) && (("" !== $tmp[0]) && '00000' !== $tmp[0]))
+		printf("[003] Expecting SQLSTATE to be either an empty string or '00000', got %s\n",
+			var_export($tmp[0], true));
+
+	if (false !== ($tmp = $stmt->errorInfo('too many arguments')))
+		printf("[003] Expecting boolean/false got %s\n", var_export($tmp, true));
+
+	$tmp = array();
+	if (false !== ($tmp = $stmt->errorInfo($tmp)))
+		printf("[004] Expecting boolean/false got %s\n", var_export($tmp, true));
+
+	$tmp = new stdClass();
+	if (false !== ($tmp = $stmt->errorInfo($tmp)))
+		printf("[005] Expecting boolean/false got %s\n", var_export($tmp, true));
+
+	$stmt = @$db->prepare('SELECT id FROM ihopeitdoesnotexist WHERE id > ? ORDER BY id
ASC');
+	@$stmt->execute();
+	if (!is_array($tmp = $stmt->errorInfo()) || (count($tmp) != 3))
+		printf("[006] Expecting array with three elements got %s\n", var_export($tmp, true));
+
+	if (is_array($tmp) && (("" === $tmp[0]) || '00000' === $tmp[0] ||
strlen($tmp[0]) != 5))
+		printf("[007] SQLSTATE should set, got %s\n",
+			var_export($tmp[0], true));
+
+	$stmt2 = $db->prepare('SELECT id FROM test WHERE id > ? ORDER BY id ASC');
+	if (!is_array($tmp = $stmt2->errorInfo()) || (count($tmp) != 3))
+		printf("[008] Expecting array with three elements got %s\n", var_export($tmp, true));
+
+	if (is_array($tmp) && (("" !== $tmp[0]) && '00000' !== $tmp[0]))
+		printf("[009] Expecting SQLSTATE to be either an empty string or '00000', got %s\n",
+			var_export($tmp[0], true));
+
+	if ($tmp === $stmt->errorInfo())
+		printf("[010] Two statement objects seem to influence each other, check manually\n");
+
+} catch (PDOException $e) {
+	// we should never get here, we use warnings, but never trust a system...s
+	printf("[001] %s, [%s} %s\n",
+		$e->getMessage(), $db->errorInfo(), implode(' ', $db->errorInfo()));
+}
+print "done!";
+?>
+--BUGFREE_EXPECTF--
+done!
+--EXPECTF--
+[002] Expecting array with three elements got array (
+  0 => '',
+)
+[006] Expecting array with three elements got array (
+  0 => '%s',
+)
+[008] Expecting array with three elements got array (
+  0 => '',
+)
+done!
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r1312 - trunk/tests/ext/pdouwendel3 Mar