function testEmptyRecordFieldValueTypeException() { //Check is Exception $recordFieldValue = new RecordFieldValue(); $recordFieldValue->setValue(new RecordFieldValue()); $this->setExpectedException('Yandex\\DataSync\\Exception\\EmptyRecordFieldValueTypeException'); $recordFieldValue->toArray(); //throw Exception }
function testFillDelta() { $fixture = array('delta_id' => 'add new object to collection', 'changes' => array(array('change_type' => 'insert', 'collection_id' => 'my_schedule', 'record_id' => 'monday', 'changes' => array(array('change_type' => 'set', 'field_id' => 'work', 'value' => array('string' => 'from 11am to 7pm', 'type' => 'string')))))); $recordFieldValue = new RecordFieldValue(); $recordFieldValue->setValue($fixture['changes'][0]['changes'][0]['value']['string']); //Field changes $recordField = new RecordField(); $recordField->setValue($recordFieldValue)->setFieldId($fixture['changes'][0]['changes'][0]['field_id'])->setChangeType(RecordField::CHANGE_TYPE_SET); //Record changes $record = new Record(); $record->setChangeType(Record::CHANGE_TYPE_INSERT)->setCollectionId($fixture['changes'][0]['collection_id'])->setRecordId($fixture['changes'][0]['record_id'])->setChanges(array($recordField))->setFields(array($recordField))->setRevision(0); $delta = new Database\Delta(); $delta->setDeltaId($fixture['delta_id'])->setChanges(array($record)); $delta2 = new Database\Delta(); $delta2->setDeltaId($fixture['delta_id'])->setChanges(new Database\Delta\Records(array($record))); $array1 = $delta->toArray(); $array2 = $delta2->toArray(); $this->assertEquals($fixture['delta_id'], $delta->getDeltaId()); $this->assertEquals($delta2->getChanges(), $delta->getChanges()); $this->assertTrue($array1 === $array2, 'Is Equals arrays'); }
//Тип изменения, применяемого к записи. //@see https://tech.yandex.ru/datasync/http/doc/tasks/create-changes-docpage/#changes-types $record->setChangeType($_REQUEST['recordChangeType'])->setCollectionId($_REQUEST['collectionId'])->setRecordId($_REQUEST['recordId']); if (isset($_REQUEST['fieldChangeType']) && $_REQUEST['fieldChangeType'] && isset($_REQUEST['fieldId']) && $_REQUEST['fieldId']) { //Поле $field = new RecordField(); //Тип изменения, применяемого к полю записи //@see https://tech.yandex.ru/datasync/http/doc/tasks/create-changes-docpage/#changes-types $field->setChangeType($_REQUEST['fieldChangeType']); //Идентификатор поля. $field->setFieldId($_REQUEST['fieldId']); if (isset($_REQUEST['value']) && $_REQUEST['value']) { //Указание значение и его типа //Если Тип значения не указан, то он определиться автоматически //@see https://tech.yandex.ru/datasync/http/doc/tasks/create-changes-docpage/#data-types $recordFieldValue = new RecordFieldValue(); $recordFieldValue->setValue($_REQUEST['value']); //установка Значения $field->setValue($recordFieldValue); } //Изменения отдельных полей записи. $record->setChanges([$field]); } //Изменения отдельных записей базы данных. $delta->setChanges([$record]); //@see https://tech.yandex.ru/datasync/http/doc/tasks/create-changes-docpage/ $dataSync->saveDelta($delta->toArray(), $database->getRevision()); //Получение "свежей" информации о БД $database = $dataSync->getDatabase($databaseId); } }