Permalink
Browse files

uses the PHP-suggested error-handling stuff for now, but we may want …

…a better long-term solution
  • Loading branch information...
1 parent 0309532 commit 9c5b2e0356aad7982c43340c30c145af20d68b70 @kentfredric committed Dec 22, 2010
Showing with 60 additions and 2 deletions.
  1. +40 −0 lib/DevKit/ErrorHandler.php
  2. +2 −2 lib/DevKit/Tester.php
  3. +18 −0 t/test-test.php.t
@@ -0,0 +1,40 @@
+<?php
+
+class DevKit_ErrorHandler {
+
+ public static function _exception_map() {
+ $array = array(
+ 1 => 'Error',
+ 2 => 'Warning',
+ 4 => 'Parse',
+ 8 => 'Notice',
+ 16 => 'Core_Error',
+ 32 => 'Core_Warning',
+ 64 => 'Compile_Error',
+ 128 => 'Compile_Warning',
+ 256 => 'User_Error',
+ 512 => 'User_Warning',
+ 1024 => 'User_Notice',
+ 2048 => 'Strict',
+ 4096 => 'Recoverable_Error',
+ 8192 => 'Deprecated',
+ 16384 => 'User_Deprecated',
+ );
+ return $array;
+ }
+
+ public static function _class_for_error( $code ){
+ $array = self::_exception_map();
+ return 'DevKit_Exception_PHP_' . $array[$code];
+ }
+
+ public function handle_error( $errno, $errstr, $errfile, $errline ){
+ throw new ErrorException( $errstr, 0, $errno, $errfile, $errline );
+ }
+
+ public static function setup(){
+ $instance = new self;
+ set_error_handler(array($instance, 'handle_error'));
+ }
+
+}
@@ -188,7 +188,7 @@ public function new_dies( $message, $class, array $args = array() ){
return $rval;
} catch ( Exception $e ){
$this->pass("Constructing $class should not succeed: $message");
- return null;
+ return $e;
}
return null;
}
@@ -225,7 +225,7 @@ public function method_call_dies ( $message, $object, $methodname, array $args )
return $rval;
} catch ( Exception $e ){
$this->pass("Calling method $methodname on $class should not succeed: $message");
- return null;
+ return $e;
}
return null;
}
View
@@ -11,6 +11,8 @@
require_once(dirname(__FILE__) . '/../lib/DevKit/Autoload.php');
$t = new DevKit_Tester();
+DevKit_ErrorHandler::setup();
+
$t->pass("A passing test");
# $t->fail("A failing test");
$t->is( 1 , "1", "String 1 is numeric 1");
@@ -24,8 +26,24 @@ class Dummy {
}
}
+class MoarDummy { }
+class MuchMoarDummy {
+ public function __construct( $mandatoryarg ) {
+ }
+}
+
$instance = $t->new_lives("Can make classes", 'Dummy', array() );
$rval = $t->method_call_lives('Can call methods', $instance, 'foo', array( ) );
$t->is( $rval , "Yes" , "value passing works");
+
+$notaninstance = $t->new_dies("Cant make class", 'I_DONT_EXIST', array() );
+$t->diag_exception( $notaninstance );
+$notaninstance = $t->new_dies("Cant make class", 'MoarDummy', array(1) );
+$t->diag_exception( $notaninstance );
+$notaninstance = $t->new_dies("Cant make class", 'MuchMoarDummy', array() );
+$t->diag_exception( $notaninstance );
+
+
+
$t->done_testing();

0 comments on commit 9c5b2e0

Please sign in to comment.