Permalink
Browse files

Error Handler: removing old definitions and refactoring tests to refl…

…ect the change.
  • Loading branch information...
1 parent 6348782 commit 3e71780eadfcd4e6be05160e73365a34d04fff76 @daschl daschl committed with nateabele Sep 23, 2011
Showing with 38 additions and 36 deletions.
  1. +0 −23 core/ErrorHandler.php
  2. +19 −13 tests/cases/core/ErrorHandlerTest.php
  3. +19 −0 tests/mocks/core/MockErrorHandler.php
View
@@ -32,13 +32,6 @@ class ErrorHandler extends \lithium\core\StaticObject {
protected static $_config = array();
/**
- * Error/exception handlers.
- *
- * @var array An array of closures that represent all invokable error/exception handlers.
- */
- protected static $_handlers = array();
-
- /**
* Types of checks available for sorting & parsing errors/exceptions.
* Default checks are for `code`, `stack` and `message`.
*
@@ -107,17 +100,6 @@ public static function __init() {
}
/**
- * Getter & setter of error/exception handlers.
- *
- * @param array $handlers If set, the passed `$handlers` array will be merged with
- * the already defined handlers in the `ErrorHandler` static class.
- * @return array Current set of handlers.
- */
- public static function handlers($handlers = array()) {
- return (static::$_handlers = $handlers + static::$_handlers);
- }
-
- /**
* Configure the `ErrorHandler`.
*
* @param array $config Configuration directives.
@@ -127,10 +109,6 @@ public static function config($config = array()) {
return (static::$_config = array_merge($config, static::$_config));
}
- public static function handler($name, $info) {
- return static::$_handlers[$name]($info);
- }
-
/**
* Register error and exception handlers.
*
@@ -209,7 +187,6 @@ public static function stop() {
public static function reset() {
static::$_config = array();
static::$_checks = array();
- static::$_handlers = array();
static::$_exceptionHandler = null;
static::__init();
}
@@ -12,6 +12,7 @@
use Exception;
use UnexpectedValueException;
use lithium\core\ErrorHandler;
+use lithium\tests\mocks\core\MockErrorHandler;
class ErrorHandlerTest extends \lithium\test\Unit {
@@ -95,19 +96,6 @@ public function testErrorCatching() {
$this->assertEqual(2, count($this->errors));
}
- public function testReset() {
- ErrorHandler::reset();
- $this->assertEqual(array(), ErrorHandler::handlers());
-
- $result = ErrorHandler::handlers(array('test' => function($error) { /* Do something */ }));
- $this->assertEqual(array('test'), array_keys($result));
- $this->assertTrue($result['test'] instanceof Closure);
- $this->assertEqual($result, ErrorHandler::handlers());
-
- ErrorHandler::reset();
- $this->assertEqual(array(), ErrorHandler::handlers());
- }
-
public function testApply() {
$subject = new ErrorHandlerTest();
ErrorHandler::apply(array($subject, 'throwException'), array(), function($details) {
@@ -139,6 +127,24 @@ public function testRun() {
$this->assertEqual(ErrorHandler::isRunning(), false);
}
+ public function testReset() {
+ $checks = MockErrorHandler::checks();
+
+ $defaultChecks = 4;
+ $this->assertEqual($defaultChecks, count($checks));
+ $this->assertTrue($checks['type'] instanceof Closure);
+
+ $checks = MockErrorHandler::checks(array('foo' => 'bar'));
+ $this->assertEqual(1, count($checks));
+ $this->assertFalse(isset($checks['type']));
+
+ MockErrorHandler::reset();
+
+ $checks = MockErrorHandler::checks();
+ $this->assertEqual($defaultChecks, count($checks));
+ $this->assertTrue($checks['type'] instanceof Closure);
+ }
+
public function testErrorTrapping() {
ErrorHandler::stop();
ErrorHandler::run(array('trapErrors' => true));
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2011, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace lithium\tests\mocks\core;
+
+class MockErrorHandler extends \lithium\core\ErrorHandler {
+
+ public static function checks($checks = array()) {
+ if($checks) {
+ static::$_checks = $checks;
+ }
+ return static::$_checks;
+ }
+}

0 comments on commit 3e71780

Please sign in to comment.