## Apache Zeta Components Manual :: File Source for regression_test.php

## Source for file regression_test.php

Documentation is available at regression_test.php

1. <?php
2. /**
3. *
4. * Licensed to the Apache Software Foundation (ASF) under one
5. * or more contributor license agreements. See the NOTICE file
6. * distributed with this work for additional information
7. * regarding copyright ownership. The ASF licenses this file
8. * to you under the Apache License, Version 2.0 (the
9. * "License"); you may not use this file except in compliance
10. * with the License. You may obtain a copy of the License at
11. *
12. * http://www.apache.org/licenses/LICENSE-2.0
13. *
14. * Unless required by applicable law or agreed to in writing,
15. * software distributed under the License is distributed on an
16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17. * KIND, either express or implied. See the License for the
18. * specific language governing permissions and limitations
19. * under the License.
20. *
21. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
22. * @version //autogentag//
23. * @filesource
24. * @package Feed
25. * @subpackage Tests
26. */
28. /**
29. * @package Feed
30. * @subpackage Tests
31. */
32. class ezcTestRegressionTest extends ezcTestCase
33. {
34. /**
35. * How to sort the test files: 'mtime' sorts by modification time, any other
36. * value sorts by name.
37. */
38. const SORT_MODE = 'name';
40. protected $files = array();
41. protected $currentFile ;
43. public function __construct ()
44. {
45. if ( self::SORT_MODE === 'mtime' )
46. {
47. // Sort by modification time to get updated tests first
48. usort ( $this-> files ,
49. array( $this, 'sortTestsByMtime' ) );
50. }
51. else
52. {
53. // Sort it, then the file a.in will be processed first. Handy for development.
54. usort ( $this-> files ,
55. array( $this, 'sortTestsByName' ) );
56. }
57. parent::__construct();
58. }
60. public function getName ( $withDataSet = TRUE )
61. {
62. return $this-> currentFile ;
63. }
65. public function getFiles ()
66. {
67. return $this-> files ;
68. }
70. public function setCurrentFile ( $file )
71. {
72. $this-> currentFile = $file;
73. }
75. protected function readDirRecursively ( $dir, &$total, $onlyWithExtension = false )
76. {
77. $extensionLength = strlen ( $onlyWithExtension );
78. $path = opendir ( $dir );
80. if ( $path === false )
81. {
82. return;
83. }
85. while ( false !== ( $file = readdir ( $path ) ) )
86. {
87. if ( $file !== "." && $file !== ".." )
88. {
89. $new = $dir . DIRECTORY_SEPARATOR . $file;
91. if ( is_file ( $new ) )
92. {
93. if ( !$onlyWithExtension ||
94. substr ( $file, -$extensionLength - 1 ) === ".{$onlyWithExtension}" )
95. {
96. $total[] = array( 'file' => $new,
97. 'mtime' => filemtime ( $new ) );
98. }
99. }
100. elseif ( is_dir ( $new ) )
101. {
102. $this-> readDirRecursively ( $new, $total, $onlyWithExtension );
103. }
104. }
105. }
106. }
108. protected function sortTestsByMtime ( $a, $b )
109. {
110. if ( $a['mtime'] != $b['mtime'] )
111. {
112. return $a['mtime'] < $b['mtime'] ? 1 : -1;
113. }
114. return strnatcmp ( $a['file'], $b['file'] );
115. }
117. protected function sortTestsByName ( $a, $b )
118. {
119. return strnatcmp ( $a['file'], $b['file'] );
120. }
122. protected function outFileName ( $file, $inExtension, $outExtension = '.out' )
123. {
124. $baseFile = substr ( $file, 0, strlen ( $file ) - strlen ( $inExtension ) );
125. return $baseFile . $outExtension;
126. }
128. public function runTest ()
129. {
130. if ( $this-> currentFile === false )
131. {
132. throw new PHPUnit_Framework_ExpectationFailedException( "No currentFile set for test " . __CLASS__ );
133. }
135. $exception = null;
136. $this->retryTest = true;
137. while ( $this->retryTest )
138. {
139. try
140. {
141. $this->retryTest = false;
142. $this->testRunRegression( $this-> currentFile );
143. }
144. catch ( Exception $e )
145. {
146. $exception = $e;
147. }
148. }
150. if ( $exception !== null )
151. {
152. throw $exception;
153. }
154. }
156. public static function suite ()
157. {
158. return new ezcMvcRegressionSuite( __CLASS__ );
159. }
160. }
161. ?>

Documentation generated by phpDocumentor 1.4.3