diff --git a/UPGRADE-3.2.md b/UPGRADE-3.2.md index 28c4eecf3cca2..b65bdd43fc561 100644 --- a/UPGRADE-3.2.md +++ b/UPGRADE-3.2.md @@ -38,8 +38,14 @@ Form FrameworkBundle --------------- - * The service `serializer.mapping.cache.doctrine.apc` is deprecated. APCu should now - be automatically used when available. + * The service `serializer.mapping.cache.doctrine.apc` is deprecated. APCu should now + be automatically used when available. + +HttpKernel +---------- + + * `DataCollector::varToString()` is deprecated and will be removed in Symfony + 4.0. Use the `cloneVar()` method instead. HttpFoundation --------------- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index f5a087ab675c9..42f709fe7c9c9 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -155,6 +155,8 @@ HttpKernel have your own `ControllerResolverInterface` implementation, you should inject an `ArgumentResolverInterface` instance. + * The `DataCollector::varToString()` method has been removed in favor of `cloneVar()`. + Serializer ---------- diff --git a/src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig b/src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig index 0ece492346b06..7f078b93ac34c 100644 --- a/src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig +++ b/src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig @@ -45,7 +45,7 @@ {% for dump in collector.getDumps('html') %}
User is not authenticated probably because they have no roles.
@@ -98,14 +98,14 @@ {% if collector.supportsRoleHierarchy %}- {{- trace.root -}} - {%- if trace.path is not empty -%} - {%- if trace.path|first != '[' %}.{% endif -%} - {{- trace.path -}} - {%- endif %} = {{ trace.value -}} -- {% elseif trace.message is defined %} - {{ trace.class }} -
{{ trace.message }}- {% else %} -
{{ trace }}- {% endif %} + {% if error.trace %} + Caused by: + {{ profiler_dump(error.trace, maxDepth=2) }} {% else %} Unknown. - {% endfor %} + {% endif %}
No GET parameters
No POST parameters
{% else %} - {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestrequest }, with_context = false) }} + {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestrequest, maxDepth: 1 }, with_context = false) }} {% endif %}DumpDataCollectorTest.php on line {$line}: 123diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php index c994250429ebf..f331dbb32b5ec 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php @@ -13,9 +13,12 @@ use Symfony\Component\Debug\Exception\SilencedErrorContext; use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector; +use Symfony\Component\VarDumper\Cloner\Data; class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase { + private static $data; + /** * @dataProvider getCollectTestData */ @@ -25,19 +28,17 @@ public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount $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(); - // Remove the trace from the real logs, to ease fixtures creation. - $logs = array_map(function ($log) { - unset($log['context']['trace'], $log['context']['exception']['trace']); - - return $log; - }, $c->getLogs()); - $this->assertEquals('logger', $c->getName()); $this->assertEquals($nb, $c->countErrors()); - $this->assertEquals($expectedLogs, $logs); + $this->assertEquals($expectedLogs, $c->getLogs()); $this->assertEquals($expectedDeprecationCount, $c->countDeprecations()); $this->assertEquals($expectedScreamCount, $c->countScreams()); @@ -48,6 +49,10 @@ public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount public function getCollectTestData() { + if (null === self::$data) { + self::$data = new Data(array()); + } + yield 'simple log' => array( 1, array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')), @@ -56,18 +61,10 @@ public function getCollectTestData() 0, ); - yield 'log with a resource' => 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, - ); - - yield 'log with an object' => array( + yield 'log with a context' => 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')), + 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, ); @@ -84,9 +81,9 @@ public function getCollectTestData() array('message' => 'foo2', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_USER_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'), ), array( - array('message' => 'foo3', 'context' => array('exception' => array('file' => __FILE__, 'line' => 82, 'class' => \ErrorException::class, 'message' => 'warning')), 'priority' => 100, 'priorityName' => 'DEBUG'), - array('message' => 'foo', 'context' => array('type' => 'E_DEPRECATED', 'file' => __FILE__, 'line' => 83, 'errorCount' => 1, 'scream' => false), 'priority' => 100, 'priorityName' => 'DEBUG'), - array('message' => 'foo2', 'context' => array('type' => 'E_USER_DEPRECATED', 'file' => __FILE__, 'line' => 84, 'errorCount' => 1, 'scream' => false), 'priority' => 100, 'priorityName' => '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, @@ -100,8 +97,8 @@ public function getCollectTestData() array('message' => 'foo3', 'context' => array('exception' => new SilencedErrorContext(E_USER_WARNING, __FILE__, __LINE__)), 'priority' => 100, 'priorityName' => 'DEBUG'), ), array( - array('message' => 'foo3', 'context' => array('exception' => array('file' => __FILE__, 'line' => 99, 'class' => \ErrorException::class, 'message' => 'warning')), 'priority' => 100, 'priorityName' => 'DEBUG'), - array('message' => 'foo3', 'context' => array('type' => 'E_USER_WARNING', 'file' => __FILE__, 'line' => 100, 'errorCount' => 1, 'scream' => true), 'priority' => 100, 'priorityName' => 'DEBUG'), + 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, diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php index eef00d4a024dd..4fea364ec7969 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -23,6 +23,8 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\VarDumper\Cloner\Data; +use Symfony\Component\VarDumper\Cloner\VarCloner; class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase { @@ -30,8 +32,9 @@ public function testCollect() { $c = new RequestDataCollector(); - $c->collect($this->createRequest(), $this->createResponse()); + $c->collect($request = $this->createRequest(), $this->createResponse()); + $cloner = new VarCloner(); $attributes = $c->getRequestAttributes(); $this->assertSame('request', $c->getName()); @@ -42,12 +45,12 @@ public function testCollect() $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest()); $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery()); $this->assertSame('html', $c->getFormat()); - $this->assertSame('foobar', $c->getRoute()); - $this->assertSame(array('name' => 'foo'), $c->getRouteParams()); + $this->assertEquals('foobar', $c->getRoute()); + $this->assertEquals($cloner->cloneVar(array('name' => 'foo')), $c->getRouteParams()); $this->assertSame(array(), $c->getSessionAttributes()); $this->assertSame('en', $c->getLocale()); - $this->assertRegExp('/Resource\(stream#\d+\)/', $attributes->get('resource')); - $this->assertSame('Object(stdClass)', $attributes->get('object')); + $this->assertEquals($cloner->cloneVar($request->attributes->get('resource')), $attributes->get('resource')); + $this->assertEquals($cloner->cloneVar($request->attributes->get('object')), $attributes->get('object')); $this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getResponseHeaders()); $this->assertSame('OK', $c->getStatusText()); diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php index 09810a98b1275..c583918f8c09f 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php @@ -13,6 +13,9 @@ use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter; +/** + * @group legacy + */ class ValueExporterTest extends \PHPUnit_Framework_TestCase { /** diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php index fe4f430777be4..45c6225bd8bdb 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\VarDumper\Cloner\Data; class ProfilerTest extends \PHPUnit_Framework_TestCase { @@ -35,7 +36,7 @@ public function testCollect() $this->assertSame(204, $profile->getStatusCode()); $this->assertSame('GET', $profile->getMethod()); - $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all()); + $this->assertInstanceOf(Data::class, $profiler->get('request')->getRequestQuery()->all()['foo']); } public function testFindWorksWithDates() diff --git a/src/Symfony/Component/Security/Core/Authorization/DebugAccessDecisionManager.php b/src/Symfony/Component/Security/Core/Authorization/DebugAccessDecisionManager.php index aa15443dd037b..219ca7621a852 100644 --- a/src/Symfony/Component/Security/Core/Authorization/DebugAccessDecisionManager.php +++ b/src/Symfony/Component/Security/Core/Authorization/DebugAccessDecisionManager.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Security\Core\Authorization; -use Doctrine\Common\Util\ClassUtils; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** @@ -50,7 +49,7 @@ public function decide(TokenInterface $token, array $attributes, $object = null) $this->decisionLog[] = array( 'attributes' => $attributes, - 'object' => $this->getStringRepresentation($object), + 'object' => $object, 'result' => $result, ); @@ -96,39 +95,4 @@ public function getDecisionLog() { return $this->decisionLog; } - - /** - * @param mixed $object - * - * @return string - */ - private function getStringRepresentation($object) - { - if (null === $object) { - return 'NULL'; - } - - if (!is_object($object)) { - if (is_bool($object)) { - return sprintf('%s (%s)', gettype($object), $object ? 'true' : 'false'); - } - if (is_scalar($object)) { - return sprintf('%s (%s)', gettype($object), $object); - } - - return gettype($object); - } - - $objectClass = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($object) : get_class($object); - - if (method_exists($object, 'getId')) { - $objectAsString = sprintf('ID: %s', $object->getId()); - } elseif (method_exists($object, '__toString')) { - $objectAsString = (string) $object; - } else { - $objectAsString = sprintf('object hash: %s', spl_object_hash($object)); - } - - return sprintf('%s (%s)', $objectClass, $objectAsString); - } } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php index f90f7769ba4c9..16661f702228a 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php @@ -32,12 +32,12 @@ public function provideObjectsAndLogs() { $object = new \stdClass(); - yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'NULL', 'result' => false)), null); - yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'boolean (true)', 'result' => false)), true); - yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'string (jolie string)', 'result' => false)), 'jolie string'); - yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'integer (12345)', 'result' => false)), 12345); - yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'resource', 'result' => false)), fopen(__FILE__, 'r')); - yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'array', 'result' => false)), array()); - yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => sprintf('stdClass (object hash: %s)', spl_object_hash($object)), 'result' => false)), $object); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => null, 'result' => false)), null); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => true, 'result' => false)), true); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'jolie string', 'result' => false)), 'jolie string'); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 12345, 'result' => false)), 12345); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => $x = fopen(__FILE__, 'r'), 'result' => false)), $x); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => $x = array(), 'result' => false)), $x); + yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => $object, 'result' => false)), $object); } } diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index a3a9e7d320062..ad6fb2a21f411 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -363,8 +363,7 @@ function isCtrlKey(e) { }; })(document); - -