/** * @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')); }
/** * @covers DaoToOneReference::getReferenced */ public function testReferenceGetsByIdIfPresentDataIsInt() { $this->getMockForAbstractClass('Dao', array('createDao'), 'BBB_NotAbstractDao2', false); $this->dao = $this->getMock('BBB_NotAbstractDao2', array('getRecordFromData'), array(), '', false); $this->record->expects($this->once())->method('getDirectly')->with('address')->will($this->returnValue(123)); $this->dao->expects($this->once())->method('getRecordFromData')->with(array('id' => 123), true, false)->will($this->returnValue('RECORD')); $reference = new DaoToOneReference($this->dao, 'localKey', 'foreignKey'); self::assertSame('RECORD', $reference->getReferenced($this->record, 'address')); }
public function testRecordCallsLoadIfAnAttributeWasNotSetYet() { $record = new Record(array('id' => 4), $this->dao, TRUE); $this->dao->expects($this->any())->method('getAttributes')->will($this->returnValue(array('id' => Dao::INT, 'name' => Dao::STRING))); $this->dao->expects($this->once())->method('getData')->with(array('id' => 4))->will($this->returnValue(array('id' => 4, 'name' => 'Test'))); self::assertEquals('Test', $record->get('name')); self::assertEquals('Test', $record->get('name')); // Checking it doesn't load twice }