Repository navigation
Expand file tree
/
Copy pathErrorHandler.php
More file actions
73 lines (61 loc) · 1.89 KB
/
Copy pathErrorHandler.php
File metadata and controls
73 lines (61 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Codeception\Subscriber;
use Codeception\Events;
use Codeception\Event\SuiteEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ErrorHandler implements EventSubscriberInterface
{
use Shared\StaticEvents;
static $events = [
Events::SUITE_BEFORE => 'handle'
];
/**
* @var bool $stopped to keep shutdownHandler from possible looping.
*/
private static $stopped = false;
/**
* @var int stores bitmask for errors
*/
private $errorLevel = 'E_ALL & ~E_STRICT & ~E_DEPRECATED';
public function handle(SuiteEvent $e)
{
$settings = $e->getSettings();
if ($settings['error_level']) {
$this->errorLevel = eval("return {$settings['error_level']};");
}
error_reporting($this->errorLevel);
set_error_handler(array($this, 'errorHandler'));
register_shutdown_function(array($this, 'shutdownHandler'));
}
public function errorHandler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting
return false;
}
if (strpos($errstr, 'Cannot modify header information') !== false) {
return false;
}
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
}
public function shutdownHandler()
{
if (self::$stopped) {
return;
}
self::$stopped = true;
$error = error_get_last();
if (!is_array($error)) {
return;
}
if (error_reporting() === 0) {
return;
}
// not fatal
if ($error['type'] > 1) {
return;
}
echo "\n\n\nFATAL ERROR. TESTS NOT FINISHED.\n";
echo sprintf("%s \nin %s:%d\n", $error['message'], $error['file'], $error['line']);
}
}