Skip to content

Commit df6c5b8

Browse files
committed
YAML Test Runner: Parse variables with $ when they're in the body
1 parent ae4a83c commit df6c5b8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tests/BuildPHPUnitClass.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,16 @@ protected function arrayToPhpCode(array|string|stdClass $arr): string {
219219
// Handle the value recursively
220220
if (is_array($value)) {
221221
$formattedValue = $this->arrayToPhpCode($value); // recursion
222-
} elseif (is_string($value) && str_starts_with($value, '$')) {
222+
} elseif (is_string($value)) {
223+
if(str_starts_with($value, '$')){
223224
$formattedValue = $value; // treat as variable
225+
} elseif(str_contains($value, '$')) {
226+
# Replace variables like [$user_key_id] with ["' . $user_key_id . '"]
227+
$formattedValue = var_export($value, true);
228+
$formattedValue = preg_replace('/("|\')(\$[a-z_]+)("|\')/', '"\' . ${2} . \'"', $formattedValue);
229+
} else {
230+
$formattedValue = var_export($value, true);
231+
}
224232
} else {
225233
$formattedValue = var_export($value, true);
226234
}

0 commit comments

Comments
 (0)