Zend Framework Unit Test Demo
Current file: /Users/dragonbe/workspace/zfunittest/application/models/mappers/GuestbookEntry.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
25.00%25.00%
25.00% 1 / 4
58.62%58.62%
58.62% 17 / 29
 
Application_Model_Mapper_GuestbookEntry
0.00%0.00%
0.00% 0 / 1
25.00%25.00%
25.00% 1 / 4
58.62%58.62%
58.62% 17 / 29
 public function setDataSource($dataSource)
0.00%0.00%
0.00% 0 / 1
77.78%77.78%
77.78% 7 / 9
 public function getDataSource()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 4 / 4
 public function fetchRow($model, $where = null, $order = null)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 8
 public function save($model)
0.00%0.00%
0.00% 0 / 1
71.43%71.43%
71.43% 5 / 7


       1                 : <?php                                                                                  
       2                 : class Application_Model_Mapper_GuestbookEntry                                          
       3               1 : {                                                                                      
       4                 :     /**                                                                                
       5                 :      * @var     Zend_Db_Table_Abstract                                                 
       6                 :      */                                                                                
       7                 :     protected $_dataSource;                                                            
       8                 :                                                                                            
       9                 :     /**                                                                                
      10                 :      * Sets the datasource linked to this model                                        
      11                 :      *                                                                                  
      12                 :      * @param   string|Zend_Db_Table_Abstract $dataSource                              
      13                 :      * @return  Application_Model_Mapper_GuestbookEntry                                
      14                 :      * @throws  RuntimeException                                                       
      15                 :      */                                                                                
      16                 :     public function setDataSource($dataSource)                                         
      17                 :     {                                                                                  
      18               1 :         if (is_string($dataSource)) {                                                  
      19               1 :             if (!class_exists($dataSource)) {                                          
      20               0 :                 throw new RuntimeException('Invalid datasource provided');             
      21                 :             }                                                                          
      22               1 :             $dataSource = new $dataSource;                                             
      23               1 :         }                                                                              
      24               1 :         if (!$dataSource instanceof Zend_Db_Table_Abstract) {                          
      25               0 :             throw new RuntimeException('Invalid datasource type provided');            
      26                 :         }                                                                              
      27               1 :         $this->_dataSource = $dataSource;                                              
      28               1 :     }                                                                                  
      29                 :     /**                                                                                
      30                 :      * Retrieves the datasource linked to this model                                   
      31                 :      *                                                                                  
      32                 :      * @return  Application_Model_DbTable_GuestbookEntry                               
      33                 :      */                                                                                
      34                 :     public function getDataSource()                                                    
      35                 :     {                                                                                  
      36               1 :         if (null === $this->_dataSource) {                                             
      37               1 :             $this->setDataSource('Application_Model_DbTable_GuestbookEntry');          
      38               1 :         }                                                                              
      39               1 :         return $this->_dataSource;                                                     
      40                 :     }                                                                                  
      41                 :     /**                                                                                
      42                 :      * Fetches a single row and populates a provide model                              
      43                 :      *                                                                                  
      44                 :      * @param   Application_Model_GuestbookEntry $model                                
      45                 :      * @param   null|array|Zend_Db_Table_Select $where                                 
      46                 :      * @param   string|array $order                                                    
      47                 :      * @throws  RuntimeException                                                       
      48                 :      */                                                                                
      49                 :     public function fetchRow($model, $where = null, $order = null)                     
      50                 :     {                                                                                  
      51               0 :         if (!$model instanceof Application_Model_GuestbookEntry) {                     
      52               0 :             throw new RuntimeException('Invalid model provided');                      
      53                 :         }                                                                              
      54               0 :         if (null !== ($resultSet = $this->getDataSource()->fetchRow($where, $order))) {
      55               0 :             if (null !== ($row = $resultSet->current())) {                             
      56               0 :                 $model->populate($row);                                                
      57               0 :             }                                                                          
      58               0 :         }                                                                              
      59               0 :     }                                                                                  
      60                 :     /**                                                                                
      61                 :      * Saves the current model into a datasource                                       
      62                 :      *                                                                                  
      63                 :      * @param   Application_Model_GuestbookEntry $model                                
      64                 :      * @throws  RuntimeException                                                       
      65                 :      */                                                                                
      66                 :     public function save($model)                                                       
      67                 :     {                                                                                  
      68               1 :         if (!$model instanceof Application_Model_GuestbookEntry) {                     
      69               0 :             throw new RuntimeException('Invalid model provided');                      
      70                 :         }                                                                              
      71               1 :         $data = $model->__toArray();                                                   
      72                 :         try {                                                                          
      73               1 :             $this->getDataSource()->insert($data);                                     
      74               1 :         } catch (Zend_Db_Statement_Exception $e) {                                     
      75               0 :             throw new RuntimeException($e->getMessage());                              
      76                 :             /** this means this content was already provided **/                       
      77                 :         }                                                                              
      78               1 :     }                                                                                  

Generated by PHPUnit 3.4.15 and Xdebug 2.1.0 using PHP 5.3.2 at Tue Sep 21 9:29:58 CEST 2010.