@@ -40,6 +40,12 @@ public function testStatusCode()
40
40
$ flattened = FlattenException::create (new \RuntimeException ());
41
41
$ this ->assertEquals ('500 ' , $ flattened ->getStatusCode ());
42
42
43
+ $ flattened = FlattenException::create (new \DivisionByZeroError (), 403 );
44
+ $ this ->assertEquals ('403 ' , $ flattened ->getStatusCode ());
45
+
46
+ $ flattened = FlattenException::create (new \DivisionByZeroError ());
47
+ $ this ->assertEquals ('500 ' , $ flattened ->getStatusCode ());
48
+
43
49
$ flattened = FlattenException::create (new NotFoundHttpException ());
44
50
$ this ->assertEquals ('404 ' , $ flattened ->getStatusCode ());
45
51
@@ -112,7 +118,7 @@ public function testHeadersForHttpException()
112
118
/**
113
119
* @dataProvider flattenDataProvider
114
120
*/
115
- public function testFlattenHttpException (\Exception $ exception )
121
+ public function testFlattenHttpException (\Throwable $ exception )
116
122
{
117
123
$ flattened = FlattenException::create ($ exception );
118
124
$ flattened2 = FlattenException::create ($ exception );
@@ -124,7 +130,7 @@ public function testFlattenHttpException(\Exception $exception)
124
130
$ this ->assertInstanceOf ($ flattened ->getClass (), $ exception , 'The class is set to the class of the original exception ' );
125
131
}
126
132
127
- public function testThrowable ()
133
+ public function testWrappedThrowable ()
128
134
{
129
135
$ exception = new FatalThrowableError (new \DivisionByZeroError ('Ouch ' , 42 ));
130
136
$ flattened = FlattenException::create ($ exception );
@@ -134,10 +140,20 @@ public function testThrowable()
134
140
$ this ->assertSame ('DivisionByZeroError ' , $ flattened ->getClass (), 'The class is set to the class of the original error ' );
135
141
}
136
142
143
+ public function testThrowable ()
144
+ {
145
+ $ exception = new \DivisionByZeroError ('Ouch ' , 42 );
146
+ $ flattened = FlattenException::create ($ exception );
147
+
148
+ $ this ->assertSame ('Ouch ' , $ flattened ->getMessage (), 'The message is copied from the original error. ' );
149
+ $ this ->assertSame (42 , $ flattened ->getCode (), 'The code is copied from the original error. ' );
150
+ $ this ->assertSame ('DivisionByZeroError ' , $ flattened ->getClass (), 'The class is set to the class of the original error ' );
151
+ }
152
+
137
153
/**
138
154
* @dataProvider flattenDataProvider
139
155
*/
140
- public function testPrevious (\Exception $ exception )
156
+ public function testPrevious (\Throwable $ exception )
141
157
{
142
158
$ flattened = FlattenException::create ($ exception );
143
159
$ flattened2 = FlattenException::create ($ exception );
@@ -163,7 +179,7 @@ public function testPreviousError()
163
179
/**
164
180
* @dataProvider flattenDataProvider
165
181
*/
166
- public function testLine (\Exception $ exception )
182
+ public function testLine (\Throwable $ exception )
167
183
{
168
184
$ flattened = FlattenException::create ($ exception );
169
185
$ this ->assertSame ($ exception ->getLine (), $ flattened ->getLine ());
@@ -172,7 +188,7 @@ public function testLine(\Exception $exception)
172
188
/**
173
189
* @dataProvider flattenDataProvider
174
190
*/
175
- public function testFile (\Exception $ exception )
191
+ public function testFile (\Throwable $ exception )
176
192
{
177
193
$ flattened = FlattenException::create ($ exception );
178
194
$ this ->assertSame ($ exception ->getFile (), $ flattened ->getFile ());
@@ -181,15 +197,15 @@ public function testFile(\Exception $exception)
181
197
/**
182
198
* @dataProvider flattenDataProvider
183
199
*/
184
- public function testToArray (\Exception $ exception )
200
+ public function testToArray (\Throwable $ exception, string $ expectedClass )
185
201
{
186
202
$ flattened = FlattenException::create ($ exception );
187
203
$ flattened ->setTrace (array (), 'foo.php ' , 123 );
188
204
189
205
$ this ->assertEquals (array (
190
206
array (
191
207
'message ' => 'test ' ,
192
- 'class ' => ' Exception ' ,
208
+ 'class ' => $ expectedClass ,
193
209
'trace ' => array (array (
194
210
'namespace ' => '' , 'short_class ' => '' , 'class ' => '' , 'type ' => '' , 'function ' => '' , 'file ' => 'foo.php ' , 'line ' => 123 ,
195
211
'args ' => array (),
@@ -201,7 +217,8 @@ public function testToArray(\Exception $exception)
201
217
public function flattenDataProvider ()
202
218
{
203
219
return array (
204
- array (new \Exception ('test ' , 123 )),
220
+ array (new \Exception ('test ' , 123 ), 'Exception ' ),
221
+ array (new \Error ('test ' , 123 ), 'Error ' )
205
222
);
206
223
}
207
224
0 commit comments