From 0ce91a6019ef8ccebaea3b75fdb31f4aec671832 Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Tue, 28 Jul 2015 17:20:14 +0200 Subject: [PATCH 1/2] Fix missing _route parameter notice in RouterListener logging case --- .../EventListener/RouterListener.php | 2 +- .../EventListener/RouterListenerTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php index 2e9cb7b6bb..704800a5cb 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php @@ -103,7 +103,7 @@ class RouterListener implements EventSubscriberInterface } if (null !== $this->logger) { - $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters))); + $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', isset($parameters['_route']) ? $parameters['_route'] : 'n/a', $this->parametersToString($parameters))); } $request->attributes->add($parameters); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php index 66fe6bd55d..fd66a602a6 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php @@ -120,4 +120,34 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase $this->assertEquals('GET', $context->getMethod()); } + + /** + * @dataProvider getLoggingParameterData + */ + public function testLoggingParameter($parameter, $log) + { + $requestMatcher = $this->getMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface'); + $requestMatcher->expects($this->once()) + ->method('matchRequest') + ->will($this->returnValue($parameter)); + + $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger->expects($this->once()) + ->method('info') + ->with($this->equalTo($log)); + + $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); + $request = Request::create('http://localhost/'); + + $listener = new RouterListener($requestMatcher, new RequestContext(), $logger, $this->requestStack); + $listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + } + + public function getLoggingParameterData() + { + return array( + array(array('_route' => 'foo'), 'Matched route "foo".'), + array(array(), 'Matched route "n/a".'), + ); + } } From 6b02601e7b3368b9725bd3b37829ac877d124821 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 30 Jul 2015 09:37:09 +0200 Subject: [PATCH 2/2] Fix merge --- .../HttpKernel/Tests/EventListener/RouterListenerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php index fd66a602a6..271aaf5b2b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php @@ -139,15 +139,15 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $request = Request::create('http://localhost/'); - $listener = new RouterListener($requestMatcher, new RequestContext(), $logger, $this->requestStack); + $listener = new RouterListener($requestMatcher, new RequestContext(), $logger); $listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); } public function getLoggingParameterData() { return array( - array(array('_route' => 'foo'), 'Matched route "foo".'), - array(array(), 'Matched route "n/a".'), + array(array('_route' => 'foo'), 'Matched route "foo" (parameters: "_route": "foo")'), + array(array(), 'Matched route "n/a" (parameters: )'), ); } }