From 175526841c95fa0c047f63b69867bbb05fefe7d1 Mon Sep 17 00:00:00 2001 From: tmont Date: Sun, 28 Jun 2009 08:13:16 +0000 Subject: [PATCH] fixed recursive iteration bug --- src/TUnit/util/PhpFileIterator.php | 22 +++++++++++++++++++--- src/TUnit/util/TestAccumulator.php | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/TUnit/util/PhpFileIterator.php b/src/TUnit/util/PhpFileIterator.php index d9a7b4a..8c1bc1a 100644 --- a/src/TUnit/util/PhpFileIterator.php +++ b/src/TUnit/util/PhpFileIterator.php @@ -32,6 +32,19 @@ parent::__construct(new RecursiveDirectoryIterator($dir)); } + /** + * Gets the children for the inner iterator + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return RecursivePhpFileIterator + */ + public function getChildren() { + return new self($this->current()->getPathName()); + } + /** * Defines acceptance criteria for iteration * @@ -43,9 +56,12 @@ */ public function accept() { return - !$this->getInnerIterator()->isDot() && - strpos($this->current()->getPathName(), DIRECTORY_SEPARATOR . '.') === false && - substr($this->current()->getFileName(), -4) === '.php'; + strpos($this->current()->getPathName(), DIRECTORY_SEPARATOR . '.') === false && ( + $this->current()->isDir() || ( + !$this->getInnerIterator()->isDot() && + substr($this->current()->getFileName(), -4) === '.php' + ) + ); } } diff --git a/src/TUnit/util/TestAccumulator.php b/src/TUnit/util/TestAccumulator.php index d20485c..231bf1d 100644 --- a/src/TUnit/util/TestAccumulator.php +++ b/src/TUnit/util/TestAccumulator.php @@ -60,7 +60,7 @@ * @return array */ public static function getTestsFromDir($dir, $recursive = true) { - $iterator = ($recursive) ? new RecursivePhpFileIterator($dir) : new PhpFileIterator($dir); + $iterator = ($recursive) ? new RecursiveIteratorIterator(new RecursivePhpFileIterator($dir)) : new PhpFileIterator($dir); $tests = array(); foreach ($iterator as $file) {