8000 Merge branch '4.1' into 4.2 · symfony/symfony@f272693 · GitHub
[go: up one dir, main page]

Skip to content

Commit f272693

Browse files
author
Robin Chalas
committed
Merge branch '4.1' into 4.2
* 4.1: 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 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
2 parents b309344 + 1fa24cb commit f272693

File tree

20 files changed

+151
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
$mergeBase = trim(shell_exec(sprintf('git merge-base "%s" HEAD', array_shift($dirs))));
1717

1818
$packages = array();
19-
$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0;
19+
$flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
2020

2121
foreach ($dirs as $k => $dir) {
2222
if (!system("git diff --name-only $mergeBase -- $dir", $exitStatus)) {
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,16 @@ public static function getEventDispatchers()
163163

164164
public static function getCallables()
165165
{
166-
$callables = array(
166+
return array(
167167
'callable_1' => 'array_key_exists',
168168
'callable_2' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'),
169169
'callable_3' => array(new CallableClass(), 'method'),
170170
'callable_4' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass::staticMethod',
171171
'callable_5' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ExtendedCallableClass', 'parent::staticMethod'),
172172
'callable_6' => function () { return 'Closure'; },
173173
'callable_7' => new CallableClass(),
174+
'callable_from_callable' => \Closure::fromCallable(new CallableClass()),
174175
);
175-
176-
if (\PHP_VERSION_ID >= 70100) {
177-
$callables['callable_from_callable'] = \Closure::fromCallable(new CallableClass());
178-
}
179-
180-
return $callables;
181176
}
182177
}
183178

Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function processValue($value, $isRoot = false)
4949
if (null === $parameters) {
5050
$r = $this->getReflectionMethod($value, $method);
5151
$class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId;
52+
$method = $r->getName();
5253
$parameters = $r->getParameters();
5354
}
5455

Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
19+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes;
1920
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
2021
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsVariadicsDummy;
2122
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
23+
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;
2224

2325
/**
2426
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -103,6 +105,7 @@ public function testClassNoConstructor()
103105

104106
/**
105107
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
108+
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "__construct()" has no argument named "$notFound". Check your service definition.
106109
*/
107110
public function testArgumentNotFound()
108111
{
@@ -115,6 +118,24 @@ public function testArgumentNotFound()
115118
$pass->process($container);
116119
}
117120

121+
/**
122+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
123+
* @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.
124+
*/
125+
public function testCorrectMethodReportedInException()
126+
{
127+
$container = new ContainerBuilder();
128+
129+
$container->register(FactoryDummyWithoutReturnTypes::class, FactoryDummyWithoutReturnTypes::class);
130+
131+
$definition = $container->register(TestDefinition1::class, TestDefinition1::class);
132+
$definition->setFactory(array(FactoryDummyWithoutReturnTypes::class, 'createTestDefinition1'));
133+
$definition->setArguments(array('$notFound' => '123'));
134+
135+
$pass = new ResolveNamedArgumentsPass();
136+
$pass->process($container);
137+
}
138+
118139
public function testTypedArgument()
119140
{
120141
$container = new ContainerBuilder();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
class FactoryDummyWithoutReturnTypes
15+
{
16+
public function createTestDefinition1()
17+
{
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
413

514
use Symfony\Component\DependencyInjection\Definition;
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,16 @@ public function testListenerDescription(callable $listener, $expected)
3030

3131
public function provideListenersToDescribe()
3232
{
33-
$listeners = array(
33+
return array(
3434
array(new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'),
3535
array(array(new FooListener(), 'listen'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
3636
array(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
3737
array('var_dump', 'var_dump'),
3838
array(function () {}, 'closure'),
39+
array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
40+
array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
41+
array(\Closure::fromCallable(function () {}), 'closure'),
3942
);
40-
41-
if (\PHP_VERSION_ID >= 70100) {
42-
$listeners[] = array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen');
43-
$listeners[] = array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic');
44-
$listeners[] = array(\Closure::fromCallable(function () {}), 'closure');
45-
}
46-
47-
return $listeners;
4843
}
4944
}
5045

Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* ->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
2727
* ->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
2828
* ->add('age', 'Symfony\Component\Form\Extension\Core\Type\IntegerType')
29-
* ->add('gender', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
30-
* 'choices' => array('Male' => 'm', 'Female' => 'f'),
29+
* ->add('color', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
30+
* 'choices' => array('Red' => 'r', 'Blue' => 'b'),
3131
* ))
3232
* ->getForm();
3333
*
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function testCreateViewFlatGroupByEmpty()
443443
array($this->obj2, $this->obj3),
444444
null, // label
445445
null, // index
446-
array() // ignored
446+
null // group
447447
);
448448

449449
$this->assertFlatView($view);
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testArrayBasedForm()
3131
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
3232
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
3333
->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
34-
->add('gender', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
35-
'choices' => array('male' => 'Male', 'female' => 'Female'),
34+
->add('color', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
35+
'choices' => array('red' => 'Red', 'blue' => 'Blue'),
3636
'required' => false,
3737
))
3838
->add('age', 'Symfony\Component\Form\Extension\Core\Type\NumberType')
Original file line numberDiff line numberDiff line change
@@ -1699,15 +1699,23 @@ protected function prepareRequestUri()
16991699
} elseif ($this->server->has('REQUEST_URI')) {
17001700
$requestUri = $this->server->get('REQUEST_URI');
17011701

1702-
// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path, only use URL path
1703-
$uriComponents = parse_url($requestUri);
1702+
if ('' !== $requestUri && '/' === $requestUri[0]) {
1703+
// To only use path and query remove the fragment.
1704+
if (false !== $pos = strpos($requestUri, '#')) {
1705+
$requestUri = substr($requestUri, 0, $pos);
1706+
}
1707+
} else {
1708+
// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
1709+
// only use URL path.
1710+
$uriComponents = parse_url($requestUri);
17041711

1705-
if (isset($uriComponents['path'])) {
1706-
$requestUri = $uriComponents['path'];
1707-
}
1712+
if (isset($uriComponents['path'])) {
1713+
$requestUri = $uriComponents['path'];
1714+
}
17081715

1709-
if (isset($uriComponents['query'])) {
1710-
$requestUri .= '?'.$uriComponents['query'];
1716+
if (isset($uriComponents['query'])) {
1717+
$requestUri .= '?'.$uriComponents['query'];
1718+
}
17111719
}
17121720
} elseif ($this->server->has('ORIG_PATH_INFO')) {
17131721
// IIS 5.0, PHP as CGI
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,55 @@ public function testCreateWithRequestUri()
283283
$this->assertEquals('http://test.com/foo', $request->getUri());
284284
}
285285

286+
/**
287+
* @dataProvider getRequestUriData
288+
*/
289+
public function testGetRequestUri($serverRequestUri, $expected, $message)
290+
{
291+
$request = new Request();
292+
$request->server->add(array(
293+
'REQUEST_URI' => $serverRequestUri,
294+
295+
// For having http://test.com
296+
'SERVER_NAME' => 'test.com',
297+
'SERVER_PORT' => 80,
298+
));
299+
300+
$this->assertSame($expected, $request->getRequestUri(), $message);
301+
$this->assertSame($expected, $request->server->get('REQUEST_URI'), 'Normalize the request URI.');
302+
}
303+
304+
public function getRequestUriData()
305+
{
306+
$message = 'Do not modify the path.';
307+
yield array('/foo', '/foo', $message);
308+
yield array('//bar/foo', '//bar/foo', $message);
309+
yield array('///bar/foo', '///bar/foo', $message);
310+
311+
$message = 'Handle when the scheme, host are on REQUEST_URI.';
312+
yield array('http://test.com/foo?bar=baz', '/foo?bar=baz', $message);
313+
314+
$message = 'Handle when the scheme, host and port are on REQUEST_URI.';
315+
yield array('http://test.com:80/foo', '/foo', $message);
316+
yield array('https://test.com:8080/foo', '/foo', $message);
317+
yield array('https://test.com:443/foo', '/foo', $message);
318+
319+
$message = 'Fragment should not be included in the URI';
320+
yield array('http://test.com/foo#bar', '/foo', $message);
321+
yield array('/foo#bar', '/foo', $message);
322+
}
323+
324+
public function testGetRequestUriWithoutRequiredHeader()
325+
{
326+
$expected = '';
327+
328+
$request = new Request();
329+
330+
$message = 'Fallback to empty URI when headers are missing.';
331+
$this->assertSame($expected, $request->getRequestUri(), $message);
332+
$this->assertSame($expected, $request->server->get('REQUEST_URI'), 'Normalize the request URI.');
333+
}
334+
286335
public function testCreateCheckPrecedence()
287336
{
288337
// server is used by default
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,8 @@ public function testFlushNothingWhenDataDumperIsProvided()
144144
$collector->dump($data);
145145
$line = __LINE__ - 1;
146146
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
147-
if (\PHP_VERSION_ID >= 50400) {
148-
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
149-
} else {
150-
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output);
151-
}
147+
148+
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
152149

153150
ob_start();
154151
$collector->__destruct();
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testRenderControllerReference()
6060
$altReference = new ControllerReference('alt_controller', array(), array());
6161

6262
$this->assertEquals(
63-
'<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" />',
63+
'<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" />',
6464
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
6565
);
6666
}
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testRenderWithControllerAndSigner()
3232
{
3333
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
3434

35-
$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());
35+
$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());
3636
}
3737

3838
public function testRenderWithUri()
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testRenderControllerReference()
5151
$altReference = new ControllerReference('alt_controller', array(), array());
5252

5353
$this->assertEquals(
54-
'<!--#include virtual="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" -->',
54+
'<!--#include virtual="/_fragment?_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" -->',
5555
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
5656
);
5757
}
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function testSign()
2121
$signer = new UriSigner('foobar');
2222

2323
$this->assertContains('?_hash=', $signer->sign('http://example.com/foo'));
24-
$this->assertContains('&_hash=', $signer->sign('http://example.com/foo?foo=bar'));
24+
$this->assertContains('?_hash=', $signer->sign('http://example.com/foo?foo=bar'));
25+
$this->assertContains('&foo=', $signer->sign('http://example.com/foo?foo=bar'));
2526
}
2627

2728
public function testCheck()
@@ -45,7 +46,7 @@ public function testCheckWithDifferentArgSeparator()
4546
$signer = new UriSigner('foobar');
4647

4748
$this->assertSame(
48-
'http://example.com/foo?baz=bay&foo=bar&_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D',
49+
'http://example.com/foo?_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D&baz=bay&foo=bar',
4950
$signer->sign('http://example.com/foo?foo=bar&baz=bay')
5051
);
5152
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
@@ -61,4 +62,15 @@ public function testCheckWithDifferentParameter()
6162
);
6263
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
6364
}
65+
66+
public function testSignerWorksWithFragments()
67+
{
68+
$signer = new UriSigner('foobar');
69+
70+
$this->assertSame(
71+
'http://example.com/foo?_hash=EhpAUyEobiM3QTrKxoLOtQq5IsWyWedoXDPqIjzNj5o%3D&bar=foo&foo=bar#foobar',
72+
$signer->sign('http://example.com/foo?bar=foo&foo=bar#foobar')
73+
);
74+
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?bar=foo&foo=bar#foobar')));
75+
}
6476
}
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public function sign($uri)
5151
}
5252

5353
$uri = $this->buildUrl($url, $params);
54+
$params[$this->parameter] = $this->computeHash($uri);
5455

55-
return $uri.(false === strpos($uri, '?') ? '?' : '&').$this->parameter.'='.$this->computeHash($uri);
56+
return $this->buildUrl($url, $params);
5657
}
5758

5859
/**
@@ -75,15 +76,15 @@ public function check($uri)
7576
return false;
7677
}
7778

78-
$hash = urlencode($params[$this->parameter]);
79+
$hash = $params[$this->parameter];
7980
unset($params[$this->parameter]);
8081

8182
return $this->computeHash($this->buildUrl($url, $params)) === $hash;
8283
}
8384

8485
private function computeHash($uri)
8586
{
86-
return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true)));
87+
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
8788
}
8889

8990
private function buildUrl(array $url, array $params = array())
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class IntlDateFormatter
132132
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
133133
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
134134
*/
135-
public function __construct(?string $locale, int $datetype, int $timetype, $timezone = null, ?int $calendar = self::GREGORIAN, string $pattern = null)
135+
public function __construct(?string $locale, ?int $datetype, ?int $timetype, $timezone = null, ?int $calendar = self::GREGORIAN, string $pattern = null)
136136
{
137137
if ('en' !== $locale && null !== $locale) {
138138< 9DFE /code>
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ private function writeProperty($zval, $property, $value)
535535
} elseif (self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE]) {
536536
$object->{$access[self::ACCESS_NAME]}($value);
537537
} elseif (self::ACCESS_TYPE_NOT_FOUND === $access[self::ACCESS_TYPE]) {
538-
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] : ''));
538+
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] : '.'));
539539
} else {
540540
throw new NoSuchPropertyException($access[self::ACCESS_NAME]);
541541
}