}'; $lResult = ObjectService::getObjects(json_decode($Json)); if (!is_object($lResult) || !isset($lResult->success) || !$lResult->success || !isset($lResult->result) || !is_array($lResult->result)) { throw new Exception('bad ObjectService::getObjects return ' . json_encode($lResult)); } if (json_encode($lResult->result) != '[{"id1":"1","id2":"23","date":"2016-05-01T14:53:54+02:00","timestamp":"2016-10-16T21:50:19+02:00","string":"aaaa","integer":"0","mainParentTestDb":"1"},{"id1":"1","id2":"101","date":"2016-04-13T09:14:33+02:00","timestamp":"2016-10-16T21:50:19+02:00","object":{"plop":"plop","plop2":"plop2"},"objectWithId":{"plop":"plop","plop2":"plop2"},"string":"cccc","integer":"2","mainParentTestDb":"1"}]') { throw new Exception('bad objects : ' . json_encode($lResult->result)); } /** ****************************** test following export import objects ****************************** **/ $lBasedObjects = [json_decode('{"id1":"1","id2":"23","date":"2016-05-01T14:53:54+02:00","timestamp":"2016-10-16T21:50:19+02:00","string":"aaaa","integer":0,"mainParentTestDb":"1"}'), json_decode('{"id1":"1","id2":"101","date":"2016-04-13T09:14:33+02:00","timestamp":"2016-10-16T21:50:19+02:00","string":"cccc","integer":2,"object":{"plop":"plop","plop2":"plop2"},"objectWithId":{"plop":"plop","plop2":"plop2"},"mainParentTestDb":"1"}')]; $lObject = null; foreach ($lResult->result as $lIndex => $lPhpObject) { $lObject = new Object('testDb'); $lObject->fromObject($lPhpObject); $lObject2 = new Object('testDb'); $lObject2->fromXml($lObject->toXml(false)); if (json_encode($lObject2->toObject(false, 'Europe/Berlin')) !== json_encode($lBasedObjects[$lIndex])) { throw new Exception('bad object : ' . json_encode($lObject2->toObject(false, 'Europe/Berlin'))); } } /** ****************************** test DateTime/DateTimeZone with database serialization ****************************** **/ $lDbTestModel = InstanceModel::getInstance()->getInstanceModel('testDb'); $lObject = $lDbTestModel->loadObject('[1,1501774389]'); $lObjectJson = $lObject->toObject(); $lObject->getValue('timestamp')->sub(new DateInterval('P0Y0M0DT5H0M0S')); $lObject->save(SqlTable::UPDATE); $lObject = $lDbTestModel->loadObject('[1,1501774389]', true); $lObject->getValue('timestamp')->add(new DateInterval('P0Y0M0DT5H0M0S')); $lObject->save(SqlTable::UPDATE); $lObject = $lDbTestModel->loadObject('[1,1501774389]', true); if (json_encode($lObject->toObject()) !== json_encode($lObjectJson)) {