Commit e5e48cd4 by Carsten Brandt

added test for Json::encode() and JsonSerializable

close #7084
parent 54e35baa
......@@ -2,6 +2,7 @@
namespace yiiunit\framework\helpers;
use yii\base\Model;
use yii\helpers\Json;
use yiiunit\TestCase;
use yii\web\JsExpression;
......@@ -48,6 +49,10 @@ class JsonTest extends TestCase
// https://github.com/yiisoft/yii2/issues/957
$data = (object) null;
$this->assertSame('{}', Json::encode($data));
// JsonSerializable
$data = new JsonModel();
$this->assertSame('{"json":"serializable"}', Json::encode($data));
}
public function testDecode()
......@@ -66,3 +71,11 @@ class JsonTest extends TestCase
Json::decode($json);
}
}
class JsonModel extends Model implements \JsonSerializable
{
function jsonSerialize()
{
return ['json' => 'serializable'];
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment