View Single Post
  #2 (permalink)  
Old 07-18-2007, 01:00 PM
Vincentt Vincentt is offline
Junior Member
 
Join Date: Jul 2007
Location: The Netherlands
Posts: 15
Default

I've found the way to do it, in case anyone's interested:

PHP Code:
// Zend_Db_Table_Rowset contains the fake results
Zend_Loader::loadClass('Zend_Db_Table_Rowset');
// Create a new Zend_Db_Table_Rowset .
// You can pass it data by passing it an array as parameter
// This array contains configuration parameters
// 'data' contains an array with the database rows as values
// Each of the database rows is yet another array,
// obviously, the key is the column and the value the value
$mockResults = new Zend_Db_Table_Rowset(array('data' => $data));
// Then get the script to think that fake entry comes from the database
$entries $this->getMock('Entries');
$entries->expects($this->any())
           ->
method('fetchAll')
           ->
will($this->returnValue($mockResults)); // DB results 
So for example, the $data array could look like this:

PHP Code:
$data = array(
    
// First row:
    
array(
        
'id' => 0,
        
'title' => 'Test result 1',
    ),
    
// Second row:
    
array(
        
'id' => 3,
        
'title' => 'Yet another test result',
    ),
    
// etc.
); 
And you would pass the Zend_Db_Table_Rowset class an array of configuration parameters with the above array as the respective value of the 'data' key.

Hope that helped anyone,

Vincent
Reply With Quote