Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / debug / Tests / Exception / FlattenExceptionTest.php
index ae01e9cb0d839741208b74611a067ce57ed27115..66171e3ae71ffb24a3a9b03d383b4efa3e5970eb 100644 (file)
@@ -13,6 +13,7 @@ namespace Symfony\Component\Debug\Tests\Exception;
 
 use PHPUnit\Framework\TestCase;
 use Symfony\Component\Debug\Exception\FlattenException;
+use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
 use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
@@ -79,6 +80,11 @@ class FlattenExceptionTest extends TestCase
 
         $flattened = FlattenException::create(new UnsupportedMediaTypeHttpException());
         $this->assertEquals('415', $flattened->getStatusCode());
+
+        if (class_exists(SuspiciousOperationException::class)) {
+            $flattened = FlattenException::create(new SuspiciousOperationException());
+            $this->assertEquals('400', $flattened->getStatusCode());
+        }
     }
 
     public function testHeadersForHttpException()
@@ -105,7 +111,7 @@ class FlattenExceptionTest extends TestCase
     /**
      * @dataProvider flattenDataProvider
      */
-    public function testFlattenHttpException(\Exception $exception, $statusCode)
+    public function testFlattenHttpException(\Exception $exception)
     {
         $flattened = FlattenException::create($exception);
         $flattened2 = FlattenException::create($exception);
@@ -120,7 +126,7 @@ class FlattenExceptionTest extends TestCase
     /**
      * @dataProvider flattenDataProvider
      */
-    public function testPrevious(\Exception $exception, $statusCode)
+    public function testPrevious(\Exception $exception)
     {
         $flattened = FlattenException::create($exception);
         $flattened2 = FlattenException::create($exception);
@@ -167,7 +173,7 @@ class FlattenExceptionTest extends TestCase
     /**
      * @dataProvider flattenDataProvider
      */
-    public function testToArray(\Exception $exception, $statusCode)
+    public function testToArray(\Exception $exception)
     {
         $flattened = FlattenException::create($exception);
         $flattened->setTrace(array(), 'foo.php', 123);
@@ -187,12 +193,75 @@ class FlattenExceptionTest extends TestCase
     public function flattenDataProvider()
     {
         return array(
-            array(new \Exception('test', 123), 500),
+            array(new \Exception('test', 123)),
         );
     }
 
+    public function testArguments()
+    {
+        $dh = opendir(__DIR__);
+        $fh = tmpfile();
+
+        $incomplete = unserialize('O:14:"BogusTestClass":0:{}');
+
+        $exception = $this->createException(array(
+            (object) array('foo' => 1),
+            new NotFoundHttpException(),
+            $incomplete,
+            $dh,
+            $fh,
+            function () {},
+            array(1, 2),
+            array('foo' => 123),
+            null,
+            true,
+            false,
+            0,
+            0.0,
+            '0',
+            '',
+            INF,
+            NAN,
+        ));
+
+        $flattened = FlattenException::create($exception);
+        $trace = $flattened->getTrace();
+        $args = $trace[1]['args'];
+        $array = $args[0][1];
+
+        closedir($dh);
+        fclose($fh);
+
+        $i = 0;
+        $this->assertSame(array('object', 'stdClass'), $array[$i++]);
+        $this->assertSame(array('object', 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'), $array[$i++]);
+        $this->assertSame(array('incomplete-object', 'BogusTestClass'), $array[$i++]);
+        $this->assertSame(array('resource', defined('HHVM_VERSION') ? 'Directory' : 'stream'), $array[$i++]);
+        $this->assertSame(array('resource', 'stream'), $array[$i++]);
+
+        $args = $array[$i++];
+        $this->assertSame($args[0], 'object');
+        $this->assertTrue('Closure' === $args[1] || is_subclass_of($args[1], '\Closure'), 'Expect object class name to be Closure or a subclass of Closure.');
+
+        $this->assertSame(array('array', array(array('integer', 1), array('integer', 2))), $array[$i++]);
+        $this->assertSame(array('array', array('foo' => array('integer', 123))), $array[$i++]);
+        $this->assertSame(array('null', null), $array[$i++]);
+        $this->assertSame(array('boolean', true), $array[$i++]);
+        $this->assertSame(array('boolean', false), $array[$i++]);
+        $this->assertSame(array('integer', 0), $array[$i++]);
+        $this->assertSame(array('float', 0.0), $array[$i++]);
+        $this->assertSame(array('string', '0'), $array[$i++]);
+        $this->assertSame(array('string', ''), $array[$i++]);
+        $this->assertSame(array('float', INF), $array[$i++]);
+
+        // assertEquals() does not like NAN values.
+        $this->assertEquals($array[$i][0], 'float');
+        $this->assertTrue(is_nan($array[$i++][1]));
+    }
+
     public function testRecursionInArguments()
     {
+        $a = null;
         $a = array('foo', array(2, &$a));
         $exception = $this->createException($a);
 
@@ -217,6 +286,9 @@ class FlattenExceptionTest extends TestCase
 
         $flattened = FlattenException::create($exception);
         $trace = $flattened->getTrace();
+
+        $this->assertSame($trace[1]['args'][0], array('array', array('array', '*SKIPPED over 10000 entries*')));
+
         $serializeTrace = serialize($trace);
 
         $this->assertContains('*SKIPPED over 10000 entries*', $serializeTrace);
@@ -227,45 +299,4 @@ class FlattenExceptionTest extends TestCase
     {
         return new \Exception();
     }
-
-    public function testSetTraceIncompleteClass()
-    {
-        $flattened = FlattenException::create(new \Exception('test', 123));
-        $flattened->setTrace(
-            array(
-                array(
-                    'file' => __FILE__,
-                    'line' => 123,
-                    'function' => 'test',
-                    'args' => array(
-                        unserialize('O:14:"BogusTestClass":0:{}'),
-                    ),
-                ),
-            ),
-            'foo.php', 123
-        );
-
-        $this->assertEquals(array(
-            array(
-                'message' => 'test',
-                'class' => 'Exception',
-                'trace' => array(
-                    array(
-                        'namespace' => '', 'short_class' => '', 'class' => '', 'type' => '', 'function' => '',
-                        'file' => 'foo.php', 'line' => 123,
-                        'args' => array(),
-                    ),
-                    array(
-                        'namespace' => '', 'short_class' => '', 'class' => '', 'type' => '', 'function' => 'test',
-                        'file' => __FILE__, 'line' => 123,
-                        'args' => array(
-                            array(
-                                'incomplete-object', 'BogusTestClass',
-                            ),
-                        ),
-                    ),
-                ),
-            ),
-        ), $flattened->toArray());
-    }
 }