Merge branch '4.2'

* 4.2:
  properly fix tests on PHP 5
  fix tests on PHP 5
  remove doubled dot from exception message
  bug #29697 [DI] Fixed wrong factory method in exception (Wojciech Gorczyca)
  [Intl] make type-hinted arguments nullable
  [DI] Fixed wrong factory method in exception
  Changed gender choice types to color
  Fix unnecessary use
  remove no longer needed PHP version checks
  remove no longer needed PHP version checks
  Fixed groupBy argument value in DefaultChoiceListFactoryTest
  [HttpKernel] Correctly Render Signed URIs Containing Fragments
  [HttpFoundation] Fix request uri when it starts with double slashes
This commit is contained in:
Robin Chalas 2019-01-05 17:38:08 +01:00
commit af9920cf10
21 changed files with 151 additions and 45 deletions

View File

@ -16,7 +16,7 @@ array_shift($dirs);
$mergeBase = trim(shell_exec(sprintf('git merge-base "%s" HEAD', array_shift($dirs))));
$packages = array();
$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0;
$flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
foreach ($dirs as $k => $dir) {
if (!system("git diff --name-only $mergeBase -- $dir", $exitStatus)) {

View File

@ -163,7 +163,7 @@ class ObjectsProvider
public static function getCallables()
{
$callables = array(
return array(
'callable_1' => 'array_key_exists',
'callable_2' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'),
'callable_3' => array(new CallableClass(), 'method'),
@ -171,13 +171,8 @@ class ObjectsProvider
'callable_5' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ExtendedCallableClass', 'parent::staticMethod'),
'callable_6' => function () { return 'Closure'; },
'callable_7' => new CallableClass(),
'callable_from_callable' => \Closure::fromCallable(new CallableClass()),
);
if (\PHP_VERSION_ID >= 70100) {
$callables['callable_from_callable'] = \Closure::fromCallable(new CallableClass());
}
return $callables;
}
}

View File

@ -49,6 +49,7 @@ class ResolveNamedArgumentsPass extends AbstractRecursivePass
if (null === $parameters) {
$r = $this->getReflectionMethod($value, $method);
$class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId;
$method = $r->getName();
$parameters = $r->getParameters();
}

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
/**

View File

@ -16,9 +16,11 @@ use Symfony\Component\DependencyInjection\Compiler\ResolveNamedArgumentsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes;
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsVariadicsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
@ -103,6 +105,7 @@ class ResolveNamedArgumentsPassTest extends TestCase
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "__construct()" has no argument named "$notFound". Check your service definition.
*/
public function testArgumentNotFound()
{
@ -115,6 +118,24 @@ class ResolveNamedArgumentsPassTest extends TestCase
$pass->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes::createTestDefinition1()" has no argument named "$notFound". Check your service definition.
*/
public function testCorrectMethodReportedInException()
{
$container = new ContainerBuilder();
$container->register(FactoryDummyWithoutReturnTypes::class, FactoryDummyWithoutReturnTypes::class);
$definition = $container->register(TestDefinition1::class, TestDefinition1::class);
$definition->setFactory(array(FactoryDummyWithoutReturnTypes::class, 'createTestDefinition1'));
$definition->setArguments(array('$notFound' => '123'));
$pass = new ResolveNamedArgumentsPass();
$pass->process($container);
}
public function testTypedArgument()
{
$container = new ContainerBuilder();

View File

@ -0,0 +1,19 @@
<?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\DependencyInjection\Tests\Fixtures;
class FactoryDummyWithoutReturnTypes
{
public function createTestDefinition1()
{
}
}

View File

@ -1,5 +1,14 @@
<?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\DependencyInjection\Tests\Fixtures;
use Symfony\Component\DependencyInjection\Definition;

View File

@ -30,21 +30,16 @@ class WrappedListenerTest extends TestCase
public function provideListenersToDescribe()
{
$listeners = array(
return array(
array(new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'),
array(array(new FooListener(), 'listen'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
array(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
array('var_dump', 'var_dump'),
array(function () {}, 'closure'),
array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
array(\Closure::fromCallable(function () {}), 'closure'),
);
if (\PHP_VERSION_ID >= 70100) {
$listeners[] = array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen');
$listeners[] = array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic');
$listeners[] = array(\Closure::fromCallable(function () {}), 'closure');
}
return $listeners;
}
}

View File

@ -26,8 +26,8 @@ use Symfony\Component\Form\Extension\Core\CoreExtension;
* ->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
* ->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
* ->add('age', 'Symfony\Component\Form\Extension\Core\Type\IntegerType')
* ->add('gender', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
* 'choices' => array('Male' => 'm', 'Female' => 'f'),
* ->add('color', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
* 'choices' => array('Red' => 'r', 'Blue' => 'b'),
* ))
* ->getForm();
*

View File

@ -443,7 +443,7 @@ class DefaultChoiceListFactoryTest extends TestCase
array($this->obj2, $this->obj3),
null, // label
null, // index
array() // ignored
null // group
);
$this->assertFlatView($view);

View File

@ -31,8 +31,8 @@ class CompoundFormPerformanceTest extends FormPerformanceTestCase
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
->add('gender', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
'choices' => array('male' => 'Male', 'female' => 'Female'),
->add('color', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
'choices' => array('red' => 'Red', 'blue' => 'Blue'),
'required' => false,
))
->add('age', 'Symfony\Component\Form\Extension\Core\Type\NumberType')

View File

@ -1699,15 +1699,23 @@ class Request
} elseif ($this->server->has('REQUEST_URI')) {
$requestUri = $this->server->get('REQUEST_URI');
// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path, only use URL path
$uriComponents = parse_url($requestUri);
if ('' !== $requestUri && '/' === $requestUri[0]) {
// To only use path and query remove the fragment.
if (false !== $pos = strpos($requestUri, '#')) {
$requestUri = substr($requestUri, 0, $pos);
}
} else {
// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
// only use URL path.
$uriComponents = parse_url($requestUri);
if (isset($uriComponents['path'])) {
$requestUri = $uriComponents['path'];
}
if (isset($uriComponents['path'])) {
$requestUri = $uriComponents['path'];
}
if (isset($uriComponents['query'])) {
$requestUri .= '?'.$uriComponents['query'];
if (isset($uriComponents['query'])) {
$requestUri .= '?'.$uriComponents['query'];
}
}
} elseif ($this->server->has('ORIG_PATH_INFO')) {
// IIS 5.0, PHP as CGI

View File

@ -283,6 +283,55 @@ class RequestTest extends TestCase
$this->assertEquals('http://test.com/foo', $request->getUri());
}
/**
* @dataProvider getRequestUriData
*/
public function testGetRequestUri($serverRequestUri, $expected, $message)
{
$request = new Request();
$request->server->add(array(
'REQUEST_URI' => $serverRequestUri,
// For having http://test.com
'SERVER_NAME' => 'test.com',
'SERVER_PORT' => 80,
));
$this->assertSame($expected, $request->getRequestUri(), $message);
$this->assertSame($expected, $request->server->get('REQUEST_URI'), 'Normalize the request URI.');
}
public function getRequestUriData()
{
$message = 'Do not modify the path.';
yield array('/foo', '/foo', $message);
yield array('//bar/foo', '//bar/foo', $message);
yield array('///bar/foo', '///bar/foo', $message);
$message = 'Handle when the scheme, host are on REQUEST_URI.';
yield array('http://test.com/foo?bar=baz', '/foo?bar=baz', $message);
$message = 'Handle when the scheme, host and port are on REQUEST_URI.';
yield array('http://test.com:80/foo', '/foo', $message);
yield array('https://test.com:8080/foo', '/foo', $message);
yield array('https://test.com:443/foo', '/foo', $message);
$message = 'Fragment should not be included in the URI';
yield array('http://test.com/foo#bar', '/foo', $message);
yield array('/foo#bar', '/foo', $message);
}
public function testGetRequestUriWithoutRequiredHeader()
{
$expected = '';
$request = new Request();
$message = 'Fallback to empty URI when headers are missing.';
$this->assertSame($expected, $request->getRequestUri(), $message);
$this->assertSame($expected, $request->server->get('REQUEST_URI'), 'Normalize the request URI.');
}
public function testCreateCheckPrecedence()
{
// server is used by default

View File

@ -144,11 +144,8 @@ EOTXT;
$collector->dump($data);
$line = __LINE__ - 1;
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
if (\PHP_VERSION_ID >= 50400) {
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
} else {
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output);
}
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
ob_start();
$collector->__destruct();

View File

@ -60,7 +60,7 @@ class EsiFragmentRendererTest extends TestCase
$altReference = new ControllerReference('alt_controller', array(), array());
$this->assertEquals(
'<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller&_hash=iPJEdRoUpGrM1ztqByiorpfMPtiW%2FOWwdH1DBUXHhEc%3D" />',
'<esi:include src="/_fragment?_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="/_fragment?_hash=iPJEdRoUpGrM1ztqByiorpfMPtiW%2FOWwdH1DBUXHhEc%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />',
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
);
}

View File

@ -32,7 +32,7 @@ class HIncludeFragmentRendererTest extends TestCase
{
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
$this->assertEquals('<hx:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=BP%2BOzCD5MRUI%2BHJpgPDOmoju00FnzLhP3TGcSHbbBLs%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
$this->assertEquals('<hx:include src="/_fragment?_hash=BP%2BOzCD5MRUI%2BHJpgPDOmoju00FnzLhP3TGcSHbbBLs%3D&amp;_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
}
public function testRenderWithUri()

View File

@ -51,7 +51,7 @@ class SsiFragmentRendererTest extends TestCase
$altReference = new ControllerReference('alt_controller', array(), array());
$this->assertEquals(
'<!--#include virtual="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" -->',
'<!--#include virtual="/_fragment?_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" -->',
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
);
}

View File

@ -21,7 +21,8 @@ class UriSignerTest extends TestCase
$signer = new UriSigner('foobar');
$this->assertContains('?_hash=', $signer->sign('http://example.com/foo'));
$this->assertContains('&_hash=', $signer->sign('http://example.com/foo?foo=bar'));
$this->assertContains('?_hash=', $signer->sign('http://example.com/foo?foo=bar'));
$this->assertContains('&foo=', $signer->sign('http://example.com/foo?foo=bar'));
}
public function testCheck()
@ -45,7 +46,7 @@ class UriSignerTest extends TestCase
$signer = new UriSigner('foobar');
$this->assertSame(
'http://example.com/foo?baz=bay&foo=bar&_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D',
'http://example.com/foo?_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D&baz=bay&foo=bar',
$signer->sign('http://example.com/foo?foo=bar&baz=bay')
);
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
@ -61,4 +62,15 @@ class UriSignerTest extends TestCase
);
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
}
public function testSignerWorksWithFragments()
{
$signer = new UriSigner('foobar');
$this->assertSame(
'http://example.com/foo?_hash=EhpAUyEobiM3QTrKxoLOtQq5IsWyWedoXDPqIjzNj5o%3D&bar=foo&foo=bar#foobar',
$signer->sign('http://example.com/foo?bar=foo&foo=bar#foobar')
);
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?bar=foo&foo=bar#foobar')));
}
}

View File

@ -51,8 +51,9 @@ class UriSigner
}
$uri = $this->buildUrl($url, $params);
$params[$this->parameter] = $this->computeHash($uri);
return $uri.(false === strpos($uri, '?') ? '?' : '&').$this->parameter.'='.$this->computeHash($uri);
return $this->buildUrl($url, $params);
}
/**
@ -75,7 +76,7 @@ class UriSigner
return false;
}
$hash = urlencode($params[$this->parameter]);
$hash = $params[$this->parameter];
unset($params[$this->parameter]);
return $this->computeHash($this->buildUrl($url, $params)) === $hash;
@ -83,7 +84,7 @@ class UriSigner
private function computeHash($uri)
{
return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true)));
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
}
private function buildUrl(array $url, array $params = array())

View File

@ -132,7 +132,7 @@ class IntlDateFormatter
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
*/
public function __construct(?string $locale, int $datetype, int $timetype, $timezone = null, ?int $calendar = self::GREGORIAN, string $pattern = null)
public function __construct(?string $locale, ?int $datetype, ?int $timetype, $timezone = null, ?int $calendar = self::GREGORIAN, string $pattern = null)
{
if ('en' !== $locale && null !== $locale) {
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');

View File

@ -535,7 +535,7 @@ class PropertyAccessor implements PropertyAccessorInterface
} elseif (self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE]) {
$object->{$access[self::ACCESS_NAME]}($value);
} elseif (self::ACCESS_TYPE_NOT_FOUND === $access[self::ACCESS_TYPE]) {
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s" in class "%s"%s.', $property, \get_class($object), isset($access[self::ACCESS_NAME]) ? ': '.$access[self::ACCESS_NAME] : ''));
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s" in class "%s"%s', $property, \get_class($object), isset($access[self::ACCESS_NAME]) ? ': '.$access[self::ACCESS_NAME] : '.'));
} else {
throw new NoSuchPropertyException($access[self::ACCESS_NAME]);
}