Merge branch '2.7'
* 2.7: [Form] NativeRequestHandler file handling fix [VarDumper] Workaround stringy numeric keys [HttpKernel] Throw double-bounce exceptions [FrameworkBundle] silence E_USER_DEPRECATED in insulated clients [minor] composer.json fix [minor] composer.json fix Fixed absolute_url for absolute paths minor #13377 [Console] Change greater by greater or equal for isFresh in FileResource [2.3] [HttpFoundation] fixed param order for Nginx's x-accel-redirect
This commit is contained in:
commit
43e100b5a1
@ -67,10 +67,10 @@ class HttpFoundationExtension extends \Twig_Extension
|
||||
$prefix = substr($prefix, 0, $pos).'/';
|
||||
}
|
||||
|
||||
$path = $prefix.$path;
|
||||
return $request->getUriForPath($prefix.$path);
|
||||
}
|
||||
|
||||
return $request->getUriForPath($path);
|
||||
return $request->getSchemeAndHttpHost().$path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,6 +43,21 @@ class HttpFoundationExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateAbsoluteUrlWithScriptFileName()
|
||||
{
|
||||
$request = Request::create('http://localhost/app/web/app_dev.php');
|
||||
$request->server->set('SCRIPT_FILENAME', '/var/www/app/web/app_dev.php');
|
||||
|
||||
$stack = new RequestStack();
|
||||
$stack->push($request);
|
||||
$extension = new HttpFoundationExtension($stack);
|
||||
|
||||
$this->assertEquals(
|
||||
'http://localhost/app/web/bundles/framework/css/structure.css',
|
||||
$extension->generateAbsoluteUrl('/app/web/bundles/framework/css/structure.css')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getGenerateRelativePathData()
|
||||
*/
|
||||
|
@ -165,7 +165,7 @@ class Client extends BaseClient
|
||||
$code = <<<EOF
|
||||
<?php
|
||||
|
||||
error_reporting($errorReporting);
|
||||
error_reporting($errorReporting & ~E_USER_DEPRECATED);
|
||||
|
||||
if ('$autoloader') {
|
||||
require_once '$autoloader';
|
||||
|
@ -60,7 +60,7 @@ class FileResource implements ResourceInterface, \Serializable
|
||||
return false;
|
||||
}
|
||||
|
||||
return filemtime($this->resource) < $timestamp;
|
||||
return filemtime($this->resource) <= $timestamp;
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
|
@ -128,7 +128,7 @@ class ConfigCacheTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
private function makeCacheStale()
|
||||
{
|
||||
touch($this->cacheFile, time() - 3600);
|
||||
touch($this->cacheFile, filemtime($this->resourceFile) - 3600);
|
||||
}
|
||||
|
||||
private function generateMetaFile()
|
||||
|
@ -17,11 +17,13 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $resource;
|
||||
protected $file;
|
||||
protected $time;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
|
||||
touch($this->file);
|
||||
$this->time = time();
|
||||
touch($this->file, $this->time);
|
||||
$this->resource = new FileResource($this->file);
|
||||
}
|
||||
|
||||
@ -42,11 +44,12 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testIsFresh()
|
||||
{
|
||||
$this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
|
||||
$this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
|
||||
$this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
|
||||
$this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
|
||||
$this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
|
||||
|
||||
$resource = new FileResource('/____foo/foobar'.rand(1, 999999));
|
||||
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
|
||||
$this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
|
||||
}
|
||||
|
||||
public function testSerializeUnserialize()
|
||||
|
@ -98,8 +98,8 @@ class NativeRequestHandler implements RequestHandlerInterface
|
||||
}
|
||||
|
||||
$fixedFiles = array();
|
||||
foreach ($_FILES as $name => $file) {
|
||||
$fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
|
||||
foreach ($_FILES as $fileKey => $file) {
|
||||
$fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
|
||||
}
|
||||
|
||||
if ('' === $name) {
|
||||
|
@ -266,6 +266,50 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->requestHandler->handleRequest($form, $this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodExceptGetProvider
|
||||
*/
|
||||
public function testSubmitMultipleFiles($method)
|
||||
{
|
||||
$form = $this->getMockForm('param1', $method);
|
||||
$file = $this->getMockFile();
|
||||
|
||||
$this->setRequestData($method, array(
|
||||
'param1' => null,
|
||||
), array(
|
||||
'param2' => $this->getMockFile('2'),
|
||||
'param1' => $file,
|
||||
'param3' => $this->getMockFile('3'),
|
||||
));
|
||||
|
||||
$form->expects($this->once())
|
||||
->method('submit')
|
||||
->with($file, 'PATCH' !== $method);
|
||||
|
||||
$this->requestHandler->handleRequest($form, $this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodExceptGetProvider
|
||||
*/
|
||||
public function testSubmitFileWithNamelessForm($method)
|
||||
{
|
||||
$form = $this->getMockForm(null, $method);
|
||||
$file = $this->getMockFile();
|
||||
|
||||
$this->setRequestData($method, array(
|
||||
'' => null,
|
||||
), array(
|
||||
'' => $file,
|
||||
));
|
||||
|
||||
$form->expects($this->once())
|
||||
->method('submit')
|
||||
->with($file, 'PATCH' !== $method);
|
||||
|
||||
$this->requestHandler->handleRequest($form, $this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPostMaxSizeFixtures
|
||||
*/
|
||||
@ -314,7 +358,7 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
abstract protected function getRequestHandler();
|
||||
|
||||
abstract protected function getMockFile();
|
||||
abstract protected function getMockFile($suffix = '');
|
||||
|
||||
protected function getMockForm($name, $method = null, $compound = true)
|
||||
{
|
||||
|
@ -46,8 +46,8 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest
|
||||
return new HttpFoundationRequestHandler($this->serverParams);
|
||||
}
|
||||
|
||||
protected function getMockFile()
|
||||
protected function getMockFile($suffix = '')
|
||||
{
|
||||
return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo');
|
||||
return new UploadedFile(__DIR__.'/../../Fixtures/foo'.$suffix, 'foo'.$suffix);
|
||||
}
|
||||
}
|
||||
|
0
src/Symfony/Component/Form/Tests/Fixtures/foo2
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo2
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo3
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo3
Normal file
@ -206,12 +206,12 @@ class NativeRequestHandlerTest extends AbstractRequestHandlerTest
|
||||
return new NativeRequestHandler($this->serverParams);
|
||||
}
|
||||
|
||||
protected function getMockFile()
|
||||
protected function getMockFile($suffix = '')
|
||||
{
|
||||
return array(
|
||||
'name' => 'upload.txt',
|
||||
'name' => 'upload'.$suffix.'.txt',
|
||||
'type' => 'text/plain',
|
||||
'tmp_name' => 'owfdskjasdfsa',
|
||||
'tmp_name' => 'owfdskjasdfsa'.$suffix,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'size' => 100,
|
||||
);
|
||||
|
@ -195,12 +195,13 @@ class BinaryFileResponse extends Response
|
||||
$path = $this->file->getRealPath();
|
||||
if (strtolower($type) == 'x-accel-redirect') {
|
||||
// Do X-Accel-Mapping substitutions.
|
||||
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect
|
||||
foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) {
|
||||
$mapping = explode('=', $mapping, 2);
|
||||
|
||||
if (2 == count($mapping)) {
|
||||
$location = trim($mapping[0]);
|
||||
$pathPrefix = trim($mapping[1]);
|
||||
$pathPrefix = trim($mapping[0]);
|
||||
$location = trim($mapping[1]);
|
||||
|
||||
if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
|
||||
$path = $location.substr($path, strlen($pathPrefix));
|
||||
|
@ -230,8 +230,8 @@ class BinaryFileResponseTest extends ResponseTestCase
|
||||
public function getSampleXAccelMappings()
|
||||
{
|
||||
return array(
|
||||
array('/var/www/var/www/files/foo.txt', '/files/=/var/www/', '/files/var/www/files/foo.txt'),
|
||||
array('/home/foo/bar.txt', '/files/=/var/www/,/baz/=/home/foo/', '/baz/bar.txt'),
|
||||
array('/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'),
|
||||
array('/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -57,13 +57,13 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
try {
|
||||
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
|
||||
} catch (\Exception $e) {
|
||||
$this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
|
||||
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
|
||||
|
||||
// set handling to false otherwise it wont be able to handle further more
|
||||
$handling = false;
|
||||
|
||||
// re-throw the exception from within HttpKernel as this is a catch-all
|
||||
return;
|
||||
// throwing $e, not $exception, is on purpose: fixing error handling code paths is the most important
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$event->setResponse($response);
|
||||
@ -81,7 +81,7 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
/**
|
||||
* Logs an exception.
|
||||
*
|
||||
* @param \Exception $exception The original \Exception instance
|
||||
* @param \Exception $exception The \Exception instance
|
||||
* @param string $message The error message to log
|
||||
* @param bool $original False when the handling of the exception thrown another exception
|
||||
*/
|
||||
|
@ -54,8 +54,9 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
try {
|
||||
$l->onKernelException($event2);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertSame('foo', $e->getMessage());
|
||||
$this->fail('RuntimeException expected');
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->assertSame('bar', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,8 +74,9 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
try {
|
||||
$l->onKernelException($event2);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertSame('foo', $e->getMessage());
|
||||
$this->fail('RuntimeException expected');
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->assertSame('bar', $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals(3, $logger->countErrors());
|
||||
@ -137,6 +139,6 @@ class TestKernelThatThrowsException implements HttpKernelInterface
|
||||
{
|
||||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
throw new \Exception('bar');
|
||||
throw new \RuntimeException('bar');
|
||||
}
|
||||
}
|
||||
|
@ -211,15 +211,17 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
}
|
||||
|
||||
if ($classInfo[1]) {
|
||||
$a = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
|
||||
$p = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
|
||||
} else {
|
||||
$a = (array) $obj;
|
||||
$p = (array) $obj;
|
||||
}
|
||||
|
||||
foreach ($a as $k => $p) {
|
||||
$a = array();
|
||||
foreach ($p as $k => $p) {
|
||||
if (!isset($k[0]) || ("\0" !== $k[0] && !$classInfo[2]->hasProperty($k))) {
|
||||
unset($a[$k]);
|
||||
$a["\0+\0".$k] = $p;
|
||||
} else {
|
||||
$a[$k] = $p;
|
||||
}
|
||||
}
|
||||
|
||||
|
94
src/Symfony/Component/VarDumper/Tests/VarClonerTest.php
Normal file
94
src/Symfony/Component/VarDumper/Tests/VarClonerTest.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class VarClonerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testClone()
|
||||
{
|
||||
$json = json_decode('{"1":{"var":"val"},"2":{"var":"val"}}');
|
||||
|
||||
$cloner = new VarCloner();
|
||||
$clone = $cloner->cloneVar($json);
|
||||
|
||||
$expected = <<<EOTXT
|
||||
Symfony\Component\VarDumper\Cloner\Data Object
|
||||
(
|
||||
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||
(
|
||||
[type] => object
|
||||
[class] => stdClass
|
||||
[value] =>
|
||||
[cut] => 0
|
||||
[handle] => %d
|
||||
[refCount] => 0
|
||||
[position] => 1
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[\000+\0001] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||
(
|
||||
[type] => object
|
||||
[class] => stdClass
|
||||
[value] =>
|
||||
[cut] => 0
|
||||
[handle] => %d
|
||||
[refCount] => 0
|
||||
[position] => 2
|
||||
)
|
||||
|
||||
[\000+\0002] => Symfony\Component\VarDumper\Cloner\Stub Object
|
||||
(
|
||||
[type] => object
|
||||
[class] => stdClass
|
||||
[value] =>
|
||||
[cut] => 0
|
||||
[handle] => %d
|
||||
[refCount] => 0
|
||||
[position] => 3
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[\000+\000var] => val
|
||||
)
|
||||
|
||||
[3] => Array
|
||||
(
|
||||
[\000+\000var] => val
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
|
||||
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
||||
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
|
||||
)
|
||||
|
||||
EOTXT;
|
||||
$this->assertStringMatchesFormat($expected, print_r($clone, true));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user