コード例 #1
0
 public function testFindsRecordByIdAndReturnsDomainObject()
 {
     //        $author = new ZFExt_Model_Author(array(
     //            'id'       => 1,
     //            'username' => 'joe_bloggs',
     //            'fullname' => 'Joe Bloggs',
     //            'email'    => '*****@*****.**',
     //            'url'      => 'http://www.example.com'
     //                )
     //        );
     $entry = new ZFExt_Model_Entry(array('id' => 1, 'title' => 'My Title', 'content' => 'My Content', 'published_date' => '2009-08-17T17:30:00Z'));
     $entry->setReferenceId("author", 1);
     // expected rowset result for found entry
     $dbData = new stdClass();
     $dbData->id = 1;
     $dbData->title = 'My Title';
     $dbData->content = 'My Content';
     $dbData->published_date = '2009-08-17T17:30:00Z';
     $dbData->author_id = 1;
     // set mock expectation on calling Zend_Db_Table::find()
     $this->_rowset->expects($this->once())->method('current')->will($this->returnValue($dbData));
     $this->_tableGateway->expects($this->once())->method('find')->with($this->equalTo(1))->will($this->returnValue($this->_rowset));
     // mock the AuthorMapper - it has separate tests
     //
     //        $authorMapper = $this->_getCleanMock('ZFExt_Model_AuthorMapper');
     //
     //        $authorMapper->expects($this->once())
     //                ->method('find')
     //                ->with($this->equalTo(1))
     //                ->will($this->returnValue($author));
     //
     //        $this->_mapper->setAuthorMapper($authorMapper);
     $entryResult = $this->_mapper->find(1);
     $this->assertEquals($entry, $entryResult);
 }
コード例 #2
0
 public function testLazyLoadingAuthorsRetrievesAuthorDomainObject()
 {
     $author = new ZFExt_Model_Author(array('id' => 5, 'username' => 'joe_bloggs', 'fullname' => 'Joe Bloggs', 'email' => '*****@*****.**', 'url' => 'http://www.example.com'));
     $entry = new ZFExt_Model_Entry();
     $entry->setReferenceId('author', 5);
     $authorMapper = $this->_getCleanMock('ZFExt_Model_AuthorMapper');
     $authorMapper->expects($this->once())->method('find')->with($this->equalTo(5))->will($this->returnValue($author));
     $entry->setAuthorMapper($authorMapper);
     $this->assertEquals('Joe Bloggs', $entry->author->fullname);
 }
コード例 #3
0
 public function save(ZFExt_Model_Entry $entry)
 {
     $data = $entry->toArray();
     $data['author_id'] = $entry->author->id;
     unset($data['author']);
     //        Zend_Debug::dump($data);
     if (!$entry->id) {
         $entry->id = $this->_getGateway()->insert($data);
         $this->_setIdentity($entry->id, $entry);
     } else {
         $where = $this->_getGateway()->getAdapter()->quoteInto('id = ?', $entry->id);
         $this->_getGateway()->update($data, $where);
     }
 }