Printer.php
Current file: C:\DATA\Viktor\Diplomka\XSLT-Benchmarking/XSLTBenchmarking/Reports/Printer.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00% 1 / 1
100.00% 3 / 3 CRAP
100.00% 44 / 44
Printer
100.00% 1 / 1
100.00% 3 / 3 8
100.00% 44 / 44
 __construct($reportsDir, array $processors)
100.00% 1 / 1 1
100.00% 4 / 4
 addReport(\XSLTBenchmarking\Reports\Report $report)
100.00% 1 / 1 1
100.00% 2 / 2
 printAll()
100.00% 1 / 1 6
100.00% 38 / 38



       1                 : <?php                                                                                                   
       2                 :                                                                                                         
       3                 : /**                                                                                                     
       4                 :  * XSLT Benchmarking                                                                                    
       5                 :  * @link https://github.com/masicek/XSLT-Benchmarking                                                   
       6                 :  * @author Viktor Mašíček <viktor@masicek.net>                                                       
       7                 :  * @license "New" BSD License                                                                           
       8                 :  */                                                                                                     
       9                 :                                                                                                         
      10                 : namespace XSLTBenchmarking\Reports;                                                                     
      11                 :                                                                                                         
      12                 : require_once LIBS . '/PhpPath/PhpPath.min.php';                                                         
      13                 :                                                                                                         
      14                 : use PhpPath\P;                                                                                          
      15                 :                                                                                                         
      16                 :                                                                                                         
      17                 : /**                                                                                                     
      18                 :  * Printing reports of testing into one XML file                                                        
      19                 :  *                                                                                                      
      20                 :  * @author Viktor Mašíček <viktor@masicek.net>                                                       
      21                 :  */                                                                                                     
      22                 : class Printer                                                                                           
      23                 : {                                                                                                       
      24                 :                                                                                                         
      25                 :                                                                                                         
      26                 :     /**                                                                                                 
      27                 :      * Directory for generating the report                                                              
      28                 :      *                                                                                                  
      29                 :      * @var string                                                                                      
      30                 :      */                                                                                                 
      31                 :     private $reportsDir;                                                                                
      32                 :                                                                                                         
      33                 :     /**                                                                                                 
      34                 :      * ([name] => ('fullName' => [fullName], 'link' => [link], 'verions' => [version]), ...)            
      35                 :      *                                                                                                  
      36                 :      * @var array                                                                                       
      37                 :      */                                                                                                 
      38                 :     private $processors;                                                                                
      39                 :                                                                                                         
      40                 :     /**                                                                                                 
      41                 :      * List of reports                                                                                  
      42                 :      *                                                                                                  
      43                 :      * @var array of \XSLTBenchmarking\Reports\Report                                                   
      44                 :      */                                                                                                 
      45                 :     private $reports = array();                                                                         
      46                 :                                                                                                         
      47                 :                                                                                                         
      48                 :     /**                                                                                                 
      49                 :      * Setting common infromation for report                                                            
      50                 :      *                                                                                                  
      51                 :      * @param string $reportsDir Directory for generating the report                                    
      52                 :      * @param array $processors ([name] => ('[INFORMATION NAME]' => [INFORMATION VALUE], ...)           
      53                 :      */                                                                                                 
      54                 :     public function __construct($reportsDir, array $processors)                                         
      55                 :     {                                                                                                   
      56               2 :         P::mcd($reportsDir);                                                                            
      57                 :                                                                                                         
      58               1 :         $this->reportsDir = $reportsDir;                                                                
      59               1 :         $this->processors = $processors;                                                                
      60               1 :     }                                                                                                   
      61                 :                                                                                                         
      62                 :                                                                                                         
      63                 :     /**                                                                                                 
      64                 :      * Add one report of one test into list of all reported tests                                       
      65                 :      *                                                                                                  
      66                 :      * @param \XSLTBenchmarking\Reports\Report $report Report of one test                               
      67                 :      *                                                                                                  
      68                 :      * @return void                                                                                     
      69                 :      */                                                                                                 
      70                 :     public function addReport(\XSLTBenchmarking\Reports\Report $report)                                 
      71                 :     {                                                                                                   
      72               1 :         $this->reports[] = $report;                                                                     
      73               1 :     }                                                                                                   
      74                 :                                                                                                         
      75                 :                                                                                                         
      76                 :     /**                                                                                                 
      77                 :      * Print all reports into one XML file and return path of the file                                  
      78                 :      *                                                                                                  
      79                 :      * Template of XML output:                                                                          
      80                 :      * <pre>                                                                                            
      81                 :      * <reports>                                                                                        
      82                 :      *    <global>                                                                                      
      83                 :      *       <repeating>...</repeating>                                                                 
      84                 :      *       <processors>                                                                               
      85                 :      *          <processor name="..." [INFORMATION 1]="..." [INFORMATION 2]="..." />                    
      86                 :      *          <processor ... />                                                                       
      87                 :      *          ...                                                                                     
      88                 :      *       </processors>                                                                              
      89                 :      *    </global>                                                                                     
      90                 :      *    <tests>                                                                                       
      91                 :      *       <test name="..." template="...">                                                           
      92                 :      *          <processor name="...">                                                                  
      93                 :      *             <input                                                                               
      94                 :      *                input="..."                                                                       
      95                 :      *                expectedOutput="..."                                                              
      96                 :      *                output="..."                                                                      
      97                 :      *                success="..."                                                                     
      98                 :      *                correctness="..."                                                                 
      99                 :      *                sumTime="..."                                                                     
     100                 :      *                avgTime="..."                                                                     
     101                 :      *                sumMemory="..."                                                                   
     102                 :      *                avgMemory="..."                                                                   
     103                 :      *                repeating="..."                                                                   
     104                 :      *             />                                                                                   
     105                 :      *             <input ... />                                                                        
     106                 :      *             ...                                                                                  
     107                 :      *          </processor>                                                                            
     108                 :      *          <processor ...>                                                                         
     109                 :      *             ...                                                                                  
     110                 :      *          </processor>                                                                            
     111                 :      *          ...                                                                                     
     112                 :      *       </test>                                                                                    
     113                 :      *       <test ...>                                                                                 
     114                 :      *          ...                                                                                     
     115                 :      *       </test>                                                                                    
     116                 :      *       ...                                                                                        
     117                 :      *    </tests>                                                                                      
     118                 :      * </reports>                                                                                       
     119                 :      * </pre>                                                                                           
     120                 :      *                                                                                                  
     121                 :      * @return string                                                                                   
     122                 :      */                                                                                                 
     123                 :     public function printAll()                                                                          
     124                 :     {                                                                                                   
     125                 :         // initialize xml                                                                               
     126               1 :         $reportsEl = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><reports></reports>');
     127                 :                                                                                                         
     128                 :         // global informations                                                                          
     129               1 :         $globalEl = $reportsEl->addChild('global');                                                     
     130               1 :         $processorsListEl = $globalEl->addChild('processors');                                          
     131               1 :         foreach ($this->processors as $name => $processor)                                              
     132                 :         {                                                                                               
     133               1 :             $processorListEl = $processorsListEl->addChild('processor');                                
     134               1 :             $processorListEl->addAttribute('name', $name);                                              
     135               1 :             foreach ($processor as $attributeName => $attribteValue)                                    
     136                 :             {                                                                                           
     137               1 :                 $processorListEl->addAttribute($attributeName, $attribteValue);                         
     138               1 :             }                                                                                           
     139               1 :         }                                                                                               
     140                 :                                                                                                         
     141                 :         // reports of tests                                                                             
     142               1 :         $testsEl = $reportsEl->addChild('tests');                                                       
     143               1 :         foreach ($this->reports as $report)                                                             
     144                 :         {                                                                                               
     145               1 :             $testEl = $testsEl->addChild('test');                                                       
     146               1 :             $testEl->addAttribute('name', $report->getTestName());                                      
     147               1 :             $testEl->addAttribute('template', $report->getTemplatePath());                              
     148                 :                                                                                                         
     149               1 :             foreach ($report->getProcessors() as $processorName)                                        
     150                 :             {                                                                                           
     151               1 :                 $processorEl = $testEl->addChild('processor');                                          
     152               1 :                 $processorEl->addAttribute('name', $processorName);                                     
     153                 :                                                                                                         
     154               1 :                 foreach ($report->getInputs($processorName) as $data)                                   
     155                 :                 {                                                                                       
     156               1 :                     $inputEl = $processorEl->addChild('input');                                         
     157               1 :                     $inputEl->addAttribute('input', $data['input']);                                    
     158               1 :                     $inputEl->addAttribute('expectedOutput', $data['expectedOutput']);                  
     159               1 :                     $inputEl->addAttribute('output', $data['output']);                                  
     160               1 :                     $inputEl->addAttribute('success', mb_convert_encoding($data['success'], 'UTF-8'));  
     161               1 :                     $inputEl->addAttribute('correctness', (int)$data['correctness']);                   
     162               1 :                     $inputEl->addAttribute('sumTime', $data['sumTime']);                                
     163               1 :                     $inputEl->addAttribute('avgTime', $data['avgTime']);                                
     164               1 :                     $inputEl->addAttribute('sumMemory', $data['sumMemory']);                            
     165               1 :                     $inputEl->addAttribute('avgMemory', $data['avgMemory']);                            
     166               1 :                     $inputEl->addAttribute('repeating', $data['repeating']);                            
     167               1 :                 }                                                                                       
     168               1 :             }                                                                                           
     169               1 :         }                                                                                               
     170                 :                                                                                                         
     171                 :         // print unique file                                                                            
     172               1 :         $reportFilePath = P::m($this->reportsDir, date('Y-m-d-H-i-s') . '.xml');                        
     173                 :                                                                                                         
     174                 :         // save + make indent                                                                           
     175               1 :         $dom = dom_import_simplexml($reportsEl)->ownerDocument;                                         
     176               1 :         $dom->formatOutput = TRUE;                                                                      
     177               1 :         $dom->save($reportFilePath);                                                                    
     178                 :                                                                                                         
     179               1 :         return $reportFilePath;                                                                         
     180                 :     }                                                                                                   
     181                 :                                                                                                         
     182                 :                                                                                                         
     183                 : }                                                                                                       


Generated by PHP_CodeCoverage @package_version@ using PHP 5.3.6 and PHPUnit @package_version@ at Tue Jun 26 15:06:55 CEST 2012.