Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Application modulaire fonctionnelle !

Emmanuel ROY authored on 12/08/2019 15:10:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,388 +0,0 @@
1
-<?php
2
-
3
-/*
4
- * This file is part of the Symfony package.
5
- *
6
- * (c) Fabien Potencier <fabien@symfony.com>
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
-namespace Symfony\Component\Debug\Tests\Exception;
13
-
14
-use PHPUnit\Framework\TestCase;
15
-use Symfony\Component\Debug\Exception\FatalThrowableError;
16
-use Symfony\Component\Debug\Exception\FlattenException;
17
-use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
18
-use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
19
-use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
20
-use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
21
-use Symfony\Component\HttpKernel\Exception\GoneHttpException;
22
-use Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException;
23
-use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
24
-use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
25
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
26
-use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
27
-use Symfony\Component\HttpKernel\Exception\PreconditionRequiredHttpException;
28
-use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
29
-use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
30
-use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
31
-use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
32
-
33
-class FlattenExceptionTest extends TestCase
34
-{
35
-    public function testStatusCode()
36
-    {
37
-        $flattened = FlattenException::create(new \RuntimeException(), 403);
38
-        $this->assertEquals('403', $flattened->getStatusCode());
39
-
40
-        $flattened = FlattenException::create(new \RuntimeException());
41
-        $this->assertEquals('500', $flattened->getStatusCode());
42
-
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
-
49
-        $flattened = FlattenException::create(new NotFoundHttpException());
50
-        $this->assertEquals('404', $flattened->getStatusCode());
51
-
52
-        $flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"'));
53
-        $this->assertEquals('401', $flattened->getStatusCode());
54
-
55
-        $flattened = FlattenException::create(new BadRequestHttpException());
56
-        $this->assertEquals('400', $flattened->getStatusCode());
57
-
58
-        $flattened = FlattenException::create(new NotAcceptableHttpException());
59
-        $this->assertEquals('406', $flattened->getStatusCode());
60
-
61
-        $flattened = FlattenException::create(new ConflictHttpException());
62
-        $this->assertEquals('409', $flattened->getStatusCode());
63
-
64
-        $flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST']));
65
-        $this->assertEquals('405', $flattened->getStatusCode());
66
-
67
-        $flattened = FlattenException::create(new AccessDeniedHttpException());
68
-        $this->assertEquals('403', $flattened->getStatusCode());
69
-
70
-        $flattened = FlattenException::create(new GoneHttpException());
71
-        $this->assertEquals('410', $flattened->getStatusCode());
72
-
73
-        $flattened = FlattenException::create(new LengthRequiredHttpException());
74
-        $this->assertEquals('411', $flattened->getStatusCode());
75
-
76
-        $flattened = FlattenException::create(new PreconditionFailedHttpException());
77
-        $this->assertEquals('412', $flattened->getStatusCode());
78
-
79
-        $flattened = FlattenException::create(new PreconditionRequiredHttpException());
80
-        $this->assertEquals('428', $flattened->getStatusCode());
81
-
82
-        $flattened = FlattenException::create(new ServiceUnavailableHttpException());
83
-        $this->assertEquals('503', $flattened->getStatusCode());
84
-
85
-        $flattened = FlattenException::create(new TooManyRequestsHttpException());
86
-        $this->assertEquals('429', $flattened->getStatusCode());
87
-
88
-        $flattened = FlattenException::create(new UnsupportedMediaTypeHttpException());
89
-        $this->assertEquals('415', $flattened->getStatusCode());
90
-
91
-        if (class_exists(SuspiciousOperationException::class)) {
92
-            $flattened = FlattenException::create(new SuspiciousOperationException());
93
-            $this->assertEquals('400', $flattened->getStatusCode());
94
-        }
95
-    }
96
-
97
-    public function testHeadersForHttpException()
98
-    {
99
-        $flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST']));
100
-        $this->assertEquals(['Allow' => 'POST'], $flattened->getHeaders());
101
-
102
-        $flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"'));
103
-        $this->assertEquals(['WWW-Authenticate' => 'Basic realm="My Realm"'], $flattened->getHeaders());
104
-
105
-        $flattened = FlattenException::create(new ServiceUnavailableHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
106
-        $this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
107
-
108
-        $flattened = FlattenException::create(new ServiceUnavailableHttpException(120));
109
-        $this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
110
-
111
-        $flattened = FlattenException::create(new TooManyRequestsHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
112
-        $this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
113
-
114
-        $flattened = FlattenException::create(new TooManyRequestsHttpException(120));
115
-        $this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
116
-    }
117
-
118
-    /**
119
-     * @dataProvider flattenDataProvider
120
-     */
121
-    public function testFlattenHttpException(\Throwable $exception)
122
-    {
123
-        $flattened = FlattenException::createFromThrowable($exception);
124
-        $flattened2 = FlattenException::createFromThrowable($exception);
125
-
126
-        $flattened->setPrevious($flattened2);
127
-
128
-        $this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
129
-        $this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
130
-        $this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
131
-    }
132
-
133
-    public function testWrappedThrowable()
134
-    {
135
-        $exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
136
-        $flattened = FlattenException::create($exception);
137
-
138
-        $this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
139
-        $this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
140
-        $this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
141
-    }
142
-
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
-
153
-    /**
154
-     * @dataProvider flattenDataProvider
155
-     */
156
-    public function testPrevious(\Throwable $exception)
157
-    {
158
-        $flattened = FlattenException::createFromThrowable($exception);
159
-        $flattened2 = FlattenException::createFromThrowable($exception);
160
-
161
-        $flattened->setPrevious($flattened2);
162
-
163
-        $this->assertSame($flattened2, $flattened->getPrevious());
164
-
165
-        $this->assertSame([$flattened2], $flattened->getAllPrevious());
166
-    }
167
-
168
-    public function testPreviousError()
169
-    {
170
-        $exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));
171
-
172
-        $flattened = FlattenException::create($exception)->getPrevious();
173
-
174
-        $this->assertEquals($flattened->getMessage(), 'Oh noes!', 'The message is copied from the original exception.');
175
-        $this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
176
-        $this->assertEquals($flattened->getClass(), 'ParseError', 'The class is set to the class of the original exception');
177
-    }
178
-
179
-    /**
180
-     * @dataProvider flattenDataProvider
181
-     */
182
-    public function testLine(\Throwable $exception)
183
-    {
184
-        $flattened = FlattenException::createFromThrowable($exception);
185
-        $this->assertSame($exception->getLine(), $flattened->getLine());
186
-    }
187
-
188
-    /**
189
-     * @dataProvider flattenDataProvider
190
-     */
191
-    public function testFile(\Throwable $exception)
192
-    {
193
-        $flattened = FlattenException::createFromThrowable($exception);
194
-        $this->assertSame($exception->getFile(), $flattened->getFile());
195
-    }
196
-
197
-    /**
198
-     * @dataProvider flattenDataProvider
199
-     */
200
-    public function testToArray(\Throwable $exception, string $expectedClass)
201
-    {
202
-        $flattened = FlattenException::createFromThrowable($exception);
203
-        $flattened->setTrace([], 'foo.php', 123);
204
-
205
-        $this->assertEquals([
206
-            [
207
-                'message' => 'test',
208
-                'class' => $expectedClass,
209
-                'trace' => [[
210
-                    'namespace' => '', 'short_class' => '', 'class' => '', 'type' => '', 'function' => '', 'file' => 'foo.php', 'line' => 123,
211
-                    'args' => [],
212
-                ]],
213
-            ],
214
-        ], $flattened->toArray());
215
-    }
216
-
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
-
230
-    public function flattenDataProvider()
231
-    {
232
-        return [
233
-            [new \Exception('test', 123), 'Exception'],
234
-            [new \Error('test', 123), 'Error'],
235
-        ];
236
-    }
237
-
238
-    public function testArguments()
239
-    {
240
-        $dh = opendir(__DIR__);
241
-        $fh = tmpfile();
242
-
243
-        $incomplete = unserialize('O:14:"BogusTestClass":0:{}');
244
-
245
-        $exception = $this->createException([
246
-            (object) ['foo' => 1],
247
-            new NotFoundHttpException(),
248
-            $incomplete,
249
-            $dh,
250
-            $fh,
251
-            function () {},
252
-            [1, 2],
253
-            ['foo' => 123],
254
-            null,
255
-            true,
256
-            false,
257
-            0,
258
-            0.0,
259
-            '0',
260
-            '',
261
-            INF,
262
-            NAN,
263
-        ]);
264
-
265
-        $flattened = FlattenException::create($exception);
266
-        $trace = $flattened->getTrace();
267
-        $args = $trace[1]['args'];
268
-        $array = $args[0][1];
269
-
270
-        closedir($dh);
271
-        fclose($fh);
272
-
273
-        $i = 0;
274
-        $this->assertSame(['object', 'stdClass'], $array[$i++]);
275
-        $this->assertSame(['object', 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'], $array[$i++]);
276
-        $this->assertSame(['incomplete-object', 'BogusTestClass'], $array[$i++]);
277
-        $this->assertSame(['resource', 'stream'], $array[$i++]);
278
-        $this->assertSame(['resource', 'stream'], $array[$i++]);
279
-
280
-        $args = $array[$i++];
281
-        $this->assertSame($args[0], 'object');
282
-        $this->assertTrue('Closure' === $args[1] || is_subclass_of($args[1], '\Closure'), 'Expect object class name to be Closure or a subclass of Closure.');
283
-
284
-        $this->assertSame(['array', [['integer', 1], ['integer', 2]]], $array[$i++]);
285
-        $this->assertSame(['array', ['foo' => ['integer', 123]]], $array[$i++]);
286
-        $this->assertSame(['null', null], $array[$i++]);
287
-        $this->assertSame(['boolean', true], $array[$i++]);
288
-        $this->assertSame(['boolean', false], $array[$i++]);
289
-        $this->assertSame(['integer', 0], $array[$i++]);
290
-        $this->assertSame(['float', 0.0], $array[$i++]);
291
-        $this->assertSame(['string', '0'], $array[$i++]);
292
-        $this->assertSame(['string', ''], $array[$i++]);
293
-        $this->assertSame(['float', INF], $array[$i++]);
294
-
295
-        // assertEquals() does not like NAN values.
296
-        $this->assertEquals($array[$i][0], 'float');
297
-        $this->assertTrue(is_nan($array[$i++][1]));
298
-    }
299
-
300
-    public function testRecursionInArguments()
301
-    {
302
-        $a = null;
303
-        $a = ['foo', [2, &$a]];
304
-        $exception = $this->createException($a);
305
-
306
-        $flattened = FlattenException::create($exception);
307
-        $trace = $flattened->getTrace();
308
-        $this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
309
-    }
310
-
311
-    public function testTooBigArray()
312
-    {
313
-        $a = [];
314
-        for ($i = 0; $i < 20; ++$i) {
315
-            for ($j = 0; $j < 50; ++$j) {
316
-                for ($k = 0; $k < 10; ++$k) {
317
-                    $a[$i][$j][$k] = 'value';
318
-                }
319
-            }
320
-        }
321
-        $a[20] = 'value';
322
-        $a[21] = 'value1';
323
-        $exception = $this->createException($a);
324
-
325
-        $flattened = FlattenException::create($exception);
326
-        $trace = $flattened->getTrace();
327
-
328
-        $this->assertSame($trace[1]['args'][0], ['array', ['array', '*SKIPPED over 10000 entries*']]);
329
-
330
-        $serializeTrace = serialize($trace);
331
-
332
-        $this->assertContains('*SKIPPED over 10000 entries*', $serializeTrace);
333
-        $this->assertNotContains('*value1*', $serializeTrace);
334
-    }
335
-
336
-    public function testAnonymousClass()
337
-    {
338
-        $flattened = FlattenException::create(new class() extends \RuntimeException {
339
-        });
340
-
341
-        $this->assertSame('RuntimeException@anonymous', $flattened->getClass());
342
-
343
-        $flattened = FlattenException::create(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException {
344
-        }))));
345
-
346
-        $this->assertSame('Class "RuntimeException@anonymous" blah.', $flattened->getMessage());
347
-    }
348
-
349
-    public function testToStringEmptyMessage()
350
-    {
351
-        $exception = new \RuntimeException();
352
-
353
-        $flattened = FlattenException::create($exception);
354
-
355
-        $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
356
-        $this->assertSame($exception->__toString(), $flattened->getAsString());
357
-    }
358
-
359
-    public function testToString()
360
-    {
361
-        $test = function ($a, $b, $c, $d) {
362
-            return new \RuntimeException('This is a test message');
363
-        };
364
-
365
-        $exception = $test('foo123', 1, null, 1.5);
366
-
367
-        $flattened = FlattenException::create($exception);
368
-
369
-        $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
370
-        $this->assertSame($exception->__toString(), $flattened->getAsString());
371
-    }
372
-
373
-    public function testToStringParent()
374
-    {
375
-        $exception = new \LogicException('This is message 1');
376
-        $exception = new \RuntimeException('This is messsage 2', 500, $exception);
377
-
378
-        $flattened = FlattenException::create($exception);
379
-
380
-        $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
381
-        $this->assertSame($exception->__toString(), $flattened->getAsString());
382
-    }
383
-
384
-    private function createException($foo)
385
-    {
386
-        return new \Exception();
387
-    }
388
-}
Browse code

initial commit

Emmanuel ROY authored on 09/08/2019 08:39:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,388 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+namespace Symfony\Component\Debug\Tests\Exception;
13
+
14
+use PHPUnit\Framework\TestCase;
15
+use Symfony\Component\Debug\Exception\FatalThrowableError;
16
+use Symfony\Component\Debug\Exception\FlattenException;
17
+use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
18
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
19
+use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
20
+use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
21
+use Symfony\Component\HttpKernel\Exception\GoneHttpException;
22
+use Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException;
23
+use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
24
+use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
25
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
26
+use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
27
+use Symfony\Component\HttpKernel\Exception\PreconditionRequiredHttpException;
28
+use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
29
+use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
30
+use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
31
+use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
32
+
33
+class FlattenExceptionTest extends TestCase
34
+{
35
+    public function testStatusCode()
36
+    {
37
+        $flattened = FlattenException::create(new \RuntimeException(), 403);
38
+        $this->assertEquals('403', $flattened->getStatusCode());
39
+
40
+        $flattened = FlattenException::create(new \RuntimeException());
41
+        $this->assertEquals('500', $flattened->getStatusCode());
42
+
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
+
49
+        $flattened = FlattenException::create(new NotFoundHttpException());
50
+        $this->assertEquals('404', $flattened->getStatusCode());
51
+
52
+        $flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"'));
53
+        $this->assertEquals('401', $flattened->getStatusCode());
54
+
55
+        $flattened = FlattenException::create(new BadRequestHttpException());
56
+        $this->assertEquals('400', $flattened->getStatusCode());
57
+
58
+        $flattened = FlattenException::create(new NotAcceptableHttpException());
59
+        $this->assertEquals('406', $flattened->getStatusCode());
60
+
61
+        $flattened = FlattenException::create(new ConflictHttpException());
62
+        $this->assertEquals('409', $flattened->getStatusCode());
63
+
64
+        $flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST']));
65
+        $this->assertEquals('405', $flattened->getStatusCode());
66
+
67
+        $flattened = FlattenException::create(new AccessDeniedHttpException());
68
+        $this->assertEquals('403', $flattened->getStatusCode());
69
+
70
+        $flattened = FlattenException::create(new GoneHttpException());
71
+        $this->assertEquals('410', $flattened->getStatusCode());
72
+
73
+        $flattened = FlattenException::create(new LengthRequiredHttpException());
74
+        $this->assertEquals('411', $flattened->getStatusCode());
75
+
76
+        $flattened = FlattenException::create(new PreconditionFailedHttpException());
77
+        $this->assertEquals('412', $flattened->getStatusCode());
78
+
79
+        $flattened = FlattenException::create(new PreconditionRequiredHttpException());
80
+        $this->assertEquals('428', $flattened->getStatusCode());
81
+
82
+        $flattened = FlattenException::create(new ServiceUnavailableHttpException());
83
+        $this->assertEquals('503', $flattened->getStatusCode());
84
+
85
+        $flattened = FlattenException::create(new TooManyRequestsHttpException());
86
+        $this->assertEquals('429', $flattened->getStatusCode());
87
+
88
+        $flattened = FlattenException::create(new UnsupportedMediaTypeHttpException());
89
+        $this->assertEquals('415', $flattened->getStatusCode());
90
+
91
+        if (class_exists(SuspiciousOperationException::class)) {
92
+            $flattened = FlattenException::create(new SuspiciousOperationException());
93
+            $this->assertEquals('400', $flattened->getStatusCode());
94
+        }
95
+    }
96
+
97
+    public function testHeadersForHttpException()
98
+    {
99
+        $flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST']));
100
+        $this->assertEquals(['Allow' => 'POST'], $flattened->getHeaders());
101
+
102
+        $flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"'));
103
+        $this->assertEquals(['WWW-Authenticate' => 'Basic realm="My Realm"'], $flattened->getHeaders());
104
+
105
+        $flattened = FlattenException::create(new ServiceUnavailableHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
106
+        $this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
107
+
108
+        $flattened = FlattenException::create(new ServiceUnavailableHttpException(120));
109
+        $this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
110
+
111
+        $flattened = FlattenException::create(new TooManyRequestsHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
112
+        $this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
113
+
114
+        $flattened = FlattenException::create(new TooManyRequestsHttpException(120));
115
+        $this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
116
+    }
117
+
118
+    /**
119
+     * @dataProvider flattenDataProvider
120
+     */
121
+    public function testFlattenHttpException(\Throwable $exception)
122
+    {
123
+        $flattened = FlattenException::createFromThrowable($exception);
124
+        $flattened2 = FlattenException::createFromThrowable($exception);
125
+
126
+        $flattened->setPrevious($flattened2);
127
+
128
+        $this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
129
+        $this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
130
+        $this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
131
+    }
132
+
133
+    public function testWrappedThrowable()
134
+    {
135
+        $exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
136
+        $flattened = FlattenException::create($exception);
137
+
138
+        $this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
139
+        $this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
140
+        $this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
141
+    }
142
+
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
+
153
+    /**
154
+     * @dataProvider flattenDataProvider
155
+     */
156
+    public function testPrevious(\Throwable $exception)
157
+    {
158
+        $flattened = FlattenException::createFromThrowable($exception);
159
+        $flattened2 = FlattenException::createFromThrowable($exception);
160
+
161
+        $flattened->setPrevious($flattened2);
162
+
163
+        $this->assertSame($flattened2, $flattened->getPrevious());
164
+
165
+        $this->assertSame([$flattened2], $flattened->getAllPrevious());
166
+    }
167
+
168
+    public function testPreviousError()
169
+    {
170
+        $exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));
171
+
172
+        $flattened = FlattenException::create($exception)->getPrevious();
173
+
174
+        $this->assertEquals($flattened->getMessage(), 'Oh noes!', 'The message is copied from the original exception.');
175
+        $this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
176
+        $this->assertEquals($flattened->getClass(), 'ParseError', 'The class is set to the class of the original exception');
177
+    }
178
+
179
+    /**
180
+     * @dataProvider flattenDataProvider
181
+     */
182
+    public function testLine(\Throwable $exception)
183
+    {
184
+        $flattened = FlattenException::createFromThrowable($exception);
185
+        $this->assertSame($exception->getLine(), $flattened->getLine());
186
+    }
187
+
188
+    /**
189
+     * @dataProvider flattenDataProvider
190
+     */
191
+    public function testFile(\Throwable $exception)
192
+    {
193
+        $flattened = FlattenException::createFromThrowable($exception);
194
+        $this->assertSame($exception->getFile(), $flattened->getFile());
195
+    }
196
+
197
+    /**
198
+     * @dataProvider flattenDataProvider
199
+     */
200
+    public function testToArray(\Throwable $exception, string $expectedClass)
201
+    {
202
+        $flattened = FlattenException::createFromThrowable($exception);
203
+        $flattened->setTrace([], 'foo.php', 123);
204
+
205
+        $this->assertEquals([
206
+            [
207
+                'message' => 'test',
208
+                'class' => $expectedClass,
209
+                'trace' => [[
210
+                    'namespace' => '', 'short_class' => '', 'class' => '', 'type' => '', 'function' => '', 'file' => 'foo.php', 'line' => 123,
211
+                    'args' => [],
212
+                ]],
213
+            ],
214
+        ], $flattened->toArray());
215
+    }
216
+
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
+
230
+    public function flattenDataProvider()
231
+    {
232
+        return [
233
+            [new \Exception('test', 123), 'Exception'],
234
+            [new \Error('test', 123), 'Error'],
235
+        ];
236
+    }
237
+
238
+    public function testArguments()
239
+    {
240
+        $dh = opendir(__DIR__);
241
+        $fh = tmpfile();
242
+
243
+        $incomplete = unserialize('O:14:"BogusTestClass":0:{}');
244
+
245
+        $exception = $this->createException([
246
+            (object) ['foo' => 1],
247
+            new NotFoundHttpException(),
248
+            $incomplete,
249
+            $dh,
250
+            $fh,
251
+            function () {},
252
+            [1, 2],
253
+            ['foo' => 123],
254
+            null,
255
+            true,
256
+            false,
257
+            0,
258
+            0.0,
259
+            '0',
260
+            '',
261
+            INF,
262
+            NAN,
263
+        ]);
264
+
265
+        $flattened = FlattenException::create($exception);
266
+        $trace = $flattened->getTrace();
267
+        $args = $trace[1]['args'];
268
+        $array = $args[0][1];
269
+
270
+        closedir($dh);
271
+        fclose($fh);
272
+
273
+        $i = 0;
274
+        $this->assertSame(['object', 'stdClass'], $array[$i++]);
275
+        $this->assertSame(['object', 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'], $array[$i++]);
276
+        $this->assertSame(['incomplete-object', 'BogusTestClass'], $array[$i++]);
277
+        $this->assertSame(['resource', 'stream'], $array[$i++]);
278
+        $this->assertSame(['resource', 'stream'], $array[$i++]);
279
+
280
+        $args = $array[$i++];
281
+        $this->assertSame($args[0], 'object');
282
+        $this->assertTrue('Closure' === $args[1] || is_subclass_of($args[1], '\Closure'), 'Expect object class name to be Closure or a subclass of Closure.');
283
+
284
+        $this->assertSame(['array', [['integer', 1], ['integer', 2]]], $array[$i++]);
285
+        $this->assertSame(['array', ['foo' => ['integer', 123]]], $array[$i++]);
286
+        $this->assertSame(['null', null], $array[$i++]);
287
+        $this->assertSame(['boolean', true], $array[$i++]);
288
+        $this->assertSame(['boolean', false], $array[$i++]);
289
+        $this->assertSame(['integer', 0], $array[$i++]);
290
+        $this->assertSame(['float', 0.0], $array[$i++]);
291
+        $this->assertSame(['string', '0'], $array[$i++]);
292
+        $this->assertSame(['string', ''], $array[$i++]);
293
+        $this->assertSame(['float', INF], $array[$i++]);
294
+
295
+        // assertEquals() does not like NAN values.
296
+        $this->assertEquals($array[$i][0], 'float');
297
+        $this->assertTrue(is_nan($array[$i++][1]));
298
+    }
299
+
300
+    public function testRecursionInArguments()
301
+    {
302
+        $a = null;
303
+        $a = ['foo', [2, &$a]];
304
+        $exception = $this->createException($a);
305
+
306
+        $flattened = FlattenException::create($exception);
307
+        $trace = $flattened->getTrace();
308
+        $this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
309
+    }
310
+
311
+    public function testTooBigArray()
312
+    {
313
+        $a = [];
314
+        for ($i = 0; $i < 20; ++$i) {
315
+            for ($j = 0; $j < 50; ++$j) {
316
+                for ($k = 0; $k < 10; ++$k) {
317
+                    $a[$i][$j][$k] = 'value';
318
+                }
319
+            }
320
+        }
321
+        $a[20] = 'value';
322
+        $a[21] = 'value1';
323
+        $exception = $this->createException($a);
324
+
325
+        $flattened = FlattenException::create($exception);
326
+        $trace = $flattened->getTrace();
327
+
328
+        $this->assertSame($trace[1]['args'][0], ['array', ['array', '*SKIPPED over 10000 entries*']]);
329
+
330
+        $serializeTrace = serialize($trace);
331
+
332
+        $this->assertContains('*SKIPPED over 10000 entries*', $serializeTrace);
333
+        $this->assertNotContains('*value1*', $serializeTrace);
334
+    }
335
+
336
+    public function testAnonymousClass()
337
+    {
338
+        $flattened = FlattenException::create(new class() extends \RuntimeException {
339
+        });
340
+
341
+        $this->assertSame('RuntimeException@anonymous', $flattened->getClass());
342
+
343
+        $flattened = FlattenException::create(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException {
344
+        }))));
345
+
346
+        $this->assertSame('Class "RuntimeException@anonymous" blah.', $flattened->getMessage());
347
+    }
348
+
349
+    public function testToStringEmptyMessage()
350
+    {
351
+        $exception = new \RuntimeException();
352
+
353
+        $flattened = FlattenException::create($exception);
354
+
355
+        $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
356
+        $this->assertSame($exception->__toString(), $flattened->getAsString());
357
+    }
358
+
359
+    public function testToString()
360
+    {
361
+        $test = function ($a, $b, $c, $d) {
362
+            return new \RuntimeException('This is a test message');
363
+        };
364
+
365
+        $exception = $test('foo123', 1, null, 1.5);
366
+
367
+        $flattened = FlattenException::create($exception);
368
+
369
+        $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
370
+        $this->assertSame($exception->__toString(), $flattened->getAsString());
371
+    }
372
+
373
+    public function testToStringParent()
374
+    {
375
+        $exception = new \LogicException('This is message 1');
376
+        $exception = new \RuntimeException('This is messsage 2', 500, $exception);
377
+
378
+        $flattened = FlattenException::create($exception);
379
+
380
+        $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
381
+        $this->assertSame($exception->__toString(), $flattened->getAsString());
382
+    }
383
+
384
+    private function createException($foo)
385
+    {
386
+        return new \Exception();
387
+    }
388
+}