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

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
78.95%78.95%
78.95% 15 / 19
77.05%77.05%
77.05% 47 / 61
 
Application_Model_GuestbookEntry
0.00%0.00%
0.00% 0 / 1
78.95%78.95%
78.95% 15 / 19
77.05%77.05%
77.05% 47 / 61
 public function __construct($params = null)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 4 / 4
 public function setFullName ($fullName)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function getFullName()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function setEmailAddress($emailAddress)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function getEmailAddress()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function setWebsite($website)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function getWebsite()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function setComment($comment)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function getComment()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function setTimestamp($timestamp)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function getTimestamp()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function populate($row)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 9 / 9
 public function __toArray()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 6 / 6
 public function __set($name, $value)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 5
 public function __get($name)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 6
 public function setMapper($mapper)
0.00%0.00%
0.00% 0 / 1
85.71%85.71%
85.71% 6 / 7
 public function getMapper()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 4 / 4
 public function fetchRow($where = null, $order = null)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 2
 public function save()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2


       1                 : <?php                                                                                  
       2                 : class Application_Model_GuestbookEntry                                                 
       3               1 : {                                                                                      
       4                 :     /**                                                                                
       5                 :      * @var     string The full name of the visitor                                    
       6                 :      */                                                                                
       7                 :     protected $_fullName;                                                              
       8                 :     /**                                                                                
       9                 :      * @var     string The email address of the visitor                                
      10                 :      */                                                                                
      11                 :     protected $_emailAddress;                                                          
      12                 :     /**                                                                                
      13                 :      * @var     string An optional link to a webpage of the visitor                    
      14                 :      */                                                                                
      15                 :     protected $_website;                                                               
      16                 :     /**                                                                                
      17                 :      * @var     string Comments provided by the visitor                                
      18                 :      */                                                                                
      19                 :     protected $_comment;                                                               
      20                 :     /**                                                                                
      21                 :      * @var     Zend_Date The timestamp the visitor left the message                   
      22                 :      */                                                                                
      23                 :     protected $_timestamp;                                                             
      24                 :     /**                                                                                
      25                 :      * @var     Application_Model_Mapper_GuestbookEntry                                
      26                 :      */                                                                                
      27                 :     protected $_mapper;                                                                
      28                 :     /**                                                                                
      29                 :      * Constructor for this guestbook entry that can populate this model at            
      30                 :      * construction.                                                                   
      31                 :      *                                                                                  
      32                 :      * @param   null|array|Zend_Db_Table_Row $params                                   
      33                 :      */                                                                                
      34                 :     public function __construct($params = null)                                        
      35                 :     {                                                                                  
      36               6 :         if (null !== $params) {                                                        
      37               3 :             $this->populate($params);                                                  
      38               3 :         }                                                                              
      39               6 :     }                                                                                  
      40                 :     /**                                                                                
      41                 :      * Sets the full name of the visitor                                               
      42                 :      *                                                                                  
      43                 :      * @param   string $fullName                                                       
      44                 :      * @return  Application_Model_GuestbookEntry                                       
      45                 :      */                                                                                
      46                 :     public function setFullName ($fullName)                                            
      47                 :     {                                                                                  
      48               4 :         $this->_fullName = (string) $fullName;                                         
      49               4 :         return $this;                                                                  
      50                 :     }                                                                                  
      51                 :     /**                                                                                
      52                 :      * Retrieves the full name of the visitor                                          
      53                 :      *                                                                                  
      54                 :      * @return string                                                                  
      55                 :      */                                                                                
      56                 :     public function getFullName()                                                      
      57                 :     {                                                                                  
      58               5 :         return $this->_fullName;                                                       
      59                 :     }                                                                                  
      60                 :     /**                                                                                
      61                 :      * Sets the e-mail address for the visitor                                         
      62                 :      *                                                                                  
      63                 :      * @param   string $emailAddress                                                   
      64                 :      * @return  Application_Model_GuestbookEntry                                       
      65                 :      */                                                                                
      66                 :     public function setEmailAddress($emailAddress)                                     
      67                 :     {                                                                                  
      68               4 :         $this->_emailAddress = (string) $emailAddress;                                 
      69               4 :         return $this;                                                                  
      70                 :     }                                                                                  
      71                 :     /**                                                                                
      72                 :      * Retrieves the e-mail from the visitor                                           
      73                 :      *                                                                                  
      74                 :      * @return  string                                                                 
      75                 :      */                                                                                
      76                 :     public function getEmailAddress()                                                  
      77                 :     {                                                                                  
      78               5 :         return $this->_emailAddress;                                                   
      79                 :     }                                                                                  
      80                 :     /**                                                                                
      81                 :      * Sets the website URL for the visitor                                            
      82                 :      *                                                                                  
      83                 :      * @param   string $website                                                        
      84                 :      * @return  Application_Model_GuestbookEntry                                       
      85                 :      */                                                                                
      86                 :     public function setWebsite($website)                                               
      87                 :     {                                                                                  
      88               4 :         $this->_website = (string) $website;                                           
      89               4 :         return $this;                                                                  
      90                 :     }                                                                                  
      91                 :     /**                                                                                
      92                 :      * Retrieves the website URL from the visitor                                      
      93                 :      *                                                                                  
      94                 :      * @return  string                                                                 
      95                 :      */                                                                                
      96                 :     public function getWebsite()                                                       
      97                 :     {                                                                                  
      98               5 :         return $this->_website;                                                        
      99                 :     }                                                                                  
     100                 :     /**                                                                                
     101                 :      * Sets the comment for the visitor                                                
     102                 :      *                                                                                  
     103                 :      * @param   string $comment                                                        
     104                 :      * @return  Application_Model_GuestbookEntry                                       
     105                 :      */                                                                                
     106                 :     public function setComment($comment)                                               
     107                 :     {                                                                                  
     108               4 :         $this->_comment = (string) $comment;                                           
     109               4 :         return $this;                                                                  
     110                 :     }                                                                                  
     111                 :     /**                                                                                
     112                 :      * Retrieves the comment from the visitor                                          
     113                 :      *                                                                                  
     114                 :      * @return  string                                                                 
     115                 :      */                                                                                
     116                 :     public function getComment()                                                       
     117                 :     {                                                                                  
     118               5 :         return $this->_comment;                                                        
     119                 :     }                                                                                  
     120                 :     /**                                                                                
     121                 :      * Sets the timestamp for the creation of this entry                               
     122                 :      *                                                                                  
     123                 :      * @param   string $timestamp                                                      
     124                 :      * @return  Application_Model_GuestbookEntry                                       
     125                 :      */                                                                                
     126                 :     public function setTimestamp($timestamp)                                           
     127                 :     {                                                                                  
     128               4 :         $this->_timestamp = $timestamp;                                                
     129               4 :         return $this;                                                                  
     130                 :     }                                                                                  
     131                 :     /**                                                                                
     132                 :      * Retrieves the timestamp from this entry                                         
     133                 :      *                                                                                  
     134                 :      * @return  string                                                                 
     135                 :      */                                                                                
     136                 :     public function getTimestamp()                                                     
     137                 :     {                                                                                  
     138               5 :         return $this->_timestamp;                                                      
     139                 :     }                                                                                  
     140                 :     /**                                                                                
     141                 :      * Populates the model with data                                                   
     142                 :      *                                                                                  
     143                 :      * @param   array|Zend_Db_Table_Row $row                                           
     144                 :      */                                                                                
     145                 :     public function populate($row)                                                     
     146                 :     {                                                                                  
     147               3 :         if (is_array($row)) {                                                          
     148               3 :             $row = new ArrayObject($row, ArrayObject::ARRAY_AS_PROPS);                 
     149               3 :         }                                                                              
     150               3 :         if (isset ($row->fullName)) { $this->setFullName($row->fullName); }            
     151               3 :         if (isset ($row->emailAddress)) { $this->setEmailAddress($row->emailAddress); }
     152               3 :         if (isset ($row->website)) { $this->setWebsite($row->website); }               
     153               3 :         if (isset ($row->comment)) { $this->setComment($row->comment); }               
     154               3 :         if (isset ($row->timestamp)) { $this->setTimestamp($row->timestamp); }         
     155               3 :     }                                                                                  
     156                 :     /**                                                                                
     157                 :      * Converts this object into an array                                              
     158                 :      *                                                                                  
     159                 :      * @return  array                                                                  
     160                 :      */                                                                                
     161                 :     public function __toArray()                                                        
     162                 :     {                                                                                  
     163                 :         return array (                                                                 
     164               3 :             'fullName'      => $this->getFullName(),                                   
     165               3 :             'emailAddress'  => $this->getEmailAddress(),                               
     166               3 :             'website'       => $this->getWebsite(),                                    
     167               3 :             'comment'       => $this->getComment(),                                    
     168               3 :             'timestamp'     => $this->getTimestamp(),                                  
     169               3 :         );                                                                             
     170                 :     }                                                                                  
     171                 :     /**                                                                                
     172                 :      * Magic setter                                                                    
     173                 :      *                                                                                  
     174                 :      * @param   string $name The name of the property to set                           
     175                 :      * @param   mixed $value The value to assign to this property                      
     176                 :      */                                                                                
     177                 :     public function __set($name, $value)                                               
     178                 :     {                                                                                  
     179               0 :         $method = 'set' . ucFirst($name);                                              
     180               0 :         if (method_exists($this, $method)) {                                           
     181               0 :             $this->$method($value);                                                    
     182               0 :         }                                                                              
     183               0 :     }                                                                                  
     184                 :     /**                                                                                
     185                 :      * Magic getter                                                                    
     186                 :      *                                                                                  
     187                 :      * @param   string $name The name of the property to get                           
     188                 :      * @return  mixed                                                                  
     189                 :      */                                                                                
     190                 :     public function __get($name)                                                       
     191                 :     {                                                                                  
     192               0 :         $value = null;                                                                 
     193               0 :         $method = 'get' . ucfirst($name);                                              
     194               0 :         if (method_exists($this, $method)) {                                           
     195               0 :             $value = $this->$method();                                                 
     196               0 :         }                                                                              
     197               0 :         return $value;                                                                 
     198                 :     }                                                                                  
     199                 :     /**                                                                                
     200                 :      * Sets the mapper class for this model                                            
     201                 :      *                                                                                  
     202                 :      * @param   string|Application_Model_Mapper_GuestbookEntry $mapper                 
     203                 :      * @return  Application_Model_GuestbookEntry                                       
     204                 :      * @throws  RuntimeException                                                       
     205                 :      */                                                                                
     206                 :     public function setMapper($mapper)                                                 
     207                 :     {                                                                                  
     208               1 :         if (is_string($mapper)) {                                                      
     209               1 :             if (!class_exists($mapper)) {                                              
     210               0 :                 throw new RuntimeException('Invalid mapper provided');                 
     211                 :             }                                                                          
     212               1 :             $mapper = new $mapper;                                                     
     213               1 :         }                                                                              
     214               1 :         $this->_mapper = $mapper;                                                      
     215               1 :         return $this;                                                                  
     216                 :     }                                                                                  
     217                 :     /**                                                                                
     218                 :      * Retrieve the mapper from this model                                             
     219                 :      *                                                                                  
     220                 :      * @return  Application_Model_Mapper_GuestbookEntry                                
     221                 :      */                                                                                
     222                 :     public function getMapper()                                                        
     223                 :     {                                                                                  
     224               1 :         if (null === $this->_mapper) {                                                 
     225               1 :             $this->setMapper('Application_Model_Mapper_GuestbookEntry');               
     226               1 :         }                                                                              
     227               1 :         return $this->_mapper;                                                         
     228                 :     }                                                                                  
     229                 :     /**                                                                                
     230                 :      * Fetches a single row from a datasource and populates this model                 
     231                 :      *                                                                                  
     232                 :      * @param   null|string|array|Zend_Db_Table_Select $where                          
     233                 :      * @param   null|string|array $order                                               
     234                 :      */                                                                                
     235                 :     public function fetchRow($where = null, $order = null)                             
     236                 :     {                                                                                  
     237               0 :         $this->getMapper()->fetchRow($this, $where, $order);                           
     238               0 :     }                                                                                  
     239                 :     /**                                                                                
     240                 :      * Saves this model into a datasource                                              
     241                 :      */                                                                                
     242                 :     public function save()                                                             
     243                 :     {                                                                                  
     244               1 :         $this->getMapper()->save($this);                                               
     245               1 :     }                                                                                  
     246                 : }                                                                                      
     247                 :                                                                                        
     248                 :                                                                                        

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.