/** * @covers Dao::getReference */ public function testGettingReferenceCachesTheReference() { $reference = $this->getMockForAbstractClass('BasicDaoReference', array(), '', false); $this->dao->expects($this->once())->method('getUserReference')->will($this->returnValue($reference)); self::assertEquals($reference, $this->dao->getReference('user')); self::assertEquals($reference, $this->dao->getReference('user')); }
/** * Gets the value of the $data array and returns it. * If the value is a DATE or DATE_WITH_TIME type, it returns a Date Object. * If the attribute name is not defined in the attributes list, the record checks if a function with * the same name but an underscore in front exists, and * _theAttributeName * * @param string $attributeName * @return mixed */ public function get($attributeName) { $attributes = $this->dao->getAttributes(); if (array_key_exists($attributeName, $attributes)) { if ($attributes[$attributeName] !== Dao::REFERENCE) { $value = $this->getDirectly($attributeName); } else { // It's a reference $reference = $this->dao->getReference($attributeName); return $reference->getReferenced($this, $attributeName); } } elseif (array_key_exists($attributeName, $this->dao->getAdditionalAttributes())) { $value = array_key_exists($attributeName, $this->data) ? $this->data[$attributeName] : null; } elseif (method_exists($this, '_' . $attributeName)) { return $this->getComputedAttribute($attributeName); } else { $this->triggerUndefinedAttributeError($attributeName); return null; } $attributeType = $this->getAttributeType($attributeName); if ($value !== null && ($attributeType === Dao::DATE || $attributeType === Dao::DATE_WITH_TIME)) { $value = new Date($value, $attributeType === Dao::DATE_WITH_TIME); } return $value; }