Skip to content

Commit 3c0747b

Browse files
authored
Skipped PHP internal errors serialization (#82)
1 parent 1d77384 commit 3c0747b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/lib/Output/ValueObjectVisitorDispatcher.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
namespace EzSystems\EzPlatformRest\Output;
88

9+
use Error;
10+
911
/**
1012
* Dispatches value objects to a visitor depending on the class name.
1113
*/
@@ -55,6 +57,11 @@ public function addVisitor($visitedClassName, ValueObjectVisitor $visitor)
5557
*/
5658
public function visit($data)
5759
{
60+
if ($data instanceof Error) {
61+
// Skip internal PHP errors serialization
62+
throw $data;
63+
}
64+
5865
if (!is_object($data)) {
5966
throw new Exceptions\InvalidTypeException($data);
6067
}

tests/lib/Output/ValueObjectVisitorDispatcherTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace EzSystems\EzPlatformRest\Tests\Output;
88

9+
use Error;
910
use EzSystems\EzPlatformRest;
1011
use EzSystems\EzPlatformRest\Output\Exceptions\InvalidTypeException;
1112
use EzSystems\EzPlatformRest\Output\Exceptions\NoVisitorFoundException;
@@ -101,6 +102,14 @@ public function testVisitValueObjectSecondRuleParentMatch()
101102
$dispatcher->visit($data);
102103
}
103104

105+
public function testVisitError(): void
106+
{
107+
$this->expectException(Error::class);
108+
109+
$dispatcher = $this->getValueObjectDispatcher();
110+
$dispatcher->visit($this->createMock(Error::class));
111+
}
112+
104113
/**
105114
* @return Common\Output\ValueObjectVisitorDispatcher
106115
*/

0 commit comments

Comments
 (0)