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 LIBS . '/PhpPath/PhpPath.min.php';
13 : require_once ROOT . '/Exceptions.php';
14 :
15 : use PhpPath\P;
16 :
17 : /**
18 : * Container for information about one test.
19 : *
20 : * @author Viktor Mašíček <viktor@masicek.net>
21 : */
22 : class Test
23 : {
24 :
25 :
26 : /**
27 : * Name of the test
28 : *
29 : * @var string
30 : */
31 : private $name;
32 :
33 : /**
34 : * Path of the XSLT template
35 : *
36 : * @var string
37 : */
38 : private $templatePath;
39 :
40 : /**
41 : * Couples of XML inpiut and expected output files
42 : *
43 : * @var array ([input] => [expected output], ...)
44 : */
45 : private $couples;
46 :
47 :
48 : /**
49 : * Set name of the test
50 : *
51 : * @param string $name Name of the test
52 : */
53 : public function __construct($name)
54 : {
55 1 : $this->name = $name;
56 1 : }
57 :
58 :
59 : /**
60 : * Return name of the test
61 : *
62 : * @return string
63 : */
64 : public function getName()
65 : {
66 1 : return $this->name;
67 : }
68 :
69 :
70 : /**
71 : * Set path of XSLT template
72 : *
73 : * @param string $templatePath The path of XSLT template
74 : *
75 : * @return void
76 : */
77 : public function setTemplatePath($templatePath)
78 : {
79 8 : $templatePath = P::mcf($templatePath);
80 :
81 7 : $extension = pathinfo($templatePath, PATHINFO_EXTENSION);
82 7 : if ($extension != 'xsl' && $extension != 'xslt')
83 7 : {
84 6 : throw new \XSLTBenchmarking\InvalidArgumentException('XSLT template path does not have extension ".xsl" or ".xslt". It has value "' . $templatePath . '"');
85 : }
86 :
87 1 : $this->templatePath = $templatePath;
88 1 : }
89 :
90 :
91 : /**
92 : * Return path of XSLT template
93 : *
94 : * @return string
95 : */
96 : public function getTemplatePath()
97 : {
98 1 : return $this->templatePath;
99 : }
100 :
101 :
102 : /**
103 : * Add couples of input and expected output XML files
104 : *
105 : * @param array $couples ([input] => [expected output], ...)
106 : *
107 : * @return void
108 : */
109 : public function addCouplesPaths(array $couples)
110 : {
111 2 : foreach ($couples as $input => $expectedOutput)
112 : {
113 2 : $inputExtension = pathinfo($input, PATHINFO_EXTENSION);
114 2 : if ($inputExtension != 'xml')
115 2 : {
116 1 : throw new \XSLTBenchmarking\InvalidArgumentException('XSLT template path does not have extension ".xml". It has value "' . $input . '"');
117 : }
118 1 : $this->couples[P::mcf($input)] = P::mcf($expectedOutput);
119 :
120 1 : }
121 1 : }
122 :
123 :
124 : /**
125 : * Return couples of input and expected output XML files
126 : *
127 : * @return array ([input] => [expected output], ...)
128 : */
129 : public function getCouplesPaths()
130 : {
131 1 : return $this->couples;
132 : }
133 :
134 :
135 : }
|