Fixed \yiiunit\framework\helpers\JsonTest::testEncode() for PHP 5.4 (#19798)

* Fixed \yiiunit\framework\helpers\JsonTest::testEncode() for PHP 5.4

'\Generator' is only supported since PHP 5.5

* Actually fixed \yiiunit\framework\helpers\JsonTest::testEncode() for PHP 5.4

Turned out the test already failed during file parsing. Now using eval to "hide" the `yield`
This commit is contained in:
rhertogh
2023-03-29 17:37:52 +02:00
committed by GitHub
parent 5406e5dad3
commit 1260d4011b

View File

@ -96,15 +96,19 @@ class JsonTest extends TestCase
$data->data = (object) null;
$this->assertSame('{}', Json::encode($data));
// Generator
$data = function () {
// Generator (Only supported since PHP 5.5)
if (PHP_VERSION_ID >= 50500) {
$data = eval(<<<'PHP'
return function () {
foreach (['a' => 1, 'b' => 2] as $name => $value) {
yield $name => $value;
}
};
PHP
);
$this->assertSame('{"a":1,"b":2}', Json::encode($data()));
}
}
public function testHtmlEncode()
{