Commit e5e48cd4 by Carsten Brandt

added test for Json::encode() and JsonSerializable

close #7084
parent 54e35baa
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace yiiunit\framework\helpers; namespace yiiunit\framework\helpers;
use yii\base\Model;
use yii\helpers\Json; use yii\helpers\Json;
use yiiunit\TestCase; use yiiunit\TestCase;
use yii\web\JsExpression; use yii\web\JsExpression;
...@@ -48,6 +49,10 @@ class JsonTest extends TestCase ...@@ -48,6 +49,10 @@ class JsonTest extends TestCase
// https://github.com/yiisoft/yii2/issues/957 // https://github.com/yiisoft/yii2/issues/957
$data = (object) null; $data = (object) null;
$this->assertSame('{}', Json::encode($data)); $this->assertSame('{}', Json::encode($data));
// JsonSerializable
$data = new JsonModel();
$this->assertSame('{"json":"serializable"}', Json::encode($data));
} }
public function testDecode() public function testDecode()
...@@ -66,3 +71,11 @@ class JsonTest extends TestCase ...@@ -66,3 +71,11 @@ class JsonTest extends TestCase
Json::decode($json); 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