Removed 'base_path' from AkInstaller->setInstalledVersion because Ak:make_dir can...
[akelos.git] / vendor / simpletest / collector.php
blob8a8b00a8807c98cb1214d27eac2b1df489c9eb90
1 <?php
2 /**
3 * This file contains the following classes: {@link SimpleCollector},
4 * {@link SimplePatternCollector}.
5 *
6 * @author Travis Swicegood <development@domain51.com>
7 * @package SimpleTest
8 * @subpackage UnitTester
9 * @version $Id: collector.php,v 1.7 2005/09/10 21:09:34 tswicegood Exp $
12 /**
13 * The basic collector for {@link GroupTest}
15 * @see collect(), GroupTest::collect()
16 * @package SimpleTest
17 * @subpackage UnitTester
19 class SimpleCollector {
21 /**
22 * Strips off any kind of slash at the end so as to normalise the path
24 * @param string $path Path to normalise.
26 function _removeTrailingSlash($path) {
27 return preg_replace('|[\\/]$|', '', $path);
29 /**
30 * @internal
31 * Try benchmarking the following. It's more code, but by not using the
32 * regex, it may be faster? Also, shouldn't be looking for
33 * DIRECTORY_SEPERATOR instead of a manual "/"?
35 if (substr($path, -1) == DIRECTORY_SEPERATOR) {
36 return substr($path, 0, -1);
37 } else {
38 return $path;
42 /**
43 * Scans the directory and adds what it can.
44 * @param object $test Group test with {@link GroupTest::addTestFile()} method.
45 * @param string $path Directory to scan.
46 * @see _attemptToAdd()
48 function collect(&$test, $path) {
49 $path = $this->_removeTrailingSlash($path);
50 if ($handle = opendir($path)) {
51 while (($entry = readdir($handle)) !== false) {
52 $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry);
54 closedir($handle);
58 /**
59 * This method determines what should be done with a given file and adds
60 * it via {@link GroupTest::addTestFile()} if necessary.
62 * This method should be overriden to provide custom matching criteria,
63 * such as pattern matching, recursive matching, etc. For an example, see
64 * {@link SimplePatternCollector::_handle()}.
66 * @param object $test Group test with {@link GroupTest::addTestFile()} method.
67 * @param string $filename A filename as generated by {@link collect()}
68 * @see collect()
69 * @access protected
71 function _handle(&$test, $file) {
72 if (!is_dir($file)) {
73 $test->addTestFile($file);
78 /**
79 * An extension to {@link SimpleCollector} that only adds files matching a
80 * given pattern.
82 * @package SimpleTest
83 * @subpackage UnitTester
84 * @see SimpleCollector
86 class SimplePatternCollector extends SimpleCollector {
87 var $_pattern;
90 /**
92 * @param string $pattern Perl compatible regex to test name against
93 * See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE}
94 * for full documentation of valid pattern.s
96 function SimplePatternCollector($pattern = '/php$/i') {
97 $this->_pattern = $pattern;
102 * Attempts to add files that match a given pattern.
104 * @see SimpleCollector::_handle()
105 * @param object $test Group test with {@link GroupTest::addTestFile()} method.
106 * @param string $path Directory to scan.
107 * @access protected
109 function _handle(&$test, $filename) {
110 if (preg_match($this->_pattern, $filename)) {
111 parent::_handle($test, $filename);