Skip to content

Commit c38c8de

Browse files
yoannrenardderrabus
authored andcommitted
[DependencyInjection] Fix AutowiringFailedException::getMessageCallback() when the message is not a closure
1 parent c3176dd commit c38c8de

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Exception/AutowiringFailedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class AutowiringFailedException extends RuntimeException
1818
{
1919
private string $serviceId;
20-
private ?\Closure $messageCallback;
20+
private ?\Closure $messageCallback = null;
2121

2222
public function __construct(string $serviceId, string|\Closure $message = '', int $code = 0, \Throwable $previous = null)
2323
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Exception;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
7+
8+
final class AutowiringFailedExceptionTest extends TestCase
9+
{
10+
public function testGetMessageCallbackWhenMessageIsNotANotClosure()
11+
{
12+
$exception = new AutowiringFailedException(
13+
'App\DummyService',
14+
'Cannot autowire service "App\DummyService": argument "$email" of method "__construct()" is type-hinted "string", you should configure its value explicitly.'
15+
);
16+
17+
self::assertNull($exception->getMessageCallback());
18+
}
19+
}

0 commit comments

Comments
 (0)