Skip to content

Instantly share code, notes, and snippets.

@brennen
Created June 18, 2009 04:03
Show Gist options
  • Save brennen/131696 to your computer and use it in GitHub Desktop.
Save brennen/131696 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
/* This might be a good general approach to getting some real
value out of PHP's built-in error reporting, where it's
painful to turn it on for an entire application. Presently
living in a t/ directory, and called like so:
php t/error_test.php name_of_file_to_check.php
I've just written a couple of shell script wrappers to
call this on various files. Cheesy, but it's late and I'm tired.
You'll want Test.php, available here:
http://search.cpan.org/dist/Test.php/
*/
require 'Test.php';
plan(3);
# First command line param is what we'll require:
$check_file = $argv[1];
# Basic sanity check: Is there even a file there?
ok(file_exists($check_file), "$check_file exists...");
set_error_handler("spark_error_handler");
$spark_error_count = 0;
$spark_error_text = '';
// Maybe take care of bogus include errors?
// Dunno if this is a good idea...
set_include_path(get_include_path() . PATH_SEPARATOR . dirname($check_file));
// Wrap the require in an output buffer, since we don't want to display anything.
ob_start();
require_ok($check_file);
ob_end_clean();
ok($spark_error_count === 0, "No errors raised during execution of $check_file.");
if ($spark_error_count > 0)
diag("$spark_error_count errors raised.\n$spark_error_text");
exit(0);
// Accumulate a count of errors here:
function spark_error_handler ($errno, $errstr, $errfile, $errline, $errcontext)
{
global $spark_error_count, $spark_error_text;
$spark_error_text .= "$errno :: $errfile, line $errline :: $errstr\n";
$spark_error_count++;
};
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment