Skip to content

Commit 49a9955

Browse files
authored
Merge pull request #205 from remicollet/issue-74
don't rely on 'args' in trace, not available in 7.4
2 parents 50e77ac + e8384e4 commit 49a9955

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/DocBlock/Tags/InvalidTag.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ static function (&$value) : void {
102102
};
103103

104104
do {
105-
$trace = array_map(
106-
static function (array $call) use ($flatten) : array {
107-
$call['args'] = $call['args'] ?? [];
108-
109-
array_walk_recursive($call['args'], $flatten);
110-
111-
return $call;
112-
},
113-
$exception->getTrace()
114-
);
105+
$trace = $exception->getTrace();
106+
if (isset($trace[0]['args'])) {
107+
$trace = array_map(
108+
static function (array $call) use ($flatten) : array {
109+
array_walk_recursive($call['args'], $flatten);
110+
return $call;
111+
},
112+
$trace
113+
);
114+
}
115115
$traceProperty->setValue($exception, $trace);
116116
$exception = $exception->getPrevious();
117117
} while ($exception !== null);

tests/unit/DocBlock/Tags/InvalidTagTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ public function testCreationWithErrorContainingClosure() : void
5656
self::assertSame('name', $tag->getName());
5757
self::assertSame('@name Body', $tag->render());
5858
self::assertSame($parentException, $tag->getException());
59-
self::assertStringStartsWith('(Closure at', $tag->getException()->getPrevious()->getTrace()[0]['args'][0]);
60-
self::assertStringContainsString(__FILE__, $tag->getException()->getPrevious()->getTrace()[0]['args'][0]);
59+
$trace = $tag->getException()->getPrevious()->getTrace();
60+
if (isset($trace[0]['args'])) { // Not set by default on 7.4
61+
self::assertStringStartsWith('(Closure at', $trace[0]['args'][0]);
62+
self::assertStringContainsString(__FILE__, $trace[0]['args'][0]);
63+
}
6164
self::assertEquals($parentException, unserialize(serialize($parentException)));
6265
}
6366
}
@@ -81,10 +84,13 @@ public function testCreationWithErrorContainingResource() : void
8184
self::assertSame('name', $tag->getName());
8285
self::assertSame('@name Body', $tag->render());
8386
self::assertSame($parentException, $tag->getException());
84-
self::assertStringStartsWith(
85-
'resource(stream)',
86-
$tag->getException()->getPrevious()->getTrace()[0]['args'][0]
87-
);
87+
$trace = $tag->getException()->getPrevious()->getTrace();
88+
if (isset($trace[0]['args'])) { // Not set by default on 7.4
89+
self::assertStringStartsWith(
90+
'resource(stream)',
91+
$trace[0]['args'][0]
92+
);
93+
}
8894
self::assertEquals($parentException, unserialize(serialize($parentException)));
8995
}
9096
}

0 commit comments

Comments
 (0)