/** * @param array|string $paths * @param array|string $suffixes * @param array|string $prefixes * @param array $exclude * @param boolean $commonPath * @return array */ public function getFilesAsArray($paths, $suffixes = '', $prefixes = '', array $exclude = array(), $commonPath = FALSE) { if (is_string($paths)) { $paths = array($paths); } $factory = new File_Iterator_Factory(); $iterator = $factory->getFileIterator($paths, $suffixes, $prefixes, $exclude); $files = array(); foreach ($iterator as $file) { $file = $file->getRealPath(); if ($file) { $files[] = $file; } } foreach ($paths as $path) { if (is_file($path)) { $files[] = realpath($path); } } $files = array_unique($files); sort($files); if ($commonPath) { return array('commonPath' => $this->getCommonPath($files), 'files' => $files); } else { return $files; } }
/** * Create test suite * * @param string $name Suite name * @param array|string $paths Paths * @param array|string $suffixes Suffixes * @param array|string $prefixes Prefixes * @param array $exclude Exclude * * @return AppendIterator */ protected static function _createSuite($name, $paths, $suffixes = '_test.php', $prefixes = '', $exclude = array()) { $factory = new File_Iterator_Factory(); $iterator = $factory->getFileIterator($paths, $suffixes, $prefixes, $exclude); $suite = new PHPUnit_Framework_TestSuite($name); $suite->addTestFiles($iterator); return $suite; }
/** * Run the task. * * @param array &$options Additional options. * * @return integer Number of errors. */ public function run(&$options) { require 'SebastianBergmann/PHPCPD/autoload.php'; $lib = realpath($this->_config->getPath() . '/lib'); $factory = new File_Iterator_Factory(); $files = array_keys(iterator_to_array($factory->getFileIterator($lib, 'php'))); $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new SebastianBergmann\PHPCPD\Detector\Strategy\DefaultStrategy()); $clones = $detector->copyPasteDetection($files, 5, 70); $printer = new SebastianBergmann\PHPCPD\TextUI\ResultPrinter(); $printer->printResult($clones, $lib, true); return count($clones); }
/** * {@inheritDoc} */ public function run(PHPUnit_Framework_TestResult $result = null, $filter = false, array $groups = array(), array $excludeGroups = array(), $processIsolation = false) { parent::run($result, $filter, $groups, $excludeGroups, $processIsolation); $args = func_get_args(); $factory = new File_Iterator_Factory(); $iterator = $factory->getFileIterator($this->directories, $this->suffix, $this->prefix, $this->exclude_directories); foreach ($iterator as $item) { $this->createAndPerform($item->getRealPath(), 'run', $args); } foreach ($this->files as $file) { $this->createAndPerform($this->root_directory . '/' . $file, 'run', $args); } }
/** * Constructor * * Parses this project root directory for all files and its classnames */ public function __construct() { $iter = File_Iterator_Factory::getFileIterator(PHPCB_ROOT_DIR, 'php'); foreach ($iter as $file) { $this->_classes['Cb' . substr($file->getFilename(), 0, -4)] = realpath($file->getPath() . '/' . $file->getFilename()); } }
public function getSortedFiles() { $iter = \File_Iterator_Factory::getFileIterator($this->path, '.php'); $files = array(); foreach ($iter as $file) { $files[] = $file; } sort($files, SORT_STRING); return $files; }
/** * Constructs a new TestSuite for .phpt test cases. * * @param string $directory * @param array $options Array with ini settings for the php instance run, * key being the name if the setting, value the ini value. * @throws InvalidArgumentException */ public function __construct($directory, array $options = array()) { if (is_string($directory) && is_dir($directory)) { $this->setName($directory); $iterator = File_Iterator_Factory::getFileIterator($directory, '.phpt'); foreach ($iterator as $testFile) { $this->addTestFile($testFile->getPathname(), $options); } } else { throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'directory name'); } }
/** * Adds fixture tests to the suite * * @param Magento_Test_TestSuite_ModuleGroups $suite * @return Magento_Test_Profiler_ModuleGroupsTest */ protected function _fillTests($suite) { $fileIterator = File_Iterator_Factory::getFileIterator(array(__DIR__ . '/_files/ModuleGroups'), '.php'); // Manually make unique array of filenames, because we may get duplicate entries there $filenames = array(); foreach ($fileIterator as $filename) { $filenames[] = (string) $filename; } $filenames = array_unique($filenames); // Compose test suite foreach ($filenames as $filename) { include_once $filename; $pathinfo = pathinfo($filename); $className = $pathinfo['filename']; $subSuite = new PHPUnit_Framework_TestSuite($className); $groups = $subSuite->getGroups(); $obj = new $className(); $suite->addTest($obj, $groups); } return $this; }
/** * Removes a directory from the whitelist (recursively). * * @param string $directory * @param string $suffix * @param string $prefix */ public function removeDirectoryFromWhitelist($directory, $suffix = '.php', $prefix = '') { $files = File_Iterator_Factory::getFileIterator($directory, $suffix, $prefix); foreach ($files as $file) { $this->removeFileFromWhitelist($file->getPathName()); } }
/** * @return File_Iterator */ public function collectTests() { $iterator = File_Iterator_Factory::getFileIterator($this->paths, $this->suffixes, $this->prefixes); if ($this->filterIterator !== NULL) { $class = new ReflectionClass($this->filterIterator); $iterator = $class->newInstance($iterator); } return $iterator; }
/** * Main execute function for PHP_CodeBrowser. * * Following steps are resolved: * 1. Clean-up output directory * 2. Merge xml log files * 3. Generate cbXML file via errorlist from plugins * 4. Save the cbErrorList as XML file * 5. Generate HTML output from cbXML * 6. Copy ressources (css, js, images) from template directory to output * * @return void */ public function run() { // clear and create output directory if (is_dir($this->_htmlOutputDir)) { $this->_ioHelper->deleteDirectory($this->_htmlOutputDir); } else { if (is_file($this->_htmlOutputDir)) { $this->_ioHelper->deleteFile($this->_htmlOutputDir); } } $this->_ioHelper->createDirectory($this->_htmlOutputDir); // init needed classes $cbViewReview = new CbViewReview(PHPCB_TEMPLATE_DIR, $this->_htmlOutputDir, $this->_ioHelper); $sourceHandler = new CbSourceHandler(); if (isset($this->_logDir)) { $cbIssueXml = new CbIssueXml(); // merge xml files $cbIssueXml->addDirectory($this->_logDir); // conversion of XML file cc to cb format foreach ($this->_registeredPlugins as $className) { $sourceHandler->addPlugin(new $className($cbIssueXml)); } } if (isset($this->_projectSource)) { foreach ($this->_projectSource as $source) { if (is_dir($source)) { $sourceHandler->addSourceFiles(File_Iterator_Factory::getFileIterator($source, array('php', 'js', 'css', 'html'))); } else { $sourceHandler->addSourceFile($source); } } } array_walk($this->_excludeExpressions, array($sourceHandler, 'excludeMatchingPCRE')); array_walk($this->_excludePatterns, array($sourceHandler, 'excludeMatchingPattern')); $files = $sourceHandler->getFiles(); if (!$files) { $cbViewReview->copyNoErrorsIndex(); } else { // Get the path prefix all files have in common $commonPathPrefix = $sourceHandler->getCommonPathPrefix(); foreach ($files as $file) { $cbViewReview->generate($file->getIssues(), $file->name(), $commonPathPrefix); } // Copy needed ressources (eg js libraries) to output directory $cbViewReview->copyRessourceFolders(); $cbViewReview->generateIndex($files); } }
/** * Parses directory for XML report files, generating a single DomDocument * inheritting all files and issues. * * @param String $directory The path to directory where xml files are stored * * @return CbIssueXml This object */ public function addDirectory($directory) { $iterator = File_Iterator_Factory::getFileIterator($directory, 'xml'); foreach ($iterator as $current) { $realFileName = realpath($current); $xml = new DOMDocument('1.0', 'UTF-8'); $xml->validateOnParse = true; if (@$xml->load(realpath($current))) { $this->addXMLFile($xml); } else { error_log("[Warning] Could not read file '{$realFileName}'. " . 'Make sure it contains valid xml.'); } unset($xml); } if (!$this->documentElement->hasChildNodes()) { error_log("[Warning] No valid log files found in '{$directory}'"); } return $this; }
* @category Testing * @package PHPUnit * @author Sebastian Bergmann <*****@*****.**> * @copyright 2002-2010 Sebastian Bergmann <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.2.10 */ require_once 'File/Iterator/Factory.php'; require_once 'PHP/CodeCoverage/Filter.php'; // Set this to the directory that contains the code coverage files. // It defaults to getcwd(). If you have configured a different directory // in prepend.php, you need to configure the same directory here. $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = getcwd(); if (isset($_GET['PHPUNIT_SELENIUM_TEST_ID'])) { $files = File_Iterator_Factory::getFileIterator($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'], $_GET['PHPUNIT_SELENIUM_TEST_ID']); $coverage = array(); foreach ($files as $file) { $filename = $file->getPathName(); $data = unserialize(file_get_contents($filename)); @unlink($filename); unset($filename); foreach ($data as $filename => $lines) { if (PHP_CodeCoverage_Filter::isFile($filename)) { if (!isset($coverage[$filename])) { $coverage[$filename] = array('md5' => md5_file($filename), 'coverage' => $lines); } else { foreach ($lines as $line => $flag) { if (!isset($coverage[$filename]['coverage'][$line]) || $flag > $coverage[$filename]['coverage'][$line]) { $coverage[$filename]['coverage'][$line] = $flag; }
/** * @covers PHP_CodeCoverage_Filter::addFilesToWhitelist * @covers PHP_CodeCoverage_Filter::getBlacklist */ public function testAddingFilesToTheWhitelistWorks() { $this->filter->addFilesToWhitelist(File_Iterator_Factory::getFilesAsArray(TEST_FILES_PATH, $suffixes = '.php')); $whitelist = $this->filter->getWhitelist(); sort($whitelist); $this->assertEquals($this->files, $whitelist); }
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ require 'File/Iterator/Autoload.php'; $stub = <<<ENDSTUB #!/usr/bin/env php <?php Phar::mapPhar('phpunit.phar'); require 'phar://phpunit.phar/TextUI/Command.php'; PHPUnit_TextUI_Command::main(); __HALT_COMPILER(); ENDSTUB; $phar = new Phar('phpunit.phar', 0, 'phpunit.phar'); $phar->startBuffering(); $phar->buildFromIterator( File_Iterator_Factory::getFileIterator('PHPUnit'), dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PHPUnit' ); $phar->setStub($stub); $phar->stopBuffering();
/** * @param string $directory * @param string $suffix * @return array * @since Method available since Release 3.3.0 */ protected static function getSeleneseFiles($directory, $suffix) { $files = array(); $iterator = File_Iterator_Factory::getFileIterator($directory, $suffix); foreach ($iterator as $file) { $files[] = (string) $file; } return $files; }
/** * @param DOMElement $testSuiteNode * @return PHPUnit_Framework_TestSuite * @since Method available since Release 3.4.0 */ protected function getTestSuite(DOMElement $testSuiteNode) { if ($testSuiteNode->hasAttribute('name')) { $suite = new PHPUnit_Framework_TestSuite((string) $testSuiteNode->getAttribute('name')); } else { $suite = new PHPUnit_Framework_TestSuite(); } foreach ($testSuiteNode->getElementsByTagName('directory') as $directoryNode) { $directory = (string) $directoryNode->nodeValue; if (empty($directory)) { continue; } if ($directoryNode->hasAttribute('prefix')) { $prefix = (string) $directoryNode->getAttribute('prefix'); } else { $prefix = ''; } if ($directoryNode->hasAttribute('suffix')) { $suffix = (string) $directoryNode->getAttribute('suffix'); } else { $suffix = 'Test.php'; } $suite->addTestFiles(File_Iterator_Factory::getFilesAsArray($this->toAbsolutePath($directory), $suffix, $prefix, array())); } foreach ($testSuiteNode->getElementsByTagName('file') as $fileNode) { $file = (string) $fileNode->nodeValue; if (empty($file)) { continue; } $suite->addTestFile($file); } return $suite; }
/** * Iterates over the project files * and calls replace token on each * * @uses pear.phpunit.de/File_Iterator */ private function _iterate() { require_once 'File/Iterator/Factory.php'; $files = File_Iterator_Factory::getFilesAsArray($this->_applicationRoot, $this->_allowedExtensions); foreach ($files as $file) { $this->_replaceToken($file); } }
* * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ require 'File/Iterator/Factory.php'; $stub = <<<ENDSTUB #!/usr/bin/env php <?php Phar::mapPhar('phpunit.phar'); require 'phar://phpunit.phar/TextUI/Command.php'; PHPUnit_TextUI_Command::main(); __HALT_COMPILER(); ENDSTUB; $phar = new Phar('phpunit.phar', 0, 'phpunit.phar'); $phar->startBuffering(); $phar->buildFromIterator(File_Iterator_Factory::getFileIterator('PHPUnit'), dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PHPUnit'); $phar->setStub($stub); $phar->stopBuffering();
/** * Returns the Test corresponding to the given suite. * This is a template method, subclasses override * the runFailed() and clearStatus() methods. * * @param string $suiteClassName * @param string $suiteClassFile * @return PHPUnit_Framework_Test */ public function getTest($suiteClassName, $suiteClassFile = '') { if (is_dir($suiteClassName) && !is_file($suiteClassName . '.php') && empty($suiteClassFile)) { $suite = new PHPUnit_Framework_TestSuite($suiteClassName); $suite->addTestFiles( File_Iterator_Factory::getFilesAsArray( $suiteClassName, array('Test.php', '.phpt') ) ); return $suite; } try { $testClass = $this->loadSuiteClass( $suiteClassName, $suiteClassFile ); } catch (Exception $e) { $this->runFailed($e->getMessage()); return NULL; } try { $suiteMethod = $testClass->getMethod(self::SUITE_METHODNAME); if (!$suiteMethod->isStatic()) { $this->runFailed( 'suite() method must be static.' ); return NULL; } try { $test = $suiteMethod->invoke(NULL, $testClass->getName()); } catch (ReflectionException $e) { $this->runFailed( sprintf( "Failed to invoke suite() method.\n%s", $e->getMessage() ) ); return NULL; } } catch (ReflectionException $e) { try { $test = new PHPUnit_Framework_TestSuite($testClass); } catch (InvalidArgumentException $e) { $test = new PHPUnit_Framework_TestSuite; $test->setName($suiteClassName); } } $this->clearStatus(); return $test; }
/** * Main execute function for PHP_CodeBrowser. * * Following steps are resolved: * 1. Clean-up output directory * 2. Merge xml log files * 3. Generate cbXML file via errorlist from plugins * 4. Save the cbErrorList as XML file * 5. Generate HTML output from cbXML * 6. Copy ressources (css, js, images) from template directory to output * * @return void */ public function run() { // clear and create output directory if (is_dir($this->_htmlOutputDir)) { $this->_ioHelper->deleteDirectory($this->_htmlOutputDir); } else { if (is_file($this->_htmlOutputDir)) { $this->_ioHelper->deleteFile($this->_htmlOutputDir); } } $this->_ioHelper->createDirectory($this->_htmlOutputDir); // init needed classes $cbViewReview = new CbViewReview(PHPCB_TEMPLATE_DIR, $this->_htmlOutputDir, $this->_ioHelper, $this->_phpSuffixes); $sourceHandler = new CbSourceHandler($this->_debugLog); if (isset($this->_logDir)) { $cbIssueXml = new CbIssueXml(); // merge xml files $cbIssueXml->addDirectory($this->_logDir); // conversion of XML file cc to cb format foreach ($this->_registeredPlugins as $className) { if (array_key_exists($className, $this->_pluginOptions)) { $plugin = new $className($cbIssueXml, $this->_pluginOptions[$className]); } else { $plugin = new $className($cbIssueXml); } $sourceHandler->addPlugin($plugin); } } if (isset($this->_projectSource)) { foreach ($this->_projectSource as $source) { if (is_dir($source)) { $factory = new File_Iterator_Factory(); $suffixes = array_merge($this->_phpSuffixes, array('php', 'js', 'css', 'html')); $sourceHandler->addSourceFiles($factory->getFileIterator($source, $suffixes)); } else { $sourceHandler->addSourceFile($source); } } } array_walk($this->_excludeExpressions, array($sourceHandler, 'excludeMatchingPCRE')); array_walk($this->_excludePatterns, array($sourceHandler, 'excludeMatchingPattern')); $files = $sourceHandler->getFiles(); if (!$files) { $cbViewReview->copyNoErrorsIndex(); } else { // Get the path prefix all files have in common $commonPathPrefix = $sourceHandler->getCommonPathPrefix(); $error_reporting = ini_get('error_reporting'); // Disable E_Strict, Text_Highlighter might throw up ini_set('error_reporting', $error_reporting & ~E_STRICT); foreach ($files as $file) { $cbViewReview->generate($file->getIssues(), $file->name(), $commonPathPrefix, $this->_excludeOK); } ini_set('error_reporting', $error_reporting); // Copy needed ressources (eg js libraries) to output directory $cbViewReview->copyRessourceFolders(); $cbViewReview->generateIndex($files, $this->_excludeOK); } }
public static function suite() { $suite = new Magento_Test_TestSuite_ModuleGroups(false); $suite->addTestFiles(File_Iterator_Factory::getFileIterator(array(__DIR__), array('Test.php'))); return $suite; }