|
| 1 | +--TEST-- |
| 2 | +SplitCallbackIterator: Automatic smoke test (syntax, warnings, silence) |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | +$source = FALSE; |
| 6 | +$output = FALSE; |
| 7 | +$global_vars = array(); |
| 8 | +$cr_okay = FALSE; |
| 9 | + |
| 10 | +$source = file_get_contents("SplitCallbackIterator.php"); |
| 11 | +$lines = preg_split('/(\\x0a|\\x0d)+/', $source, 0, PREG_SPLIT_NO_EMPTY); |
| 12 | + |
| 13 | +if(preg_match('/\?>\s*$/', $source)) |
| 14 | + echo "SplitCallbackIterator has closing PHP tag at end\n"; |
| 15 | +else |
| 16 | + echo "SplitCallbackIterator is missing closing PHP tag at end\n"; |
| 17 | + |
| 18 | +if(file_exists(preg_replace("|[^/]+$|", "DOS_LINE_ENDINGS", "SplitCallbackIterator"))) { |
| 19 | + // Check for a consistent use of only CRLF if a "DOS_LINE_ENDINGS" marker |
| 20 | + // file exists in the containing folder |
| 21 | + $cr_okay = (preg_match_all('/\x0d\x0a/', $source) == preg_match_all('/\x0d/', $source) |
| 22 | + && preg_match_all('/\x0d\x0a/', $source) == preg_match_all('/\x0a/', $source)); |
| 23 | +} else { |
| 24 | + // Otherwise (normal situation) any CR character is treated as a bug |
| 25 | + $cr_okay = !preg_match('/\x0d/', $source); |
| 26 | +} |
| 27 | + |
| 28 | +if($cr_okay) |
| 29 | + echo "SplitCallbackIterator does not contain CR characters (or is consistent and in a folder marked with DOS_LINE_ENDINGS)\n"; |
| 30 | +else |
| 31 | + echo "SplitCallbackIterator does contain CR characters (and is not consistent or not in a folder marked with DOS_LINE_ENDINGS)\n"; |
| 32 | + |
| 33 | +$global_vars = array_keys($GLOBALS); |
| 34 | + |
| 35 | +ob_start(); |
| 36 | +require_once("SplitCallbackIterator.php"); |
| 37 | +$output = ob_get_contents(); |
| 38 | +ob_end_clean(); |
| 39 | +if($output === "") |
| 40 | + echo "Parsing of SplitCallbackIterator was silent\n"; |
| 41 | +else |
| 42 | + echo "Parsing of SplitCallbackIterator was not silent:\n$output"; |
| 43 | + |
| 44 | +// XXX: Currently, we have these exceptions of global variables being added... |
| 45 | +$global_vars = array_merge($global_vars, |
| 46 | + array('db_host', 'db_user', 'db_pass', 'db_name', |
| 47 | + 'memcache_hostconfig', |
| 48 | + 'global_script_resources_object')); |
| 49 | + |
| 50 | +if(count(array_diff(array_keys($GLOBALS), $global_vars)) == 0) |
| 51 | + print "SplitCallbackIterator did not pollute global variable space\n"; |
| 52 | +else |
| 53 | + print "SplitCallbackIterator added these variables to global space: ". |
| 54 | + implode(", ", array_diff(array_keys($GLOBALS), $global_vars)). |
| 55 | + "\n"; |
| 56 | + |
| 57 | +$class_defs = array(); |
| 58 | +foreach($lines as $line) { |
| 59 | + if(preg_match('/^\s*((abstract)\s+)?(class|interface|trait)\s+([a-z0-9_]+)/i', $line, $matches)) { |
| 60 | + $new_def = "$matches[3] $matches[4]"; |
| 61 | + if($matches[3] == 'class' |
| 62 | + && preg_match('/Exception$/', $matches[4])) { |
| 63 | + foreach($class_defs as $class_def) { |
| 64 | + if(preg_match("/^".preg_replace("/^(trait|interface)/", "class", $class_def)."/", $new_def)) |
| 65 | + continue 2; |
| 66 | + } |
| 67 | + } |
| 68 | + $class_defs[] = $new_def; |
| 69 | + } |
| 70 | +} |
| 71 | +if(count($class_defs) <= 1) { |
| 72 | + print "SplitCallbackIterator contains at most one class, interface, or trait (except for Exception classes)\n"; |
| 73 | +} else { |
| 74 | + print "SplitCallbackIterator contains multiple classes/interfaces/traits:\n"; |
| 75 | + print " ".implode("\n ", $class_defs)."\n"; |
| 76 | +} |
| 77 | +?> |
| 78 | +--EXPECT-- |
| 79 | +SplitCallbackIterator has closing PHP tag at end |
| 80 | +SplitCallbackIterator does not contain CR characters (or is consistent and in a folder marked with DOS_LINE_ENDINGS) |
| 81 | +Parsing of SplitCallbackIterator was silent |
| 82 | +SplitCallbackIterator did not pollute global variable space |
| 83 | +SplitCallbackIterator contains at most one class, interface, or trait (except for Exception classes) |
0 commit comments