@@ -40,6 +40,12 @@ public function testStatusCode()
4040 $ flattened = FlattenException::create (new \RuntimeException ());
4141 $ this ->assertEquals ('500 ' , $ flattened ->getStatusCode ());
4242
43+ $ flattened = FlattenException::createFromThrowable (new \DivisionByZeroError (), 403 );
44+ $ this ->assertEquals ('403 ' , $ flattened ->getStatusCode ());
45+
46+ $ flattened = FlattenException::createFromThrowable (new \DivisionByZeroError ());
47+ $ this ->assertEquals ('500 ' , $ flattened ->getStatusCode ());
48+
4349 $ flattened = FlattenException::create (new NotFoundHttpException ());
4450 $ this ->assertEquals ('404 ' , $ flattened ->getStatusCode ());
4551
@@ -112,10 +118,10 @@ public function testHeadersForHttpException()
112118 /**
113119 * @dataProvider flattenDataProvider
114120 */
115- public function testFlattenHttpException (\Exception $ exception )
121+ public function testFlattenHttpException (\Throwable $ exception )
116122 {
117- $ flattened = FlattenException::create ($ exception );
118- $ flattened2 = FlattenException::create ($ exception );
123+ $ flattened = FlattenException::createFromThrowable ($ exception );
124+ $ flattened2 = FlattenException::createFromThrowable ($ exception );
119125
120126 $ flattened ->setPrevious ($ flattened2 );
121127
@@ -124,7 +130,7 @@ public function testFlattenHttpException(\Exception $exception)
124130 $ this ->assertInstanceOf ($ flattened ->getClass (), $ exception , 'The class is set to the class of the original exception ' );
125131 }
126132
127- public function testThrowable ()
133+ public function testWrappedThrowable ()
128134 {
129135 $ exception = new FatalThrowableError (new \DivisionByZeroError ('Ouch ' , 42 ));
130136 $ flattened = FlattenException::create ($ exception );
@@ -134,13 +140,23 @@ public function testThrowable()
134140 $ this ->assertSame ('DivisionByZeroError ' , $ flattened ->getClass (), 'The class is set to the class of the original error ' );
135141 }
136142
143+ public function testThrowable ()
144+ {
145+ $ error = new \DivisionByZeroError ('Ouch ' , 42 );
146+ $ flattened = FlattenException::createFromThrowable ($ error );
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+
137153 /**
138154 * @dataProvider flattenDataProvider
139155 */
140- public function testPrevious (\Exception $ exception )
156+ public function testPrevious (\Throwable $ exception )
141157 {
142- $ flattened = FlattenException::create ($ exception );
143- $ flattened2 = FlattenException::create ($ exception );
158+ $ flattened = FlattenException::createFromThrowable ($ exception );
159+ $ flattened2 = FlattenException::createFromThrowable ($ exception );
144160
145161 $ flattened ->setPrevious ($ flattened2 );
146162
@@ -163,33 +179,33 @@ public function testPreviousError()
163179 /**
164180 * @dataProvider flattenDataProvider
165181 */
166- public function testLine (\Exception $ exception )
182+ public function testLine (\Throwable $ exception )
167183 {
168- $ flattened = FlattenException::create ($ exception );
184+ $ flattened = FlattenException::createFromThrowable ($ exception );
169185 $ this ->assertSame ($ exception ->getLine (), $ flattened ->getLine ());
170186 }
171187
172188 /**
173189 * @dataProvider flattenDataProvider
174190 */
175- public function testFile (\Exception $ exception )
191+ public function testFile (\Throwable $ exception )
176192 {
177- $ flattened = FlattenException::create ($ exception );
193+ $ flattened = FlattenException::createFromThrowable ($ exception );
178194 $ this ->assertSame ($ exception ->getFile (), $ flattened ->getFile ());
179195 }
180196
181197 /**
182198 * @dataProvider flattenDataProvider
183199 */
184- public function testToArray (\Exception $ exception )
200+ public function testToArray (\Throwable $ exception, string $ expectedClass )
185201 {
186- $ flattened = FlattenException::create ($ exception );
202+ $ flattened = FlattenException::createFromThrowable ($ exception );
187203 $ flattened ->setTrace (array (), 'foo.php ' , 123 );
188204
189205 $ this ->assertEquals (array (
190206 array (
191207 'message ' => 'test ' ,
192- 'class ' => ' Exception ' ,
208+ 'class ' => $ expectedClass ,
193209 'trace ' => array (array (
194210 'namespace ' => '' , 'short_class ' => '' , 'class ' => '' , 'type ' => '' , 'function ' => '' , 'file ' => 'foo.php ' , 'line ' => 123 ,
195211 'args ' => array (),
@@ -198,10 +214,24 @@ public function testToArray(\Exception $exception)
198214 ), $ flattened ->toArray ());
199215 }
200216
217+ public function testCreate ()
218+ {
219+ $ exception = new NotFoundHttpException (
220+ 'test ' ,
221+ new \RuntimeException ('previous ' , 123 )
222+ );
223+
224+ $ this ->assertSame (
225+ FlattenException::createFromThrowable ($ exception )->toArray (),
226+ FlattenException::create ($ exception )->toArray ()
227+ );
228+ }
229+
201230 public function flattenDataProvider ()
202231 {
203232 return array (
204- array (new \Exception ('test ' , 123 )),
233+ array (new \Exception ('test ' , 123 ), 'Exception ' ),
234+ array (new \Error ('test ' , 123 ), 'Error ' ),
205235 );
206236 }
207237
0 commit comments