Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
@@ -12,11 +12,11 @@
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector;
use Symfony\Component\HttpKernel\Kernel;
class ConfigDataCollectorTest extends TestCase
{
@@ -31,31 +31,16 @@ class ConfigDataCollectorTest extends TestCase
$this->assertTrue($c->isDebug());
$this->assertSame('config', $c->getName());
$this->assertSame('testkernel', $c->getAppName());
$this->assertSame(PHP_VERSION, $c->getPhpVersion());
$this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', \PHP_VERSION);
$this->assertMatchesRegularExpression('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', \PHP_VERSION);
$this->assertSame(\PHP_INT_SIZE * 8, $c->getPhpArchitecture());
$this->assertSame(class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
$this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());
$this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
$this->assertNull($c->getToken());
// if else clause because we don't know it
if (extension_loaded('xdebug')) {
$this->assertTrue($c->hasXDebug());
} else {
$this->assertFalse($c->hasXDebug());
}
// if else clause because we don't know it
if (((extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'))
||
(extension_loaded('apc') && ini_get('apc.enabled'))
||
(extension_loaded('Zend OPcache') && ini_get('opcache.enable'))
||
(extension_loaded('xcache') && ini_get('xcache.cacher'))
||
(extension_loaded('wincache') && ini_get('wincache.ocenabled')))) {
$this->assertTrue($c->hasAccelerator());
} else {
$this->assertFalse($c->hasAccelerator());
}
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
}
}
@@ -72,7 +57,7 @@ class KernelForTest extends Kernel
public function getBundles()
{
return array();
return [];
}
public function registerContainerConfiguration(LoaderInterface $loader)
@@ -15,9 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector\CloneVarDataCollector;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
class DataCollectorTest extends TestCase
{
@@ -32,19 +30,9 @@ class DataCollectorTest extends TestCase
public function testCloneVarExistingFilePath()
{
$c = new CloneVarDataCollector($filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_'));
$c = new CloneVarDataCollector([$filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_')]);
$c->collect(new Request(), new Response());
$data = $c->getData();
$this->assertInstanceOf(Stub::class, $data->getRawData()[0][0]);
$this->assertDumpEquals("\"$filePath\"", $data);
}
private function assertDumpEquals($dump, $data, $message = '')
{
$dumper = new CliDumper();
$dumper->setColors(false);
$this->assertSame(rtrim($dump), rtrim($dumper->dump($data, true)), $message);
$this->assertSame($filePath, $c->getData()[0]);
}
}
@@ -12,10 +12,11 @@
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\CliDumper;
/**
* @author Nicolas Grekas <p@tchwork.com>
@@ -24,7 +25,7 @@ class DumpDataCollectorTest extends TestCase
{
public function testDump()
{
$data = new Data(array(array(123)));
$data = new Data([[123]]);
$collector = new DumpDataCollector();
@@ -35,19 +36,19 @@ class DumpDataCollectorTest extends TestCase
$this->assertSame(1, $collector->getDumpsCount());
$dump = $collector->getDumps('html');
$this->assertTrue(isset($dump[0]['data']));
$this->assertArrayHasKey('data', $dump[0]);
$dump[0]['data'] = preg_replace('/^.*?<pre/', '<pre', $dump[0]['data']);
$dump[0]['data'] = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump[0]['data']);
$xDump = array(
array(
$xDump = [
[
'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
'name' => 'DumpDataCollectorTest.php',
'file' => __FILE__,
'line' => $line,
'fileExcerpt' => false,
),
);
],
];
$this->assertEquals($xDump, $dump);
$this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
@@ -57,7 +58,7 @@ class DumpDataCollectorTest extends TestCase
public function testCollectDefault()
{
$data = new Data(array(array(123)));
$data = new Data([[123]]);
$collector = new DumpDataCollector();
@@ -66,7 +67,7 @@ class DumpDataCollectorTest extends TestCase
ob_start();
$collector->collect(new Request(), new Response());
$output = ob_get_clean();
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
$this->assertSame(1, $collector->getDumpsCount());
@@ -75,7 +76,7 @@ class DumpDataCollectorTest extends TestCase
public function testCollectHtml()
{
$data = new Data(array(array(123)));
$data = new Data([[123]]);
$collector = new DumpDataCollector(null, 'test://%f:%l');
@@ -103,13 +104,32 @@ EOTXT;
public function testFlush()
{
$data = new Data(array(array(456)));
$data = new Data([[456]]);
$collector = new DumpDataCollector();
$collector->dump($data);
$line = __LINE__ - 1;
ob_start();
$collector->__destruct();
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
}
public function testFlushNothingWhenDataDumperIsProvided()
{
$data = new Data([[456]]);
$dumper = new CliDumper('php://output');
$collector = new DumpDataCollector(null, null, null, null, $dumper);
ob_start();
$collector->dump($data);
$line = __LINE__ - 1;
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
ob_start();
$collector->__destruct();
$this->assertEmpty(ob_get_clean());
}
}
@@ -13,9 +13,9 @@ namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
class ExceptionDataCollectorTest extends TestCase
{
@@ -37,4 +37,23 @@ class ExceptionDataCollectorTest extends TestCase
$this->assertSame('exception', $c->getName());
$this->assertSame($trace, $c->getTrace());
}
public function testCollectWithoutException()
{
$c = new ExceptionDataCollector();
$c->collect(new Request(), new Response());
$this->assertFalse($c->hasException());
}
public function testReset()
{
$c = new ExceptionDataCollector();
$c->collect(new Request(), new Response(), new \Exception());
$c->reset();
$c->collect(new Request(), new Response());
$this->assertFalse($c->hasException());
}
}
@@ -14,95 +14,133 @@ 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(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->willReturn(123);
$logger->expects($this->exactly(2))->method('getLogs')->willReturn([]);
$c = new LoggerDataCollector($logger, __DIR__.'/');
$c->lateCollect();
$compilerLogs = $c->getCompilerLogs()->getValue('message');
$this->assertSame([
['message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'],
['message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'],
], $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']);
$this->assertSame([
['message' => 'Some custom logging message'],
['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->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))
$logger = $this
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$c->expects($this->any())->method('cloneVar')->willReturn(self::$data);
$logger->expects($this->once())->method('countErrors')->willReturn($nb);
$logger->expects($this->exactly(2))->method('getLogs')->willReturn($logs);
$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"]) ? [$e["\0*\0message"], $e["\0*\0severity"]] : [$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 testReset()
{
$logger = $this
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('clear');
$c = new LoggerDataCollector($logger);
$c->reset();
}
public function getCollectTestData()
{
if (null === self::$data) {
self::$data = new Data(array());
}
yield 'simple log' => array(
yield 'simple log' => [
1,
array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
[['message' => 'foo', 'context' => [], 'priority' => 100, 'priorityName' => 'DEBUG']],
[['message' => 'foo', 'context' => [], 'priority' => 100, 'priorityName' => 'DEBUG']],
0,
0,
);
];
yield 'log with a context' => array(
yield 'log with a context' => [
1,
array(array('message' => 'foo', 'context' => array('foo' => 'bar'), 'priority' => 100, 'priorityName' => 'DEBUG')),
array(array('message' => 'foo', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG')),
[['message' => 'foo', 'context' => ['foo' => 'bar'], 'priority' => 100, 'priorityName' => 'DEBUG']],
[['message' => 'foo', 'context' => ['foo' => 'bar'], 'priority' => 100, 'priorityName' => 'DEBUG']],
0,
0,
);
];
if (!class_exists(SilencedErrorContext::class)) {
return;
}
yield 'logs with some deprecations' => array(
yield 'logs with some deprecations' => [
1,
array(
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(
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),
),
[
['message' => 'foo3', 'context' => ['exception' => new \ErrorException('warning', 0, \E_USER_WARNING)], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo', 'context' => ['exception' => new \ErrorException('deprecated', 0, \E_DEPRECATED)], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo2', 'context' => ['exception' => new \ErrorException('deprecated', 0, \E_USER_DEPRECATED)], 'priority' => 100, 'priorityName' => 'DEBUG'],
],
[
['message' => 'foo3', 'context' => ['exception' => ['warning', \E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo', 'context' => ['exception' => ['deprecated', \E_DEPRECATED]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false],
['message' => 'foo2', 'context' => ['exception' => ['deprecated', \E_USER_DEPRECATED]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false],
],
2,
0,
array(100 => array('count' => 3, 'name' => 'DEBUG')),
);
[100 => ['count' => 3, 'name' => 'DEBUG']],
];
yield 'logs with some silent errors' => array(
yield 'logs with some silent errors' => [
1,
array(
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(
array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true),
),
[
['message' => 'foo3', 'context' => ['exception' => new \ErrorException('warning', 0, \E_USER_WARNING)], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo3', 'context' => ['exception' => new SilencedErrorContext(\E_USER_WARNING, __FILE__, __LINE__)], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => '0', 'context' => ['exception' => new SilencedErrorContext(\E_USER_WARNING, __FILE__, __LINE__)], 'priority' => 100, 'priorityName' => 'DEBUG'],
],
[
['message' => 'foo3', 'context' => ['exception' => ['warning', \E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo3', 'context' => ['exception' => [\E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true],
['message' => '0', 'context' => ['exception' => [\E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true],
],
0,
1,
);
2,
];
}
}
@@ -12,9 +12,9 @@
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector;
class MemoryDataCollectorTest extends TestCase
{
@@ -23,8 +23,8 @@ class MemoryDataCollectorTest extends TestCase
$collector = new MemoryDataCollector();
$collector->collect(new Request(), new Response());
$this->assertInternalType('integer', $collector->getMemory());
$this->assertInternalType('integer', $collector->getMemoryLimit());
$this->assertIsInt($collector->getMemory());
$this->assertIsInt($collector->getMemoryLimit());
$this->assertSame('memory', $collector->getName());
}
@@ -39,21 +39,21 @@ class MemoryDataCollectorTest extends TestCase
public function getBytesConversionTestData()
{
return array(
array('2k', 2048),
array('2 k', 2048),
array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
array('0xf', 15),
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
array('1G', 1024 * 1024 * 1024),
array('-1', -1),
array('0', 0),
array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
return [
['2k', 2048],
['2 k', 2048],
['8m', 8 * 1024 * 1024],
['+2 k', 2048],
['+2???k', 2048],
['0x10', 16],
['0xf', 15],
['010', 8],
['+0x10 k', 16 * 1024],
['1g', 1024 * 1024 * 1024],
['1G', 1024 * 1024 * 1024],
['-1', -1],
['0', 0],
['2mk', 2048], // the unit must be the last char, so in this case 'k', not 'm'
];
}
}
@@ -12,21 +12,20 @@
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpFoundation\Request;
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 TestCase
{
@@ -35,8 +34,8 @@ class RequestDataCollectorTest extends TestCase
$c = new RequestDataCollector();
$c->collect($request = $this->createRequest(), $this->createResponse());
$c->lateCollect();
$cloner = new VarCloner();
$attributes = $c->getRequestAttributes();
$this->assertSame('request', $c->getName());
@@ -46,13 +45,14 @@ class RequestDataCollectorTest extends TestCase
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery());
$this->assertInstanceOf(ParameterBag::class, $c->getResponseCookies());
$this->assertSame('html', $c->getFormat());
$this->assertEquals('foobar', $c->getRoute());
$this->assertEquals(array('name' => $cloner->cloneVar(array('name' => 'foo'))->seek('name')), $c->getRouteParams());
$this->assertSame(array(), $c->getSessionAttributes());
$this->assertEquals(['name' => 'foo'], $c->getRouteParams());
$this->assertSame([], $c->getSessionAttributes());
$this->assertSame('en', $c->getLocale());
$this->assertEquals($cloner->cloneVar($request->attributes->get('resource')), $attributes->get('resource'));
$this->assertEquals($cloner->cloneVar($request->attributes->get('object')), $attributes->get('object'));
$this->assertContainsEquals(__FILE__, $attributes->get('resource'));
$this->assertSame('stdClass', $attributes->get('object')->getType());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());
$this->assertSame('OK', $c->getStatusText());
@@ -62,26 +62,13 @@ class RequestDataCollectorTest extends TestCase
public function testCollectWithoutRouteParams()
{
$request = $this->createRequest(array());
$request = $this->createRequest([]);
$c = new RequestDataCollector();
$c->collect($request, $this->createResponse());
$c->lateCollect();
$this->assertEquals(array(), $c->getRouteParams());
}
public function testKernelResponseDoesNotStartSession()
{
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = new Request();
$session = new Session(new MockArraySessionStorage());
$request->setSession($session);
$response = new Response();
$c = new RequestDataCollector();
$c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertFalse($session->isStarted());
$this->assertEquals([], $c->getRouteParams());
}
/**
@@ -94,8 +81,9 @@ class RequestDataCollectorTest extends TestCase
$response = $this->createResponse();
$this->injectController($c, $callable, $request);
$c->collect($request, $response);
$c->lateCollect();
$this->assertSame($expected, $c->getController(), sprintf('Testing: %s', $name));
$this->assertSame($expected, $c->getController()->getValue(true), sprintf('Testing: %s', $name));
}
public function provideControllerCallables()
@@ -106,95 +94,95 @@ class RequestDataCollectorTest extends TestCase
$r3 = new \ReflectionClass($this);
// test name, callable, expected
return array(
array(
return [
[
'"Regular" callable',
array($this, 'testControllerInspection'),
array(
'class' => __NAMESPACE__.'\RequestDataCollectorTest',
[$this, 'testControllerInspection'],
[
'class' => self::class,
'method' => 'testControllerInspection',
'file' => __FILE__,
'line' => $r1->getStartLine(),
),
),
],
],
array(
[
'Closure',
function () { return 'foo'; },
array(
[
'class' => __NAMESPACE__.'\{closure}',
'method' => null,
'file' => __FILE__,
'line' => __LINE__ - 5,
),
),
],
],
array(
[
'Static callback as string',
__NAMESPACE__.'\RequestDataCollectorTest::staticControllerMethod',
array(
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2->getStartLine(),
),
),
],
],
array(
[
'Static callable with instance',
array($this, 'staticControllerMethod'),
array(
[$this, 'staticControllerMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2->getStartLine(),
),
),
],
],
array(
[
'Static callable with class name',
array('Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'staticControllerMethod'),
array(
['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'staticControllerMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2->getStartLine(),
),
),
],
],
array(
[
'Callable with instance depending on __call()',
array($this, 'magicMethod'),
array(
[$this, 'magicMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'magicMethod',
'file' => 'n/a',
'line' => 'n/a',
),
),
],
],
array(
[
'Callable with class name depending on __callStatic()',
array('Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'magicMethod'),
array(
['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'magicMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'magicMethod',
'file' => 'n/a',
'line' => 'n/a',
),
),
],
],
array(
[
'Invokable controller',
$this,
array(
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => null,
'file' => __FILE__,
'line' => $r3->getStartLine(),
),
),
);
],
],
];
}
public function testItIgnoresInvalidCallables()
@@ -208,7 +196,57 @@ class RequestDataCollectorTest extends TestCase
$this->assertSame('n/a', $c->getController());
}
protected function createRequest($routeParams = array('name' => 'foo'))
public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie()
{
$request = $this->createRequest();
$request->cookies->add([
'sf_redirect' => '{}',
]);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$c = new RequestDataCollector();
$c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse()));
$this->assertTrue($request->attributes->get('_redirected'));
}
public function testItSetsARedirectCookieIfTheResponseIsARedirection()
{
$c = new RequestDataCollector();
$response = $this->createResponse();
$response->setStatusCode(302);
$response->headers->set('Location', '/somewhere-else');
$c->collect($request = $this->createRequest(), $response);
$c->lateCollect();
$cookie = $this->getCookieByName($response, 'sf_redirect');
$this->assertNotEmpty($cookie->getValue());
}
public function testItCollectsTheRedirectionAndClearTheCookie()
{
$c = new RequestDataCollector();
$request = $this->createRequest();
$request->attributes->set('_redirected', true);
$request->cookies->add([
'sf_redirect' => '{"method": "POST"}',
]);
$c->collect($request, $response = $this->createResponse());
$c->lateCollect();
$this->assertEquals('POST', $c->getRedirect()['method']);
$cookie = $this->getCookieByName($response, 'sf_redirect');
$this->assertNull($cookie->getValue());
}
protected function createRequest($routeParams = ['name' => 'foo'])
{
$request = Request::create('http://test.com/foo?bar=baz');
$request->attributes->set('foo', 'bar');
@@ -282,4 +320,15 @@ class RequestDataCollectorTest extends TestCase
{
throw new \LogicException('Unexpected method call');
}
private function getCookieByName(Response $response, $name)
{
foreach ($response->headers->getCookies() as $cookie) {
if ($cookie->getName() == $name) {
return $cookie;
}
}
throw new \InvalidArgumentException(sprintf('Cookie named "%s" is not in response', $name));
}
}
@@ -12,9 +12,10 @@
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
use Symfony\Component\Stopwatch\Stopwatch;
/**
* @group time-sensitive
@@ -30,7 +31,7 @@ class TimeDataCollectorTest extends TestCase
$c->collect($request, new Response());
$this->assertEquals(1000, $c->getStartTime());
$this->assertEquals(0, $c->getStartTime());
$request->server->set('REQUEST_TIME_FLOAT', 2);
@@ -43,7 +44,7 @@ class TimeDataCollectorTest extends TestCase
$this->assertEquals(0, $c->getStartTime());
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
$kernel->expects($this->once())->method('getStartTime')->will($this->returnValue(123456));
$kernel->expects($this->once())->method('getStartTime')->willReturn(123456.0);
$c = new TimeDataCollector($kernel);
$request = new Request();
@@ -51,5 +52,6 @@ class TimeDataCollectorTest extends TestCase
$c->collect($request, new Response());
$this->assertEquals(123456000, $c->getStartTime());
$this->assertSame(class_exists(Stopwatch::class, false), $c->isStopwatchInstalled());
}
}