bug #29310 [MonologBridge] Return empty list for unknown requests (ro0NL)

This PR was merged into the 4.1 branch.

Discussion
----------

[MonologBridge] Return empty list for unknown requests

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Small continuation of #23659. Currently if the specified request is unknown, you'll get all available requests merged. This fixes it.

Commits
-------

69be8e649e [MonologBridge] Return empty list for unknonwn requests
This commit is contained in:
Fabien Potencier 2018-11-26 08:13:50 +01:00
commit d788976d7b
2 changed files with 7 additions and 4 deletions

View File

@ -60,8 +60,8 @@ class DebugProcessor implements DebugLoggerInterface
*/
public function getLogs(/* Request $request = null */)
{
if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->records[$hash = spl_object_hash($request)])) {
return $this->records[$hash];
if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) {
return $this->records[spl_object_hash($request)] ?? array();
}
if (0 === \count($this->records)) {
@ -76,8 +76,8 @@ class DebugProcessor implements DebugLoggerInterface
*/
public function countErrors(/* Request $request = null */)
{
if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->errorCount[$hash = spl_object_hash($request)])) {
return $this->errorCount[$hash];
if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) {
return $this->errorCount[spl_object_hash($request)] ?? 0;
}
return array_sum($this->errorCount);

View File

@ -58,6 +58,9 @@ class DebugProcessorTest extends TestCase
$this->assertCount(2, $processor->getLogs($request));
$this->assertSame(1, $processor->countErrors($request));
$this->assertCount(0, $processor->getLogs(new Request()));
$this->assertSame(0, $processor->countErrors(new Request()));
}
private function getRecord($level = Logger::WARNING, $message = 'test')