From cf850c1a151bc67edf07166cfe3024a26fd0e8b8 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Thu, 6 Dec 2018 19:19:56 +0100 Subject: [PATCH 01/12] [HttpFoundation] Fix request uri when it starts with double slashes --- .../Component/HttpFoundation/Request.php | 22 ++++++--- .../HttpFoundation/Tests/RequestTest.php | 49 +++++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 89611660add2..10687e35c901 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1837,15 +1837,23 @@ protected function prepareRequestUri() } 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 diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 539bb69cfb7c..f2c8f94f7723 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -283,6 +283,55 @@ public function testCreateWithRequestUri() $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 From b9ece6bde7a204b6afe94fc7978181a14eae2a22 Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Mon, 24 Dec 2018 12:22:50 +0000 Subject: [PATCH 02/12] [HttpKernel] Correctly Render Signed URIs Containing Fragments Rebuild the URL with the computed hash instead of appending it onto the end of the URI, preventing incorrect formatting when dealing with URIs containing fragments. --- .../Tests/Fragment/EsiFragmentRendererTest.php | 2 +- .../Fragment/HIncludeFragmentRendererTest.php | 2 +- .../Tests/Fragment/SsiFragmentRendererTest.php | 2 +- .../Component/HttpKernel/Tests/UriSignerTest.php | 16 ++++++++++++++-- src/Symfony/Component/HttpKernel/UriSigner.php | 7 ++++--- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php index 00d796d52051..51e5756203ee 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php @@ -72,7 +72,7 @@ public function testRenderControllerReference() $altReference = new ControllerReference('alt_controller', array(), array()); $this->assertEquals( - '', + '', $strategy->render($reference, $request, array('alt' => $altReference))->getContent() ); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php index e3926708c1b5..68f8ded4e971 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -32,7 +32,7 @@ public function testRenderWithControllerAndSigner() { $strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo')); - $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); + $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); } public function testRenderWithUri() diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/SsiFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/SsiFragmentRendererTest.php index f725803118f7..ff98fd2616ee 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/SsiFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/SsiFragmentRendererTest.php @@ -51,7 +51,7 @@ public function testRenderControllerReference() $altReference = new ControllerReference('alt_controller', array(), array()); $this->assertEquals( - '', + '', $strategy->render($reference, $request, array('alt' => $altReference))->getContent() ); } diff --git a/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php b/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php index 84ec19f70db2..9b7fe08a9990 100644 --- a/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php @@ -21,7 +21,8 @@ public function testSign() $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 @@ public function testCheckWithDifferentArgSeparator() $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 @@ public function testCheckWithDifferentParameter() ); $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'))); + } } diff --git a/src/Symfony/Component/HttpKernel/UriSigner.php b/src/Symfony/Component/HttpKernel/UriSigner.php index 28459b4ecd39..63d1a0856f4b 100644 --- a/src/Symfony/Component/HttpKernel/UriSigner.php +++ b/src/Symfony/Component/HttpKernel/UriSigner.php @@ -51,8 +51,9 @@ public function sign($uri) } $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 @@ public function check($uri) 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 @@ public function check($uri) 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()) From b8f6390ef924b9f48c64de727a3b57bc9384923d Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 4 Jan 2019 02:14:05 +0300 Subject: [PATCH 03/12] Fixed groupBy argument value in DefaultChoiceListFactoryTest --- .../Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index 245024824083..983fdd27287a 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -443,7 +443,7 @@ public function testCreateViewFlatGroupByEmpty() array($this->obj2, $this->obj3), null, // label null, // index - array() // ignored + null // group ); $this->assertFlatView($view); From 99448c6e786b95de425a658585fff5dbd73d69c6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 4 Jan 2019 14:48:06 +0100 Subject: [PATCH 04/12] remove no longer needed PHP version checks --- .github/build-packages.php | 2 +- .../Tests/DataCollector/DumpDataCollectorTest.php | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/build-packages.php b/.github/build-packages.php index b09cea2fe230..e61eae51df55 100644 --- a/.github/build-packages.php +++ b/.github/build-packages.php @@ -16,7 +16,7 @@ $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)) { diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php index fd5ea11e720b..341ddc6d8ddd 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php @@ -125,11 +125,8 @@ public function testFlushNothingWhenDataDumperIsProvided() $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(); From 7a132fe1561efb31d861b5bfbc69fa6583a3f3e2 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 4 Jan 2019 16:09:47 +0100 Subject: [PATCH 05/12] remove no longer needed PHP version checks --- .../Tests/Console/Descriptor/ObjectsProvider.php | 9 ++------- .../Tests/Debug/WrappedListenerTest.php | 13 ++++--------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 12e81898bf5f..7cb887684fea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -155,7 +155,7 @@ public static function getEventDispatchers() 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'), @@ -163,13 +163,8 @@ public static function getCallables() '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; } } diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php index f743f148d2d2..3847a1553c76 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php @@ -30,21 +30,16 @@ public function testListenerDescription(callable $listener, $expected) 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; } } From fdf98af58b80a0e5ec9c7a0f0a104d23121e5f2b Mon Sep 17 00:00:00 2001 From: Aaron Somi Date: Sat, 5 Jan 2019 06:17:43 +0000 Subject: [PATCH 06/12] Changed gender choice types to color Signed-off-by: Aaron Somi --- src/Symfony/Component/Form/Forms.php | 4 ++-- .../Component/Form/Tests/CompoundFormPerformanceTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Forms.php b/src/Symfony/Component/Form/Forms.php index c316eb083060..9b352aa5dd20 100644 --- a/src/Symfony/Component/Form/Forms.php +++ b/src/Symfony/Component/Form/Forms.php @@ -26,8 +26,8 @@ * ->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(); * diff --git a/src/Symfony/Component/Form/Tests/CompoundFormPerformanceTest.php b/src/Symfony/Component/Form/Tests/CompoundFormPerformanceTest.php index e0a333069c00..e5d8e9a9877e 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormPerformanceTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormPerformanceTest.php @@ -31,8 +31,8 @@ public function testArrayBasedForm() $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') From 922885c89243fd1a796b1fe9daa63f428fdd92cb Mon Sep 17 00:00:00 2001 From: Wojciech Gorczyca Date: Thu, 27 Dec 2018 13:08:49 +0100 Subject: [PATCH 07/12] [DI] Fixed wrong factory method in exception --- .../Compiler/ResolveNamedArgumentsPass.php | 1 + .../ResolveNamedArgumentsPassTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index f9431b21d890..b5b832c83f0b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -49,6 +49,7 @@ protected function processValue($value, $isRoot = false) if (null === $parameters) { $r = $this->getReflectionMethod($value, $method); $class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId; + $method = $r->getName(); $parameters = $r->getParameters(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 4665ee96f5f3..b900c41a8c4f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -16,9 +16,11 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; +use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy; 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 @@ -103,6 +105,7 @@ public function testClassNoConstructor() /** * @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 @@ public function testArgumentNotFound() $pass->process($container); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition. + */ + public function testCorrectMethodReportedInException() + { + $container = new ContainerBuilder(); + + $container->register(FactoryDummy::class, FactoryDummy::class); + + $definition = $container->register(TestDefinition1::class, TestDefinition1::class); + $definition->setFactory(array(FactoryDummy::class, 'create')); + $definition->setArguments(array('$notFound' => '123')); + + $pass = new ResolveNamedArgumentsPass(); + $pass->process($container); + } + public function testTypedArgument() { $container = new ContainerBuilder(); From 16ebeb395f4ff23ccd5bd8c41a3b508386e91398 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 4 Jan 2019 21:31:51 +0100 Subject: [PATCH 08/12] [Intl] make type-hinted arguments nullable --- src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index 6cae285a527e..69ab7c00c486 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -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'); From 0a3d3d4dff2870056b86b04903bacbb02a854f2a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 5 Jan 2019 08:48:11 +0100 Subject: [PATCH 09/12] bug #29697 [DI] Fixed wrong factory method in exception (Wojciech Gorczyca) This PR was submitted for the 4.2 branch but it was merged into the 4.1 branch instead (closes #29697). Discussion ---------- [DI] Fixed wrong factory method in exception | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29678 | License | MIT | Doc PR | n/a When a service definition with a factory defines invalid arguments, the [resulting exception message ](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php#L70)incorrectly specifies the factory constructor instead of the factory method as not having the specified named arguments. Commits ------- 922885c892 [DI] Fixed wrong factory method in exception --- .../Compiler/ResolveNamedArgumentsPass.php | 1 + .../ResolveNamedArgumentsPassTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 90cf64adbec3..36980df09fd9 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -49,6 +49,7 @@ protected function processValue($value, $isRoot = false) if (null === $parameters) { $r = $this->getReflectionMethod($value, $method); $class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId; + $method = $r->getName(); $parameters = $r->getParameters(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index fe681b41df78..087d7ab79508 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -16,8 +16,10 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; +use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; +use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1; /** * @author Kévin Dunglas @@ -102,6 +104,7 @@ public function testClassNoConstructor() /** * @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() { @@ -114,6 +117,24 @@ public function testArgumentNotFound() $pass->process($container); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition. + */ + public function testCorrectMethodReportedInException() + { + $container = new ContainerBuilder(); + + $container->register(FactoryDummy::class, FactoryDummy::class); + + $definition = $container->register(TestDefinition1::class, TestDefinition1::class); + $definition->setFactory(array(FactoryDummy::class, 'create')); + $definition->setArguments(array('$notFound' => '123')); + + $pass = new ResolveNamedArgumentsPass(); + $pass->process($container); + } + public function testTypedArgument() { $container = new ContainerBuilder(); From 4c04328b59a2c3c3a2fa1658cbed7cbc9e5d8f2a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 5 Jan 2019 11:05:43 +0100 Subject: [PATCH 10/12] remove doubled dot from exception message --- src/Symfony/Component/PropertyAccess/PropertyAccessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 2db7357d6488..ad44cd5e4519 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -535,7 +535,7 @@ private function writeProperty($zval, $property, $value) } 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]); } From 6d84aeb131684fdc639d3a8a5e20912781622a5f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 5 Jan 2019 13:04:54 +0100 Subject: [PATCH 11/12] fix tests on PHP 5 --- .../Tests/Compiler/ResolveNamedArgumentsPassTest.php | 4 ++-- .../DependencyInjection/Tests/Fixtures/FactoryDummy.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 087d7ab79508..c994ff99c3c1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -119,7 +119,7 @@ public function testArgumentNotFound() /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition. + * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::createTestDefinition1()" has no argument named "$notFound". Check your service definition. */ public function testCorrectMethodReportedInException() { @@ -128,7 +128,7 @@ public function testCorrectMethodReportedInException() $container->register(FactoryDummy::class, FactoryDummy::class); $definition = $container->register(TestDefinition1::class, TestDefinition1::class); - $definition->setFactory(array(FactoryDummy::class, 'create')); + $definition->setFactory(array(FactoryDummy::class, 'createTestDefinition1')); $definition->setArguments(array('$notFound' => '123')); $pass = new ResolveNamedArgumentsPass(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php index da984b562a39..04aa5fa28280 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php @@ -33,6 +33,10 @@ public static function createSelf(): self public static function createParent(): parent { } + + public function createTestDefinition1() + { + } } class FactoryParent From c8ced3a9a2e28a6e53ac554d3b8cbf2c18f1fb65 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 5 Jan 2019 13:23:38 +0100 Subject: [PATCH 12/12] properly fix tests on PHP 5 --- .../ResolveNamedArgumentsPassTest.php | 8 ++++---- .../Tests/Fixtures/FactoryDummy.php | 4 ---- .../FactoryDummyWithoutReturnTypes.php | 19 +++++++++++++++++++ .../Tests/Fixtures/TestDefinition1.php | 18 ++++++++++++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummyWithoutReturnTypes.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestDefinition1.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index c994ff99c3c1..17b8ebf31a00 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; -use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy; +use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes; use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1; @@ -119,16 +119,16 @@ public function testArgumentNotFound() /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::createTestDefinition1()" has no argument named "$notFound". Check your service definition. + * @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(FactoryDummy::class, FactoryDummy::class); + $container->register(FactoryDummyWithoutReturnTypes::class, FactoryDummyWithoutReturnTypes::class); $definition = $container->register(TestDefinition1::class, TestDefinition1::class); - $definition->setFactory(array(FactoryDummy::class, 'createTestDefinition1')); + $definition->setFactory(array(FactoryDummyWithoutReturnTypes::class, 'createTestDefinition1')); $definition->setArguments(array('$notFound' => '123')); $pass = new ResolveNamedArgumentsPass(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php index 04aa5fa28280..da984b562a39 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummy.php @@ -33,10 +33,6 @@ public static function createSelf(): self public static function createParent(): parent { } - - public function createTestDefinition1() - { - } } class FactoryParent diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummyWithoutReturnTypes.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummyWithoutReturnTypes.php new file mode 100644 index 000000000000..f480a668b5c2 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FactoryDummyWithoutReturnTypes.php @@ -0,0 +1,19 @@ + + * + * 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() + { + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestDefinition1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestDefinition1.php new file mode 100644 index 000000000000..8ec76a9de63c --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TestDefinition1.php @@ -0,0 +1,18 @@ + + * + * 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; + +class TestDefinition1 extends Definition +{ +}