Overview

Namespaces

  • PHP
  • XSLTBenchmarking
    • Reports
    • RunnerConsole
    • TestsGenerator
    • TestsRunner

Classes

  • Convertor
  • HtmlConvertorDriver
  • Merger
  • Printer
  • Report

Interfaces

  • IConvertorDriver
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  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:         P::mcd($reportsDir);
 57: 
 58:         $this->reportsDir = $reportsDir;
 59:         $this->processors = $processors;
 60:     }
 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:         $this->reports[] = $report;
 73:     }
 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:         $reportsEl = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><reports></reports>');
127: 
128:         // global informations
129:         $globalEl = $reportsEl->addChild('global');
130:         $processorsListEl = $globalEl->addChild('processors');
131:         foreach ($this->processors as $name => $processor)
132:         {
133:             $processorListEl = $processorsListEl->addChild('processor');
134:             $processorListEl->addAttribute('name', $name);
135:             foreach ($processor as $attributeName => $attribteValue)
136:             {
137:                 $processorListEl->addAttribute($attributeName, $attribteValue);
138:             }
139:         }
140: 
141:         // reports of tests
142:         $testsEl = $reportsEl->addChild('tests');
143:         foreach ($this->reports as $report)
144:         {
145:             $testEl = $testsEl->addChild('test');
146:             $testEl->addAttribute('name', $report->getTestName());
147:             $testEl->addAttribute('template', $report->getTemplatePath());
148: 
149:             foreach ($report->getProcessors() as $processorName)
150:             {
151:                 $processorEl = $testEl->addChild('processor');
152:                 $processorEl->addAttribute('name', $processorName);
153: 
154:                 foreach ($report->getInputs($processorName) as $data)
155:                 {
156:                     $inputEl = $processorEl->addChild('input');
157:                     $inputEl->addAttribute('input', $data['input']);
158:                     $inputEl->addAttribute('expectedOutput', $data['expectedOutput']);
159:                     $inputEl->addAttribute('output', $data['output']);
160:                     $inputEl->addAttribute('success', mb_convert_encoding($data['success'], 'UTF-8'));
161:                     $inputEl->addAttribute('correctness', (int)$data['correctness']);
162:                     $inputEl->addAttribute('sumTime', $data['sumTime']);
163:                     $inputEl->addAttribute('avgTime', $data['avgTime']);
164:                     $inputEl->addAttribute('sumMemory', $data['sumMemory']);
165:                     $inputEl->addAttribute('avgMemory', $data['avgMemory']);
166:                     $inputEl->addAttribute('repeating', $data['repeating']);
167:                 }
168:             }
169:         }
170: 
171:         // print unique file
172:         $reportFilePath = P::m($this->reportsDir, date('Y-m-d-H-i-s') . '.xml');
173: 
174:         // save + make indent
175:         $dom = dom_import_simplexml($reportsEl)->ownerDocument;
176:         $dom->formatOutput = TRUE;
177:         $dom->save($reportFilePath);
178: 
179:         return $reportFilePath;
180:     }
181: 
182: 
183: }
184: 
XSTL Benchmarking API documentation generated by ApiGen.
Generated using the TokenReflection library.