Implemented JsonSerializable interface for models/records

This commit is contained in:
Gregory Oschwald
2013-10-26 14:13:56 -07:00
parent 7fa971aef8
commit 569043cb8f
4 changed files with 47 additions and 3 deletions
+31
View File
@@ -159,4 +159,35 @@ class CountryTest extends \PHPUnit_Framework_TestCase
'raw method returns raw input'
);
}
public function testJsonSerialize()
{
$this->assertEquals(
$this->raw,
$this->model->jsonSerialize(),
'jsonSerialize returns initial array'
);
$this->assertEquals(
$this->raw['country'],
$this->model->country->jsonSerialize(),
'jsonSerialize returns initial array for the record'
);
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
$this->markTestSkipped('Requires PHP 5.4+.');
}
$this->assertEquals(
json_encode($this->raw),
json_encode($this->model),
'json_encode can be called on the model object directly'
);
$this->assertEquals(
json_encode($this->raw['country']),
json_encode($this->model->country),
'json_encode can be called on the record object directly'
);
}
}