Beispiel #1
0
 /**
  * Overrides the default error handler
  *
  * @param boolean $enable  If `true` override the default error handler,
  *                         if `false` restore the default handler.
  * @param array   $options An options array. Available options are:
  *                         - 'handler': An error handler closure.
  *
  */
 protected function _errorHandler($enable, $options = [])
 {
     $defaults = ['handler' => null];
     $options += $defaults;
     if (!$enable) {
         return restore_error_handler();
     }
     $handler = function ($code, $message, $file, $line = 0, $args = []) {
         $trace = debug_backtrace();
         $trace = array_slice($trace, 1, count($trace));
         $message = "`" . Debugger::errorType($code) . "` {$message}";
         $code = 0;
         $exception = compact('code', 'message', 'file', 'line', 'trace');
         throw new PhpErrorException($exception);
     };
     $options['handler'] = $options['handler'] ?: $handler;
     set_error_handler($options['handler'], error_reporting());
 }
Beispiel #2
0
    describe("::loader()", function () {
        it("gets/sets a loader", function () {
            $loader = Stub::create();
            expect(Debugger::loader($loader))->toBe($loader);
        });
    });
    describe("::errorType()", function () {
        it("returns some reader-friendly error type string", function () {
            expect(Debugger::errorType(E_ERROR))->toBe('E_ERROR');
            expect(Debugger::errorType(E_WARNING))->toBe('E_WARNING');
            expect(Debugger::errorType(E_PARSE))->toBe('E_PARSE');
            expect(Debugger::errorType(E_NOTICE))->toBe('E_NOTICE');
            expect(Debugger::errorType(E_CORE_ERROR))->toBe('E_CORE_ERROR');
            expect(Debugger::errorType(E_CORE_WARNING))->toBe('E_CORE_WARNING');
            expect(Debugger::errorType(E_CORE_ERROR))->toBe('E_CORE_ERROR');
            expect(Debugger::errorType(E_COMPILE_ERROR))->toBe('E_COMPILE_ERROR');
            expect(Debugger::errorType(E_CORE_WARNING))->toBe('E_CORE_WARNING');
            expect(Debugger::errorType(E_COMPILE_WARNING))->toBe('E_COMPILE_WARNING');
            expect(Debugger::errorType(E_USER_ERROR))->toBe('E_USER_ERROR');
            expect(Debugger::errorType(E_USER_WARNING))->toBe('E_USER_WARNING');
            expect(Debugger::errorType(E_USER_NOTICE))->toBe('E_USER_NOTICE');
            expect(Debugger::errorType(E_STRICT))->toBe('E_STRICT');
            expect(Debugger::errorType(E_RECOVERABLE_ERROR))->toBe('E_RECOVERABLE_ERROR');
            expect(Debugger::errorType(E_DEPRECATED))->toBe('E_DEPRECATED');
            expect(Debugger::errorType(E_USER_DEPRECATED))->toBe('E_USER_DEPRECATED');
        });
        it("returns <INVALID> for undefined error type", function () {
            expect(Debugger::errorType(123456))->toBe('<INVALID>');
        });
    });
});