Skip to content

Commit 7d1e408

Browse files
committed
YAML Test Runner: updates length function for
1 parent 4a671db commit 7d1e408

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

tests/BuildPHPUnitClass.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,11 @@ protected function length(array $actions): string
409409
{
410410
$key = $this->parseValue(key($actions));
411411
$value = current($actions);
412-
$output = sprintf(
413-
"\$_len_ = is_string(%s) ? strlen(%s) : (is_countable(%s) ? count(%s) : null);\n",
414-
$key,
415-
$key,
416-
$key,
417-
$key
412+
$output = "\$body = " . $key . ";\n";
413+
$output .= "if (is_string(\$body) && str_starts_with(\$body, '[')) {\n" .
414+
"\t\$body = json_decode(\$body);\n}\n";
415+
$output .= sprintf(
416+
"\$_len_ = is_string(\$body) ? strlen(\$body) : (is_countable(\$body) ? count(\$body) : null);\n"
418417
);
419418
$output .= sprintf("\$this->assertEquals(%d, \$_len_);\n", $value);
420419
return $output;

0 commit comments

Comments
 (0)