List:Commits« Previous MessageNext Message »
From:uwendel Date:October 25 2007 10:45am
Subject:PHP mysqlnd svn commit: r1146 - trunk/tests/ext/pdo
View as plain text  
Author: uwendel
Date: 2007-10-25 10:45:37 +0200 (Thu, 25 Oct 2007)
New Revision: 1146

Added:
   trunk/tests/ext/pdo/pdo_query_fetch_class_private.phpt
Log:
I don't think FETCH_CLASS should work with classes that 
have a private constructor. If the user can't instantiate 
such a class, why should PDO be able to do that? Maybe an
OO expect can explain that to me. I let the test fail
for now.


Added: trunk/tests/ext/pdo/pdo_query_fetch_class_private.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_query_fetch_class_private.phpt	2007-10-24 16:04:38 UTC (rev
1145)
+++ trunk/tests/ext/pdo/pdo_query_fetch_class_private.phpt	2007-10-25 08:45:37 UTC (rev
1146)
@@ -0,0 +1,51 @@
+--TEST--
+PDO Common: PDO->query(..., PDO::FETCH_CLASS) - private
+--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 {
+
+	$select = 'SELECT id, val FROM test ORDER BY id ASC';
+
+	class fetch_class_private_members {
+		private $id = 0;
+		private $val = 0;
+	}
+	$stmt = $db->query($select, PDO::FETCH_CLASS, 'fetch_class_private_members');
+
+	class fetch_class_private_constructor {
+		private function __construct() {
+		}
+		public static function factory() {
+			return new fetch_class_private_constructor();
+		}
+	}
+	$stmt = $db->query($select, PDO::FETCH_CLASS, 'fetch_class_private_constructor');
+	print "[TODO] PDO can instantiate the class, can we do it?\n";
+	$obj = new fetch_class_private_constructor();
+	print "[TODO] No, we can't. So, how come PDO can?\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->errorCode(), implode(' ', $db->errorInfo()));
+}
+print "done!";
+?>
+--EXPECTF--
+done!
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r1146 - trunk/tests/ext/pdouwendel25 Oct