Skip to content

Commit 8372de2

Browse files
committed
Fixed issue with set in YAML specification + interpolation for PHP 8.2
1 parent fbf73de commit 8372de2

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

util/ActionTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,15 @@ private function transform_and_set(array $action): string
175175

176176
private function set(array $action): string
177177
{
178-
$key = key($action);
179-
$this->variables[] = $action[$key];
180-
return YamlTests::render(self::TEMPLATE_SET_VARIABLE, [
181-
':var' => $action[$key],
182-
':value' => $this->convertResponseField($key)
183-
]);
178+
$output = '';
179+
foreach ($action as $key => $var) {
180+
$this->variables[] = $var;
181+
$output .= YamlTests::render(self::TEMPLATE_SET_VARIABLE, [
182+
':var' => $var,
183+
':value' => $this->convertResponseField($key)
184+
]);
185+
}
186+
return $output;
184187
}
185188

186189
private function warnings(array $action, array &$vars)

util/YamlTests.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ public function build(): array
291291
]
292292
);
293293
}
294+
// Fix ${var} string interpolation deprecated for PHP 8.2
295+
// @see https://php.watch/versions/8.2/$%7Bvar%7D-string-interpolation-deprecated
296+
$test = $this->fixStringInterpolationInCurlyBracket($test);
294297
file_put_contents($testDirName . '/' . $testName . '.php', $test);
295298
try {
296299
eval(substr($test, 5)); // remove <?php header
@@ -309,6 +312,16 @@ public function build(): array
309312
];
310313
}
311314

315+
/**
316+
* Convert ${var} in {$var} for PHP 8.2 deprecation notice
317+
*
318+
* @see https://php.watch/versions/8.2/$%7Bvar%7D-string-interpolation-deprecated
319+
*/
320+
private function fixStringInterpolationInCurlyBracket(string $code): string
321+
{
322+
return preg_replace('/\${([^}]+)}/', '{\$$1}', $code);
323+
}
324+
312325
private function extractTestNamespace(string $path)
313326
{
314327
$file = substr($path, strlen($this->testDir) + 1);

0 commit comments

Comments
 (0)