/** * @test */ public function setValueForKeyTest() { $function = 'Superman'; $key = 'function'; $this->fixture->setValueForKey($key, $function); $this->assertEquals($function, $this->fixture->valueForKey($key)); }
/** * Converts the query result set into objects * * @param array|\stdClass $input * @throws \Cundd\Rest\Domain\Exception\NoDatabaseSelectedException if the converted Document has no database * @return Document */ public function convertToDocument($input) { if (!$input) { return NULL; } $inputData = $input; if (is_object($input)) { if ($input instanceof \stdClass) { $inputData = get_object_vars($input); } } $convertedObject = NULL; if (!$this->useRawQueryResults) { // If the input already is a Document return it if (is_object($input) && $input instanceof Document) { return $input; } switch (TRUE) { case isset($inputData['uid']): $convertedObject = $this->findByUid($inputData['uid']); break; case isset($inputData['id']) && $this->getDatabase(): $convertedObject = $this->findByGuid($this->getDatabase() . '-' . $inputData['id']); break; case isset($inputData['id']): $convertedObject = $this->findById($inputData['id']); break; default: } } if (!$convertedObject) { $convertedObject = new Document(); } /* * Check if the input has a value for key 'data_protected' or * 'dataProtected' and set it first */ if (isset($inputData['data_protected']) && $inputData['data_protected']) { $inputData[Document::DATA_PROPERTY_NAME] = $inputData['data_protected']; unset($inputData['data_protected']); } $key = Document::DATA_PROPERTY_NAME; if (isset($inputData[$key]) && $inputData[$key]) { $value = $inputData[$key]; $convertedObject->setValueForKey($key, $value); unset($inputData[$key]); } /* * Loop through each (remaining) key value pair from the input and * assign it to the Document */ foreach ($inputData as $key => $value) { // if (ctype_lower($key[0])) { // Preserve the case // $key = GeneralUtility::underscoredToLowerCamelCase($key); // } else { // $key = GeneralUtility::underscoredToUpperCamelCase($key); // } $convertedObject->setValueForKey($key, $value); } /* * Make sure the Document's database is set */ if (!$convertedObject->_getDb()) { $currentDatabase = $this->getDatabase(); if (!$currentDatabase) { throw new NoDatabaseSelectedException('The given object and the repository have no database set', 1389257938); } $convertedObject->_setDb($currentDatabase); } return $convertedObject; }