3 * This file contains the following classes: {@link SimpleCollector},
4 * {@link SimplePatternCollector}.
6 * @author Travis Swicegood <development@domain51.com>
8 * @subpackage UnitTester
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.
23 * @param string $path Path to normalise.
24 * @return string Path without trailing slash.
26 function _removeTrailingSlash($path) {
27 if (substr($path, -1) == DIRECTORY_SEPARATOR
) {
28 return substr($path, 0, -1);
29 } elseif (substr($path, -1) == '/') {
30 return substr($path, 0, -1);
37 * Scans the directory and adds what it can.
38 * @param object $test Group test with {@link GroupTest::addTestFile()} method.
39 * @param string $path Directory to scan.
40 * @see _attemptToAdd()
42 function collect(&$test, $path) {
43 $path = $this->_removeTrailingSlash($path);
44 if ($handle = opendir($path)) {
45 while (($entry = readdir($handle)) !== false) {
46 if ($this->_isHidden($entry)) {
49 $this->_handle($test, $path . DIRECTORY_SEPARATOR
. $entry);
56 * This method determines what should be done with a given file and adds
57 * it via {@link GroupTest::addTestFile()} if necessary.
59 * This method should be overriden to provide custom matching criteria,
60 * such as pattern matching, recursive matching, etc. For an example, see
61 * {@link SimplePatternCollector::_handle()}.
63 * @param object $test Group test with {@link GroupTest::addTestFile()} method.
64 * @param string $filename A filename as generated by {@link collect()}
68 function _handle(&$test, $file) {
72 $test->addTestFile($file);
76 * Tests for hidden files so as to skip them. Currently
77 * only tests for Unix hidden files.
78 * @param string $filename Plain filename.
79 * @return boolean True if hidden file.
82 function _isHidden($filename) {
83 return strncmp($filename, '.', 1) == 0;
88 * An extension to {@link SimpleCollector} that only adds files matching a
92 * @subpackage UnitTester
93 * @see SimpleCollector
95 class SimplePatternCollector
extends SimpleCollector
{
100 * @param string $pattern Perl compatible regex to test name against
101 * See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE}
102 * for full documentation of valid pattern.s
104 function SimplePatternCollector($pattern = '/php$/i') {
105 $this->_pattern
= $pattern;
109 * Attempts to add files that match a given pattern.
111 * @see SimpleCollector::_handle()
112 * @param object $test Group test with {@link GroupTest::addTestFile()} method.
113 * @param string $path Directory to scan.
116 function _handle(&$test, $filename) {
117 if (preg_match($this->_pattern
, $filename)) {
118 parent
::_handle($test, $filename);