|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Camspiers\LoggerBridge; |
|
4
|
|
|
|
|
5
|
|
|
use Camspiers\LoggerBridge\ErrorReporter\DebugErrorReporter; |
|
6
|
|
|
use Config; |
|
7
|
|
|
|
|
8
|
|
|
class DebugErrorReporterTest extends \PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testReportErrorNotLive() |
|
11
|
|
|
{ |
|
12
|
|
|
Config::inst()->update('SS_Backtrace', 'ignore_function_args', array()); |
|
13
|
|
|
|
|
14
|
|
|
$envMock = $this->getMock(__NAMESPACE__.'\EnvReporter\EnvReporter'); |
|
15
|
|
|
|
|
16
|
|
|
$envMock->expects($this->once()) |
|
17
|
|
|
->method('isLive') |
|
18
|
|
|
->will($this->returnValue(false)); |
|
19
|
|
|
|
|
20
|
|
|
$debugErrorReporter = new DebugErrorReporter($envMock); |
|
21
|
|
|
|
|
22
|
|
|
ob_start(); |
|
23
|
|
|
|
|
24
|
|
|
$debugErrorReporter->reportError( |
|
25
|
|
|
new \ErrorException( |
|
26
|
|
|
'Error message', |
|
27
|
|
|
E_USER_ERROR, |
|
28
|
|
|
0, |
|
29
|
|
|
'example-file.php', |
|
30
|
|
|
10 |
|
31
|
|
|
) |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$contents = ob_get_contents(); |
|
35
|
|
|
ob_end_clean(); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertContains( |
|
38
|
|
|
'[User Error]', |
|
39
|
|
|
$contents |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertContains( |
|
43
|
|
|
'Error message', |
|
44
|
|
|
$contents |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertContains( |
|
48
|
|
|
'Line 10 in example-file.php', |
|
49
|
|
|
$contents |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testReportErrorLive() |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
Config::inst()->update('Director', 'alternate_base_url', 'http://localhost'); |
|
56
|
|
|
define('BASE_URL', 'http://localhost/'); |
|
57
|
|
|
define('FRAMEWORK_DIR', 'framework'); |
|
58
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
|
59
|
|
|
$_SERVER['REQUEST_URI'] = '/'; |
|
60
|
|
|
|
|
61
|
|
|
Config::inst()->update('SS_Backtrace', 'ignore_function_args', array()); |
|
62
|
|
|
|
|
63
|
|
|
$envMock = $this->getMock(__NAMESPACE__.'\EnvReporter\EnvReporter'); |
|
64
|
|
|
|
|
65
|
|
|
$envMock->expects($this->once()) |
|
66
|
|
|
->method('isLive') |
|
67
|
|
|
->will($this->returnValue(true)); |
|
68
|
|
|
|
|
69
|
|
|
$debugErrorReporter = new DebugErrorReporter($envMock); |
|
70
|
|
|
|
|
71
|
|
|
ob_start(); |
|
72
|
|
|
|
|
73
|
|
|
$debugErrorReporter->reportError( |
|
74
|
|
|
new \ErrorException( |
|
75
|
|
|
'Error message', |
|
76
|
|
|
E_USER_ERROR, |
|
77
|
|
|
0, |
|
78
|
|
|
'example-file.php', |
|
79
|
|
|
10 |
|
80
|
|
|
) |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$contents = ob_get_contents(); |
|
84
|
|
|
ob_end_clean(); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals( |
|
87
|
|
|
<<<HTML |
|
88
|
|
|
<!DOCTYPE html><html><head><title>GET /</title><link rel="stylesheet" type="text/css" href="http://localhost/framework/css/debug.css" /></head><body><div class="info"><h1>Website Error</h1></div></body></html> |
|
89
|
|
|
HTML |
|
90
|
|
|
, |
|
91
|
|
|
$contents |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: