Skip to content

Commit

Permalink
Fixed issue with set in YAML specification + interpolation for PHP 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Sep 28, 2023
1 parent fbf73de commit 8372de2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 9 additions & 6 deletions util/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,15 @@ private function transform_and_set(array $action): string

private function set(array $action): string
{
$key = key($action);
$this->variables[] = $action[$key];
return YamlTests::render(self::TEMPLATE_SET_VARIABLE, [
':var' => $action[$key],
':value' => $this->convertResponseField($key)
]);
$output = '';
foreach ($action as $key => $var) {
$this->variables[] = $var;
$output .= YamlTests::render(self::TEMPLATE_SET_VARIABLE, [
':var' => $var,
':value' => $this->convertResponseField($key)
]);
}
return $output;
}

private function warnings(array $action, array &$vars)
Expand Down
13 changes: 13 additions & 0 deletions util/YamlTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ public function build(): array
]
);
}
// Fix ${var} string interpolation deprecated for PHP 8.2
// @see https://php.watch/versions/8.2/$%7Bvar%7D-string-interpolation-deprecated
$test = $this->fixStringInterpolationInCurlyBracket($test);
file_put_contents($testDirName . '/' . $testName . '.php', $test);
try {
eval(substr($test, 5)); // remove <?php header
Expand All @@ -309,6 +312,16 @@ public function build(): array
];
}

/**
* Convert ${var} in {$var} for PHP 8.2 deprecation notice
*
* @see https://php.watch/versions/8.2/$%7Bvar%7D-string-interpolation-deprecated
*/
private function fixStringInterpolationInCurlyBracket(string $code): string
{
return preg_replace('/\${([^}]+)}/', '{\$$1}', $code);
}

private function extractTestNamespace(string $path)
{
$file = substr($path, strlen($this->testDir) + 1);
Expand Down

0 comments on commit 8372de2

Please sign in to comment.