Overview

Namespaces

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

Classes

  • AMemoryUsageDriver
  • AProcessorDriver
  • Controlor
  • Libxslt1123phpProcessorDriver
  • Libxslt1126phpProcessorDriver
  • LinuxMemoryUsageDriver
  • MemoryUsage
  • MSXML30ProcessorDriver
  • MSXML60ProcessorDriver
  • Params
  • Processor
  • Runner
  • Sablotron103cmdProcessorDriver
  • Saxon655ProcessorDriver
  • SaxonHE9402ProcessorDriver
  • Test
  • TestRunner
  • WindowsMemoryUsageDriver
  • Xalan271ProcessorDriver
  • XmlParamsDriver
  • Xsltproc1123ProcessorDriver
  • Xsltproc1126ProcessorDriver
  • XT20051206ProcessorDriver

Interfaces

  • IParamsDriver
  • 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\TestsRunner;
 11: 
 12: require_once __DIR__ . '/IParamsDriver.php';
 13: require_once __DIR__ . '/../../Exceptions.php';
 14: require_once LIBS . '/PhpPath/PhpPath.min.php';
 15: 
 16: use PhpPath\P;
 17: 
 18: 
 19: /**
 20:  * Class for read params of test form XML file.
 21:  *
 22:  * @author Viktor Mašíček <viktor@masicek.net>
 23:  */
 24: class XmlParamsDriver implements IParamsDriver
 25: {
 26: 
 27: 
 28:     /**
 29:      * Params loaded from xml file
 30:      *
 31:      * @var \SimpleXMLElement
 32:      */
 33:     private $test;
 34: 
 35:     /**
 36:      * The path of the directory with definition of test
 37:      *
 38:      * @var string
 39:      */
 40:     private $rootDirectory;
 41: 
 42:     /**
 43:      * The path of the generated file defined test
 44:      *
 45:      * @var string
 46:      */
 47:     private $path;
 48: 
 49: 
 50:     /**
 51:      * Set the params file.
 52:      *
 53:      * @param string $paramsFilePath The path of the file with deffinition of generated tests
 54:      * @param bool $read Flag, for reading the params
 55:      *
 56:      * @throws \XSLTBenchmarking\InvalidArgumentException Wrong format of file with params
 57:      */
 58:     public function __construct($paramsFilePath, $read = TRUE)
 59:     {
 60:         // reading of params
 61:         if ($read)
 62:         {
 63:             // validate
 64:             $dom = new \DOMDocument();
 65:             $dom->load($paramsFilePath);
 66:             try {
 67:                 $dom->schemaValidate(P::m(__DIR__, 'XmlParamsDriver.xsd'));
 68:             } catch (\Exception $e) {
 69:                 $error = libxml_get_last_error();
 70:                 throw new \XSLTBenchmarking\InvalidArgumentException(
 71:                     'File "' . $paramsFilePath . '" has wrong format: ' . $error->message
 72:                 );
 73:             }
 74: 
 75:             $this->rootDirectory = dirname($paramsFilePath);
 76:             $this->test = new \SimpleXMLElement($paramsFilePath, 0, TRUE);
 77:         }
 78:         else
 79:         {
 80:             $this->path = $paramsFilePath;
 81:         }
 82:     }
 83: 
 84: 
 85:     /**
 86:      * Function for generating new paramas file
 87:      *
 88:      * @param string $name Name of the test
 89:      * @param string $templatePath Path of tested XSLT template
 90:      * @param array $couplesPaths ([input] => [output], ...)
 91:      *
 92:      * @return void
 93:      */
 94:     public function generate($name, $templatePath, array $couplesPaths)
 95:     {
 96:         // get base name of couples
 97:         $couplesKeys = array_map('basename', array_keys($couplesPaths));
 98:         $couplesValues = array_map('basename', $couplesPaths);
 99:         $couples = array_combine($couplesKeys, $couplesValues);
100: 
101:         // make xml file
102:         $testDef = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><test></test>');
103:         $testDef->addAttribute('name', $name);
104:         $testDef->addAttribute('template', $templatePath);
105: 
106:         // couples
107:         foreach ($couples as $input => $output)
108:         {
109:             $couple = $testDef->addChild('couple');
110:             $couple->addAttribute('input', $input);
111:             $couple->addAttribute('output', $output);
112:         }
113: 
114:         // save
115:         $dom = dom_import_simplexml($testDef)->ownerDocument;
116:         $dom->formatOutput = TRUE;
117:         $dom->save($this->path);
118:     }
119: 
120: 
121:     /**
122:      * Return the name of test
123:      *
124:      * @return string
125:      */
126:     public function getName()
127:     {
128:         return (string)$this->test['name'];
129:     }
130: 
131: 
132:     /**
133:      * Return the path to the XSLT template
134:      *
135:      * @return string
136:      */
137:     public function getTemplatePath()
138:     {
139:         return P::m($this->rootDirectory, (string)$this->test['template']);
140:     }
141: 
142: 
143:     /**
144:      * Return the path to the XML files for testing
145:      * - input
146:      * - expected output
147:      *
148:      * @return array ([input] => [expected output])
149:      */
150:     public function getCouplesPaths()
151:     {
152:         $couples = array();
153:         foreach ($this->test->couple as $couple)
154:         {
155:             $input = P::m($this->rootDirectory, (string)$couple['input']);
156:             $output = P::m($this->rootDirectory, (string)$couple['output']);
157: 
158:             $couples[$input] = $output;
159:         }
160: 
161:         return $couples;
162:     }
163: 
164: 
165: }
166: 
XSTL Benchmarking API documentation generated by ApiGen.
Generated using the TokenReflection library.