Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / http-kernel / Tests / DataCollector / LoggerDataCollectorTest.php
index a8500495790ae93a601ba1f5410c652d49a99c19..7a5833d4e9093564a60568e6365e47b379e043d4 100644 (file)
 namespace Symfony\Component\HttpKernel\Tests\DataCollector;
 
 use PHPUnit\Framework\TestCase;
+use Symfony\Component\Debug\Exception\SilencedErrorContext;
 use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
+use Symfony\Component\VarDumper\Cloner\Data;
 
 class LoggerDataCollectorTest extends TestCase
 {
+    private static $data;
+
     /**
      * @dataProvider getCollectTestData
      */
@@ -25,14 +29,19 @@ class LoggerDataCollectorTest extends TestCase
         $logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
         $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
 
-        $c = new LoggerDataCollector($logger);
+        // disable cloning the context, to ease fixtures creation.
+        $c = $this->getMockBuilder(LoggerDataCollector::class)
+            ->setMethods(array('cloneVar'))
+            ->setConstructorArgs(array($logger))
+            ->getMock();
+        $c->expects($this->any())->method('cloneVar')->willReturn(self::$data);
         $c->lateCollect();
 
-        $this->assertSame('logger', $c->getName());
-        $this->assertSame($nb, $c->countErrors());
-        $this->assertSame($expectedLogs ?: $logs, $c->getLogs());
-        $this->assertSame($expectedDeprecationCount, $c->countDeprecations());
-        $this->assertSame($expectedScreamCount, $c->countScreams());
+        $this->assertEquals('logger', $c->getName());
+        $this->assertEquals($nb, $c->countErrors());
+        $this->assertEquals($expectedLogs, $c->getLogs());
+        $this->assertEquals($expectedDeprecationCount, $c->countDeprecations());
+        $this->assertEquals($expectedScreamCount, $c->countScreams());
 
         if (isset($expectedPriorities)) {
             $this->assertSame($expectedPriorities, $c->getPriorities());
@@ -41,56 +50,59 @@ class LoggerDataCollectorTest extends TestCase
 
     public function getCollectTestData()
     {
-        return array(
-            array(
-                1,
-                array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                null,
-                0,
-                0,
-            ),
-            array(
-                1,
-                array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                0,
-                0,
-            ),
+        if (null === self::$data) {
+            self::$data = new Data(array());
+        }
+
+        yield 'simple log' => array(
+            1,
+            array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
+            array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
+            0,
+            0,
+        );
+
+        yield 'log with a context' => array(
+            1,
+            array(array('message' => 'foo', 'context' => array('foo' => 'bar'), 'priority' => 100, 'priorityName' => 'DEBUG')),
+            array(array('message' => 'foo', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG')),
+            0,
+            0,
+        );
+
+        if (!class_exists(SilencedErrorContext::class)) {
+            return;
+        }
+
+        yield 'logs with some deprecations' => array(
+            1,
             array(
-                1,
-                array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                0,
-                0,
+                array('message' => 'foo3', 'context' => array('exception' => new \ErrorException('warning', 0, E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
+                array('message' => 'foo', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'),
+                array('message' => 'foo2', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_USER_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'),
             ),
             array(
-                1,
-                array(
-                    array('message' => 'foo', 'context' => array('type' => E_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
-                    array('message' => 'foo2', 'context' => array('type' => E_USER_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
-                ),
-                null,
-                2,
-                0,
-                array(100 => array('count' => 2, 'name' => 'DEBUG')),
+                array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG'),
+                array('message' => 'foo', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
+                array('message' => 'foo2', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
             ),
+            2,
+            0,
+            array(100 => array('count' => 3, 'name' => 'DEBUG')),
+        );
+
+        yield 'logs with some silent errors' => array(
+            1,
             array(
-                1,
-                array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123, 'scream' => true), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                0,
-                1,
+                array('message' => 'foo3', 'context' => array('exception' => new \ErrorException('warning', 0, E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
+                array('message' => 'foo3', 'context' => array('exception' => new SilencedErrorContext(E_USER_WARNING, __FILE__, __LINE__)), 'priority' => 100, 'priorityName' => 'DEBUG'),
             ),
             array(
-                1,
-                array(
-                    array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG'),
-                    array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => -1, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG'),
-                ),
-                array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => -1, 'file' => __FILE__, 'line' => 123, 'errorCount' => 2), 'priority' => 100, 'priorityName' => 'DEBUG')),
-                0,
-                1,
+                array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG'),
+                array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true),
             ),
+            0,
+            1,
         );
     }
 }