Example #1
0
 /**
  * Show directory structure
  *
  * @param string Relative path, in relation to the location of {@link PHPRACK_PATH} file
  * @param array List of options
  * @return $this
  */
 public function showDirectory($dir, array $options = array())
 {
     require_once PHPRACK_PATH . '/Adapters/File.php';
     $dir = phpRack_Adapters_File::factory($dir)->getFileName();
     if (!file_exists($dir)) {
         $this->_failure("Directory '{$dir}' is absent");
         return $this;
     }
     $this->_log("Directory tree '" . realpath($dir) . "':");
     // Create our file iterator
     require_once PHPRACK_PATH . '/Adapters/Files/DirectoryFilterIterator.php';
     $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($dir);
     if (array_key_exists('exclude', $options)) {
         $iterator->setExclude($options['exclude']);
     }
     if (array_key_exists('maxDepth', $options)) {
         $iterator->setMaxDepth($options['maxDepth']);
     }
     $this->_log(implode("\n", $this->_convertDirectoriesToLines($iterator, $dir)));
     return $this;
 }
 public function testWeCanIterateThroughFiles()
 {
     $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory(PHPRACK_PATH);
     $iterator->setExtensions('php, phtml')->setExclude('/\\.svn/')->setMaxDepth(0);
     $this->assertGreaterThan(0, count($iterator), 'Empty iterator, why?');
 }
Example #3
0
    include 'phprack.php';
    exit;
}
ob_start();
?>

<link rel="stylesheet" href="QUnit/qunit.css" type="text/css" />
<script type="text/javascript" src="QUnit/qunit.js"></script>

<?php 
$jsTestsPath = "QUnit/test/";
/**
 * @see phpRack_Adapters_Files_DirectoryFilterIterator
 */
require_once '../../phpRack/Adapters/Files/DirectoryFilterIterator.php';
$iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($jsTestsPath);
$iterator->setExclude('/.svn/')->setExtensions('js');
foreach ($iterator as $file) {
    ?>
    <script type="text/javascript"
        src="<?php 
    echo str_replace('\\', '/', $file->getPathname());
    ?>
">
    </script>
<?php 
}
?>

<h1 id="qunit-header">phpRack Test Suite</h1>
<h2 id="qunit-banner"></h2>
Example #4
0
 /**
  * Add suite
  *
  * Suite is a collection of tests. Name of the suite ($suiteName) is a name
  * of directory in "phpRack/Suite/library".
  *
  * @param $suiteName string Suite name
  * @param $config array config
  * @return $this
  * @throws phpRack_Exception if suite can't be found
  * @see MySuite::_init()
  * @see phpRack_Suite_Test
  */
 protected function _addSuite($suiteName, array $config = array())
 {
     $dir = PHPRACK_PATH . '/Suite/library/' . $suiteName;
     // create suite file iterator
     require_once PHPRACK_PATH . '/Adapters/Files/DirectoryFilterIterator.php';
     $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($dir)->setExtensions('php');
     require_once PHPRACK_PATH . '/Suite/Test.php';
     foreach ($iterator as $file) {
         $label = substr($file->getRealPath(), strlen($dir));
         // phpRack_Exception is possible here
         $test = phpRack_Suite_Test::factory($suiteName . $label, $this->_runner);
         $test->setConfig($config);
         $this->_tests[] = $test;
     }
     return $this;
 }
Example #5
0
File: Php.php Project: tpc2/phprack
 /**
  * Check files in directory have correct php syntax.
  *
  * Possible options are:
  *
  * <code>
  * class MyTest extends phpRack_Test {
  *   public function testCodeValidity() {
  *     $this->assert->php->lint(
  *       '/home/myproject/php', // path to PHP files
  *       array(
  *         'extensions' => 'php,phtml', // comma-separated list of extensions to parse
  *         'exclude' => array('/\.svn/'), // list of RegExps to exclude
  *         'verbose' => true, // show detailed log, with one file per line
  *       )
  *     );
  *   }
  * }
  * </code>
  *
  * @param string Directory path to check
  * @param array List of options
  * @return $this
  */
 public function lint($dir, array $options = array())
 {
     require_once PHPRACK_PATH . '/Adapters/File.php';
     $dir = phpRack_Adapters_File::factory($dir)->getFileName();
     if (!file_exists($dir)) {
         $this->_failure("Directory '{$dir}' does not exist");
         return $this;
     }
     // Create our file iterator
     require_once PHPRACK_PATH . '/Adapters/Files/DirectoryFilterIterator.php';
     $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($dir);
     if (!empty($options['exclude'])) {
         $iterator->setExclude($options['exclude']);
     }
     if (!empty($options['extensions'])) {
         $iterator->setExtensions($options['extensions']);
     }
     $lintCommand = 'php -l';
     $valid = $invalid = 0;
     foreach ($iterator as $file) {
         $file = realpath($file->getPathname());
         $command = $lintCommand . ' ' . escapeshellarg($file) . ' 2>&1';
         /**
          * @see phpRack_Adapters_Shell_Command
          */
         require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
         $output = phpRack_Adapters_Shell_Command::factory($command)->run();
         if (preg_match('#^No syntax errors detected#', $output)) {
             if (!empty($options['verbose'])) {
                 $this->_success("File '{$file}' is valid");
             }
             $valid++;
         } else {
             $this->_failure("File '{$file}' is NOT valid:");
             $this->_log($output);
             $invalid++;
         }
     }
     // notify phpRack about success in the test
     if (!$invalid) {
         $this->_success("{$valid} files are LINT-valid");
     }
     $this->_log(sprintf('%d files LINT-checked, among them: %d valid and %d invalid', $valid + $invalid, $valid, $invalid));
     return $this;
 }