8000 bug #15392 Fix missing _route parameter notice in RouterListener logg… · craue/symfony@004c1fd · GitHub
Skip to content

Commit 004c1fd

Browse files
committed
bug symfony#15392 Fix missing _route parameter notice in RouterListener logging case (Haehnchen)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes symfony#15392). Discussion ---------- Fix missing _route parameter notice in RouterListener logging case | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | na | License | MIT | Doc PR | na `\Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest` missed test cases in logging condition. So if we provide routing matches without a `_route` parameter `notice` messages are thrown. In this case i added a check and use `n/a` for empty route names as this is also shown in profiler if it not exists. Commits ------- 0ce91a6 Fix missing _route parameter notice in RouterListener logging case
2 parents ccf52ec + 0ce91a6 commit 004c1fd

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Symfony/Component/HttpKernel/EventListener/RouterListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function onKernelRequest(GetResponseEvent $event)
103103
}
104104

105105
if (null !== $this->logger) {
106-
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
106+
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', isset($parameters['_route']) ? $parameters['_route'] : 'n/a', $this->parametersToString($parameters)));
107107
}
108108

109109
$request->attributes->add($parameters);

src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,34 @@ public function testSubRequestWithDifferentMethod()
120120

121121
$this->assertEquals('GET', $context->getMethod());
122122
}
123+
124+
/**
125+
* @dataProvider getLoggingParameterData
126+
*/
127+
public function testLoggingParameter($parameter, $log)
128+
{
129+
$requestMatcher = $this->getMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface');
130+
$requestMatcher->expects($this->once())
131+
->method('matchRequest')
132+
->will($this->returnValue($parameter));
133+
134+
$logger = $this->getMock('Psr\Log\LoggerInterface');
135+
$logger->expects($this->once())
136+
->method('info')
137+
->with($this->equalTo($log));
138+
139+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
140+
$request = Request::create('http://localhost/');
141+
142+
$listener = new RouterListener($requestMatcher, new RequestContext(), $logger, $this->requestStack);
143+
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
144+
}
145+
146+
public function getLoggingParameterData()
147+
{
148+
return array(
149+
array(array('_route' => 'foo'), 'Matched route "foo".'),
150+
array(array(), 'Matched route "n/a".'),
151+
);
152+
}
123153
}

0 commit comments

Comments
 (0)
0