3 * This file contains the following classes: {@link SimpleCollector},
4 * {@link SimplePatternCollector}.
6 * @author Travis Swicegood <development@domain51.com>
8 * @subpackage UnitTester
9 * @version $Id: collector.php,v 1.7 2005/09/10 21:09:34 tswicegood Exp $
13 * The basic collector for {@link GroupTest}
15 * @see collect(), GroupTest::collect()
17 * @subpackage UnitTester
19 class SimpleCollector
{
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);
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);
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);
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()}
71 function _handle(&$test, $file) {
73 $test->addTestFile($file);
79 * An extension to {@link SimpleCollector} that only adds files matching a
83 * @subpackage UnitTester
84 * @see SimpleCollector
86 class SimplePatternCollector
extends SimpleCollector
{
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.
109 function _handle(&$test, $filename) {
110 if (preg_match($this->_pattern
, $filename)) {
111 parent
::_handle($test, $filename);