| | 511 | |
|---|
| | 512 | /** |
|---|
| | 513 | * Error handler for the current test browser instance. |
|---|
| | 514 | * |
|---|
| | 515 | * @param mixed $errno Error number |
|---|
| | 516 | * @param string $errstr Error message |
|---|
| | 517 | * @param string $errfile Error file |
|---|
| | 518 | * @param mixed $errline Error line |
|---|
| | 519 | */ |
|---|
| | 520 | static public function handlePhpError($errno, $errstr, $errfile, $errline) |
|---|
| | 521 | { |
|---|
| | 522 | if (($errno & error_reporting()) == 0) |
|---|
| | 523 | { |
|---|
| | 524 | return; |
|---|
| | 525 | } |
|---|
| | 526 | |
|---|
| | 527 | $msg = sprintf('PHP send a "%%s" error at %s line %s (%s)', $errfile, $errline, $errstr); |
|---|
| | 528 | switch ($errno) |
|---|
| | 529 | { |
|---|
| | 530 | case E_WARNING: |
|---|
| | 531 | throw new Exception(sprintf($msg, 'warning')); |
|---|
| | 532 | break; |
|---|
| | 533 | case E_NOTICE: |
|---|
| | 534 | throw new Exception(sprintf($msg, 'notice')); |
|---|
| | 535 | break; |
|---|
| | 536 | case E_STRICT: |
|---|
| | 537 | throw new Exception(sprintf($msg, 'strict')); |
|---|
| | 538 | break; |
|---|
| | 539 | case E_RECOVERABLE_ERROR: |
|---|
| | 540 | throw new Exception(sprintf($msg, 'catchable')); |
|---|
| | 541 | break; |
|---|
| | 542 | } |
|---|
| | 543 | } |
|---|
| | 544 | |
|---|
| | 545 | /** |
|---|
| | 546 | * Exception handler for the current test browser instance. |
|---|
| | 547 | * |
|---|
| | 548 | * @param Exception $exception The exception |
|---|
| | 549 | */ |
|---|
| | 550 | function handleException(Exception $exception) |
|---|
| | 551 | { |
|---|
| | 552 | $this->test()->error(sprintf('%s: %s', get_class($exception), $exception->getMessage())); |
|---|
| | 553 | |
|---|
| | 554 | $traceData = $exception->getTrace(); |
|---|
| | 555 | array_unshift($traceData, array( |
|---|
| | 556 | 'function' => '', |
|---|
| | 557 | 'file' => $exception->getFile() != null ? $exception->getFile() : 'n/a', |
|---|
| | 558 | 'line' => $exception->getLine() != null ? $exception->getLine() : 'n/a', |
|---|
| | 559 | 'args' => array(), |
|---|
| | 560 | )); |
|---|
| | 561 | |
|---|
| | 562 | $traces = array(); |
|---|
| | 563 | $lineFormat = ' at %s%s%s() in %s line %s'; |
|---|
| | 564 | for ($i = 0, $count = count($traceData); $i < $count; $i++) |
|---|
| | 565 | { |
|---|
| | 566 | $line = isset($traceData[$i]['line']) ? $traceData[$i]['line'] : 'n/a'; |
|---|
| | 567 | $file = isset($traceData[$i]['file']) ? $traceData[$i]['file'] : 'n/a'; |
|---|
| | 568 | $args = isset($traceData[$i]['args']) ? $traceData[$i]['args'] : array(); |
|---|
| | 569 | $this->test()->error(sprintf($lineFormat, |
|---|
| | 570 | (isset($traceData[$i]['class']) ? $traceData[$i]['class'] : ''), |
|---|
| | 571 | (isset($traceData[$i]['type']) ? $traceData[$i]['type'] : ''), |
|---|
| | 572 | $traceData[$i]['function'], |
|---|
| | 573 | $file, |
|---|
| | 574 | $line |
|---|
| | 575 | )); |
|---|
| | 576 | } |
|---|
| | 577 | |
|---|
| | 578 | $this->test()->fail('An uncaught exception has been thrown.'); |
|---|
| | 579 | } |
|---|
| 508 | | |
|---|
| 509 | | if (!defined('E_RECOVERABLE_ERROR')) |
|---|
| 510 | | { |
|---|
| 511 | | define('E_RECOVERABLE_ERROR', 4096); |
|---|
| 512 | | } |
|---|
| 513 | | |
|---|
| 514 | | /** |
|---|
| 515 | | * Error handler for the current test browser instance. |
|---|
| 516 | | * |
|---|
| 517 | | * @param mixed $errno Error number |
|---|
| 518 | | * @param string $errstr Error message |
|---|
| 519 | | * @param string $errfile Error file |
|---|
| 520 | | * @param mixed $errline Error line |
|---|
| 521 | | */ |
|---|
| 522 | | function sfTestBrowserErrorHandler($errno, $errstr, $errfile, $errline) |
|---|
| 523 | | { |
|---|
| 524 | | if (($errno & error_reporting()) == 0) |
|---|
| 525 | | { |
|---|
| 526 | | return; |
|---|
| 527 | | } |
|---|
| 528 | | |
|---|
| 529 | | $msg = sprintf('PHP send a "%%s" error at %s line %s (%s)', $errfile, $errline, $errstr); |
|---|
| 530 | | switch ($errno) |
|---|
| 531 | | { |
|---|
| 532 | | case E_WARNING: |
|---|
| 533 | | throw new Exception(sprintf($msg, 'warning')); |
|---|
| 534 | | break; |
|---|
| 535 | | case E_NOTICE: |
|---|
| 536 | | throw new Exception(sprintf($msg, 'notice')); |
|---|
| 537 | | break; |
|---|
| 538 | | case E_STRICT: |
|---|
| 539 | | throw new Exception(sprintf($msg, 'strict')); |
|---|
| 540 | | break; |
|---|
| 541 | | case E_RECOVERABLE_ERROR: |
|---|
| 542 | | throw new Exception(sprintf($msg, 'catchable')); |
|---|
| 543 | | break; |
|---|
| 544 | | } |
|---|
| 545 | | } |
|---|
| 546 | | |
|---|
| 547 | | set_error_handler('sfTestBrowserErrorHandler'); |
|---|