8000 [Messenger] Add method HandlerFailedException::hasNestedExceptionOfClass · symfony/symfony@cdbe8c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cdbe8c8

Browse files
author
Timothée BARRAY
committed
[Messenger] Add method HandlerFailedException::hasNestedExceptionOfClass
To know if specific exception are the origin of messenger failure
1 parent 7466148 commit cdbe8c8

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/Symfony/Component/Messenger/Exception/HandlerFailedException.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@ public function getNestedExceptions(): array
4949
{
5050
return $this->exceptions;
5151
}
52+
53+
public function hasNestedExceptionOfClass(string $exceptionClassName): bool
54+
{
55+
return 0 < \count(
56+
array_filter(
57+
$this->exceptions,
58+
function ($exception) use ($exceptionClassName) {
59+
return \get_class($exception) === $exceptionClassName;
60+
}
61+
)
62+
);
63+
}
5264
}

src/Symfony/Component/Messenger/Tests/Exception/HandlerFailedExceptionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\Messenger\Envelope;
77
use Symfony\Component\Messenger\Exception\HandlerFailedException;
8+
use Symfony\Component\Messenger\Tests\Fixtures\MyOwnException;
89

910
class HandlerFailedExceptionTest extends TestCase
1011
{
@@ -28,4 +29,14 @@ public function __construct()
2829
$this->assertIsString($originalException->getCode(), 'Original exception code still with original type (string)');
2930
$this->assertSame($exception->getCode(), $originalException->getCode(), 'Original exception code is not modified');
3031
}
32+
33+
public function testThatNestedExceptionClassAreFound()
34+
{
35+
$envelope = new Envelope(new \stdClass());
36+
$exception = new MyOwnException();
37+
38+
$handlerException = new HandlerFailedException($envelope, [$exception]);
39+
$this->assertTrue($handlerException->hasNestedExceptionOfClass(MyOwnException::class));
40+
$this->assertFalse($handlerException->hasNestedExceptionOfClass(\LogicException::class));
41+
}
3142
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file 7AA6 is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Tests\Fixtures;
13+
14+
class MyOwnException extends \Exception
15+
{
16+
17+
}

0 commit comments

Comments
 (0)
0