From 1260d4011be37999dbd0713f3c83fc0bbab1fa24 Mon Sep 17 00:00:00 2001 From: rhertogh Date: Wed, 29 Mar 2023 17:37:52 +0200 Subject: [PATCH] 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` --- tests/framework/helpers/JsonTest.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/framework/helpers/JsonTest.php b/tests/framework/helpers/JsonTest.php index 302f486a0d..f8150c764d 100644 --- a/tests/framework/helpers/JsonTest.php +++ b/tests/framework/helpers/JsonTest.php @@ -96,14 +96,18 @@ class JsonTest extends TestCase $data->data = (object) null; $this->assertSame('{}', Json::encode($data)); - // Generator - $data = function () { - foreach (['a' => 1, 'b' => 2] as $name => $value) { - yield $name => $value; - } - }; - - $this->assertSame('{"a":1,"b":2}', Json::encode($data())); + // 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()