Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / http-kernel / Tests / DataCollector / LoggerDataCollectorTest.php
index 7a5833d4e9093564a60568e6365e47b379e043d4..3dec3bd7f87a00878a9167ca2508c72f5b98a1dd 100644 (file)
@@ -14,46 +14,82 @@ 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;
+    public function testCollectWithUnexpectedFormat()
+    {
+        $logger = $this
+            ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
+            ->setMethods(array('countErrors', 'getLogs', 'clear'))
+            ->getMock();
+        $logger->expects($this->once())->method('countErrors')->will($this->returnValue('foo'));
+        $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue(array()));
+
+        $c = new LoggerDataCollector($logger, __DIR__.'/');
+        $c->lateCollect();
+        $compilerLogs = $c->getCompilerLogs()->getValue('message');
+
+        $this->assertSame(array(
+            array('message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'),
+            array('message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'),
+        ), $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']);
+
+        $this->assertSame(array(
+            array('message' => 'Some custom logging message'),
+            array('message' => 'With ending :'),
+        ), $compilerLogs['Unknown Compiler Pass']);
+    }
 
     /**
      * @dataProvider getCollectTestData
      */
     public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null)
     {
-        $logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock();
+        $logger = $this
+            ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
+            ->setMethods(array('countErrors', 'getLogs', 'clear'))
+            ->getMock();
         $logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
         $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
 
-        // 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 = new LoggerDataCollector($logger);
         $c->lateCollect();
 
         $this->assertEquals('logger', $c->getName());
         $this->assertEquals($nb, $c->countErrors());
-        $this->assertEquals($expectedLogs, $c->getLogs());
+
+        $logs = array_map(function ($v) {
+            if (isset($v['context']['exception'])) {
+                $e = &$v['context']['exception'];
+                $e = isset($e["\0*\0message"]) ? array($e["\0*\0message"], $e["\0*\0severity"]) : array($e["\0Symfony\Component\Debug\Exception\SilencedErrorContext\0severity"]);
+            }
+
+            return $v;
+        }, $c->getLogs()->getValue(true));
+        $this->assertEquals($expectedLogs, $logs);
         $this->assertEquals($expectedDeprecationCount, $c->countDeprecations());
         $this->assertEquals($expectedScreamCount, $c->countScreams());
 
         if (isset($expectedPriorities)) {
-            $this->assertSame($expectedPriorities, $c->getPriorities());
+            $this->assertSame($expectedPriorities, $c->getPriorities()->getValue(true));
         }
     }
 
-    public function getCollectTestData()
+    public function testReset()
     {
-        if (null === self::$data) {
-            self::$data = new Data(array());
-        }
+        $logger = $this
+            ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
+            ->setMethods(array('countErrors', 'getLogs', 'clear'))
+            ->getMock();
+        $logger->expects($this->once())->method('clear');
 
+        $c = new LoggerDataCollector($logger);
+        $c->reset();
+    }
+
+    public function getCollectTestData()
+    {
         yield 'simple log' => array(
             1,
             array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
@@ -65,7 +101,7 @@ class LoggerDataCollectorTest extends TestCase
         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')),
+            array(array('message' => 'foo', 'context' => array('foo' => 'bar'), 'priority' => 100, 'priorityName' => 'DEBUG')),
             0,
             0,
         );
@@ -82,9 +118,9 @@ class LoggerDataCollectorTest extends TestCase
                 array('message' => 'foo2', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_USER_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'),
             ),
             array(
-                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),
+                array('message' => 'foo3', 'context' => array('exception' => array('warning', E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
+                array('message' => 'foo', 'context' => array('exception' => array('deprecated', E_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
+                array('message' => 'foo2', 'context' => array('exception' => array('deprecated', E_USER_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
             ),
             2,
             0,
@@ -98,8 +134,8 @@ class LoggerDataCollectorTest extends TestCase
                 array('message' => 'foo3', 'context' => array('exception' => new SilencedErrorContext(E_USER_WARNING, __FILE__, __LINE__)), 'priority' => 100, 'priorityName' => 'DEBUG'),
             ),
             array(
-                array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG'),
-                array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true),
+                array('message' => 'foo3', 'context' => array('exception' => array('warning', E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
+                array('message' => 'foo3', 'context' => array('exception' => array(E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true),
             ),
             0,
             1,