Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit36f8fe5

Browse files
bug#43781 [Messenger] FixTraceableMessageBus implementation so it can compute caller even when used within a callback (Ocramius)
This PR was squashed before being merged into the 4.4 branch.Discussion----------[Messenger] Fix `TraceableMessageBus` implementation so it can compute caller even when used within a callback| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets || License | MIT| Doc PR |Quoting commits:>> This test shows that `array_map([new TraceableMessageBus(...), 'dispatch'], $messages)` does not work at all,> because `debug_backtrace()` is used in internals to compute the call-site, and it is not considering the fact> that the caller may be:>> * an internal PHP function> * a callback (this example test scenario)> * generated code (`eval()` result)>> The output of such a failure:>> ```> 1) Symfony\Component\Messenger\Tests\TraceableMessageBusTest::testItTracesExceptionsWhenMessageBusIsFiredFromArrayCallback> Undefined array key "line">> /app/src/Symfony/Component/Messenger/TraceableMessageBus.php:66> /app/src/Symfony/Component/Messenger/TraceableMessageBus.php:36> /app/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php:175> ```>> To be on the safe side, also removed `compact()` usage, which was making everything> much muddier and harder to comprehend.Commits-------1423229 [Messenger] Fix `TraceableMessageBus` implementation so it can compute caller even when used within a callback
2 parents822e9e5 +1423229 commit36f8fe5

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

‎src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,22 @@ public function testItTracesExceptions()
156156
],
157157
],$actualTracedMessage);
158158
}
159+
160+
publicfunctiontestItTracesExceptionsWhenMessageBusIsFiredFromArrayCallback()
161+
{
162+
$message =newDummyMessage('Hello');
163+
$exception =new \RuntimeException();
164+
165+
$bus =$this->createMock(MessageBusInterface::class);
166+
$bus->expects($this->once())
167+
->method('dispatch')
168+
->with($message)
169+
->willThrowException($exception);
170+
171+
$traceableBus =newTraceableMessageBus($bus);
172+
173+
$this->expectExceptionObject($exception);
174+
175+
array_map([$traceableBus,'dispatch'], [$message]);
176+
}
159177
}

‎src/Symfony/Component/Messenger/TraceableMessageBus.php‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ private function getCaller(): array
6262
{
6363
$trace =debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS,8);
6464

65-
$file =$trace[1]['file'];
66-
$line =$trace[1]['line'];
65+
$file =$trace[1]['file'] ??null;
66+
$line =$trace[1]['line'] ??null;
6767

6868
$handleTraitFile = (new \ReflectionClass(HandleTrait::class))->getFileName();
6969
$found =false;
@@ -97,9 +97,12 @@ private function getCaller(): array
9797
}
9898
}
9999

100-
$name =str_replace('\\','/',$file);
101-
$name =substr($name,strrpos($name,'/') +1);
100+
$name =str_replace('\\','/', (string)$file);
102101

103-
returncompact('name','file','line');
102+
return [
103+
'name' =>substr($name,strrpos($name,'/') +1),
104+
'file' =>$file,
105+
'line' =>$line,
106+
];
104107
}
105108
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp