diff options
author | Ulf Wendel <uw@php.net> | 2007-08-09 10:16:24 +0000 |
---|---|---|
committer | Ulf Wendel <uw@php.net> | 2007-08-09 10:16:24 +0000 |
commit | a166bd39ac8d1cfb7cf95e862f036ef4d03dc983 (patch) | |
tree | 4eed3b07aed2ecc3f8a95d5f2b6707c9ff3a794e | |
parent | af91a4056af85e67f10a7242b2974e238b00d1f1 (diff) | |
download | php-git-a166bd39ac8d1cfb7cf95e862f036ef4d03dc983.tar.gz |
I forgot those files when merging mysqlnd SVN and HEAD. Only required by
tests that test experimental features and are skipped by default that's why
I missed them.
-rw-r--r-- | ext/mysqli/tests/local_infile_tools.inc | 111 | ||||
-rw-r--r-- | ext/mysqli/tests/reflection_tools.inc | 121 |
2 files changed, 232 insertions, 0 deletions
diff --git a/ext/mysqli/tests/local_infile_tools.inc b/ext/mysqli/tests/local_infile_tools.inc new file mode 100644 index 0000000000..d740b8253c --- /dev/null +++ b/ext/mysqli/tests/local_infile_tools.inc @@ -0,0 +1,111 @@ +<?php + /* Utility function for mysqli_set_local_infile*.phpt tests */ + function shutdown_clean($file) { + if ($file) { + unlink($file); + } + } + + function create_standard_csv($offset) { + // create a CVS file + $file = tempnam(sys_get_temp_dir(), 'mysqli_test'); + if (!$fp = fopen($file, 'w')) { + printf("[%03d + 1] Cannot create CVS file '%s'\n", $offset, $file); + return NULL; + } else { + /* Looks ugly? No, handy if you have crashes... */ + register_shutdown_function("shutdown_clean", $file); + } + + if (ini_get('unicode.semantics')) { + if (!fwrite($fp, (binary)"'97';'x';\n") || + !fwrite($fp, (binary)"'98';'y';\n") || + !fwrite($fp, (binary)"99;'z';\n")) { + printf("[%03d + 2] Cannot write CVS file '%s'\n", $offset, $file); + return NULL; + } + } else { + if (!fwrite($fp, "97;'x';\n") || + !fwrite($fp, "98;'y';\n") || + !fwrite($fp, "99;'z';\n")) { + printf("[%03d + 3] Cannot write CVS file '%s'\n", $offset, $file); + return NULL; + } + } + + fclose($fp); + + if (!chmod($file, 0644)) { + printf("[%03d + 4] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might not be able to read it\n", + $offset, $file); + return NULL; + } + return $file; + } + + function try_handler($offset, $link, $file, $handler, $expected = null) { + + if ('default' == $handler) { + mysqli_set_local_infile_default($link); + } else if (!mysqli_set_local_infile_handler($link, $handler)) { + printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler); + return false; + } + printf("Callback set to '%s'\n", $handler); + + if (!mysqli_query($link, sprintf("DELETE FROM test"))) { + printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1, mysqli_errno($link), mysqli_error($link)); + return false; + } + + if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' + INTO TABLE test + FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' + LINES TERMINATED BY '\n'", + mysqli_real_escape_string($link, $file)))) { + printf("[%03d] LOAD DATA failed, [%d] %s\n", + $offset + 2, + mysqli_errno($link), mysqli_error($link)); + } + + if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) { + printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link), mysqli_error($link)); + return false; + } + + if (!is_array($expected)) + return true; + + foreach ($expected as $k => $values) { + if (!$tmp = mysqli_fetch_assoc($res)) { + printf("[%03d/%d] [%d] '%s'\n", $offset + 4, $k, mysqli_errno($link), mysqli_error($link)); + return false; + } + if ($values['id'] != $tmp['id']) { + printf("[%03d/%d] Expecting %s got %s\n", + $offset + 5, $k, + $values['id'], $tmp['id']); + return false; + } + if ($values['label'] != $tmp['label']) { + printf("[%03d/%d] Expecting %s got %s\n", + $offset + 6, $k, + $values['label'], $tmp['label']); + return false; + } + } + + if ($res && $tmp = mysqli_fetch_assoc($res)) { + printf("[%03d] More results than expected!\n", $offset + 7); + do { + var_dump($tmp); + } while ($tmp = mysqli_fetch_assoc($res)); + return false; + } + + if ($res) + mysqli_free_result($res); + + return true; + } +?>
\ No newline at end of file diff --git a/ext/mysqli/tests/reflection_tools.inc b/ext/mysqli/tests/reflection_tools.inc new file mode 100644 index 0000000000..a96634b3c8 --- /dev/null +++ b/ext/mysqli/tests/reflection_tools.inc @@ -0,0 +1,121 @@ +<?php + function inspectClass($class) { + + /* not used: public ReflectionClass[] getInterfaces() */ + + printf("\nInspecting class '%s'\n", $class->getName()); + printf("isInternal: %s\n", ($class->isInternal()) ? 'yes' : 'no'); + printf("isUserDefined: %s\n", ($class->isUserDefined()) ? 'yes' : 'no'); + printf("isInstantiable: %s\n", ($class->isInstantiable()) ? 'yes' : 'no'); + printf("isInterface: %s\n", ($class->isInterface()) ? 'yes' : 'no'); + printf("isAbstract: %s\n", ($class->isAbstract()) ? 'yes' : 'no'); + printf("isFinal: %s\n", ($class->isFinal()) ? 'yes' : 'no'); + printf("isIteratable: %s\n", ($class->isIterateable()) ? 'yes' : 'no'); + printf("Modifiers: '%d'\n", $class->getModifiers()); + printf("Parent Class: '%s'\n", $class->getParentClass()); + printf("Extension: '%s'\n", $class->getExtensionName()); + + if ($method = $class->getConstructor()) + inspectMethod($method); + + if ($methods = $class->getMethods()) { + $tmp = array(); + foreach ($methods as $method) + $tmp[$method->getName()] = $method; + + ksort($tmp, SORT_STRING); + foreach ($tmp as $method) + inspectMethod($method); + } + + if ($properties = $class->getProperties()) { + $tmp = array(); + foreach ($properties as $prop) + $tmp[$prop->getName()] = $prop; + ksort($tmp, SORT_STRING); + foreach ($tmp as $prop) + inspectProperty($prop); + } + + + if ($properties = $class->getDefaultProperties()) { + ksort($properties, SORT_STRING); + foreach ($properties as $name => $v) + printf("Default property '%s'\n", $name); + } + + if ($properties = $class->getStaticProperties()) { + ksort($properties, SORT_STRING); + foreach ($properties as $name => $v) + printf("Static property '%s'\n", $name); + } + + if ($constants = $class->getConstants()) { + ksort($constants, SORT_STRING); + foreach ($constant as $name => $value) + printf("Constant '%s' = '%s'\n", $name, $value); + } + + } + + function inspectProperty(&$prop) { + + printf("\nInspecting property '%s'\n", $prop->getName()); + printf("isPublic: %s\n", ($prop->isPublic()) ? 'yes' : 'no'); + printf("isPrivate: %s\n", ($prop->isPrivate()) ? 'yes' : 'no'); + printf("isProtected: %s\n", ($prop->isProtected()) ? 'yes' : 'no'); + printf("isStatic: %s\n", ($prop->isStatic()) ? 'yes' : 'no'); + printf("isDefault: %s\n", ($prop->isDefault()) ? 'yes' : 'no'); + printf("Modifiers: %d\n", $prop->getModifiers()); + // printf("Value\n"); var_export($prop->getValue()); + + } + + function inspectMethod(&$method) { + + printf("\nInspecting method '%s'\n", $method->getName()); + printf("isFinal: %s\n", ($method->isFinal()) ? 'yes' : 'no'); + printf("isAbstract: %s\n", ($method->isAbstract()) ? 'yes' : 'no'); + printf("isPublic: %s\n", ($method->isPublic()) ? 'yes' : 'no'); + printf("isPrivate: %s\n", ($method->isPrivate()) ? 'yes' : 'no'); + printf("isProtected: %s\n", ($method->isProtected()) ? 'yes' : 'no'); + printf("isStatic: %s\n", ($method->isStatic()) ? 'yes' : 'no'); + printf("isConstructor: %s\n", ($method->isConstructor()) ? 'yes' : 'no'); + printf("isDestructor: %s\n", ($method->isDestructor()) ? 'yes' : 'no'); + printf("isInternal: %s\n", ($method->isInternal()) ? 'yes' : 'no'); + printf("isUserDefined: %s\n", ($method->isUserDefined()) ? 'yes' : 'no'); + printf("returnsReference: %s\n", ($method->returnsReference()) ? 'yes' : 'no'); + printf("Modifiers: %d\n", $method->getModifiers()); + printf("Number of Parameters: %d\n", $method->getNumberOfParameters()); + printf("Number of Required Parameters: %d\n", $method->getNumberOfRequiredParameters()); + + if ($params = $method->getParameters()) { + $tmp = array(); + foreach ($params as $k => $param) + $tmp[$param->getName()] = $param; + + ksort($tmp, SORT_STRING); + foreach ($tmp as $param) + inspectParameter($method, $param); + } + + if ($static = $method->getStaticVariables()) { + sort($static, SORT_STRING); + printf("Static variables: %s\n", implode('/', $static)); + } + + } + + function inspectParameter(&$method, &$param) { + + printf("\nInspecting parameter '%s' of method '%s'\n", + $param->getName(), $method->getName()); + printf("isArray: %s\n", ($param->isArray()) ? 'yes': 'no'); + printf("allowsNull: %s\n", ($param->allowsNull()) ? 'yes' : 'no'); + printf("isPassedByReference: %s\n", ($param->isPassedByReference()) ? 'yes' : 'no'); + printf("isOptional: %s\n", ($param->isOptional()) ? 'yes' : 'no'); + printf("isDefaultValueAvailable: %s\n", ($param->isDefaultValueAvailable()) ? 'yes' : 'no'); + // printf("getDefaultValue: %s\n", ($param->getDefaultValue()) ? 'yes' : 'no'); + + } +?>
\ No newline at end of file |