コード例 #1
0
 /**
  * @dataProvider provideTestDirs
  */
 public function testAddDir($dirname, $expected_result, $manipulate, $zipContentsOnly = false)
 {
     # Create new archive
     $archive = '/tmp/archive.zip';
     $zip = new ZipArchiveEx();
     $zip->open($archive, ZIPARCHIVE::OVERWRITE);
     # Try to add directory:
     if ($zipContentsOnly) {
         $result = $zip->addDirContents($dirname);
     } else {
         $result = $zip->addDir($dirname);
     }
     $this->assertEquals($expected_result, $result);
     # Close archive:
     $zip->close();
     # If directory was added successfully
     if ($result) {
         # Remove extracted testdirectory from
         # former testruns:
         $extractionDir = self::$tmpDir . '/' . basename($dirname);
         FileSystemManager::rrmdir($extractionDir);
         # Extract directory
         $output = array();
         # -u Option forces update of already existing files,
         # importang for testing on travis-ci.org!
         $extractTo = $zipContentsOnly ? $extractionDir : self::$tmpDir;
         exec('unzip -u ' . $archive . ' -d ' . $extractTo, $output, $result);
         $this->assertEquals(0, $result);
         # 0 = successfull
         # $manipulate holds the file to manipulate,
         # so the following assertion fails.
         if ($manipulate) {
             file_put_contents($extractionDir . '/' . $manipulate, 'Lorem ipsum dolor sit amet.');
             $expected_result = 1;
         } else {
             $expected_result = 0;
         }
         # Compare extracted directory and original one
         exec('diff -arq ' . $dirname . ' ' . $extractionDir, $output, $result);
         LogMore::debug('Output of diff-command: %s', implode(PHP_EOL, $output));
         LogMore::debug('Expecting %d, got: %d', $expected_result, $result);
         $this->assertEquals($expected_result, $result);
     }
 }
コード例 #2
0
 /**
  * Function: parseFile
  *
  * Returns:
  *
  * 	The pretty-printed PHP code
  */
 private function parseFile($file)
 {
     LogMore::debug('parsing file %s', $file);
     $statements = file_get_contents($file);
     # Create Parser
     $parser = new PHPParser_Parser(new PHPParser_Lexer());
     # Create syntax tree
     $syntax_tree = $parser->parse($statements);
     LogMore::debug('Syntax tree parsed');
     # Pretty print syntax tree/convert syntax tree back to PHP statements:
     return $this->prettyPrint($syntax_tree);
 }
コード例 #3
0
<?php

function foo()
{
    echo 'foo', PHP_EOL;
}
# Project to test the filtering/replacing of function calls:
foo();
LogMore::debug('Yuhu');
コード例 #4
0
 /**
  * Function: recursiveAddDir
  *
  * Recursively adds the passed directory and all files
  * and folders beneath it.
  *
  * Parameters:
  *
  * 	$dirname - The directory to add.
  * 	$basedir - The basedir where $dirname resides.
  * 	$adddir - Add the basedir as directory itself
  * 		to the zipfile?
  *
  * Returns:
  *
  * 	TRUE on success or FALSE on failure.
  */
 private function recursiveAddDir($dirname, $basedir = null, $adddir = true)
 {
     LogMore::debug('In recursiveAddDir');
     $rc = false;
     # If $dirname is a directory
     if (is_dir($dirname)) {
         LogMore::debug('Is a directory: %s', $dirname);
         # Save current working directory
         $working_directory = getcwd();
         # Switch to passed directory
         chdir($dirname);
         # Get basename of passed directory
         $basename = $basedir . basename($dirname);
         # Add empty directory with the name of the passed directory
         if ($adddir) {
             LogMore::debug('Add empty dir %s', $basename);
             $rc = $this->addEmptyDir($basename);
             LogMore::debug('RC: %d', $rc);
             $basename = $basename . '/';
         } else {
             $basename = null;
         }
         # Get all files in the directory
         $files = glob('*');
         LogMore::debug('Number of files in %s: %d', $basename, sizeof($files));
         # Loop through files
         foreach ($files as $f) {
             # If file is directory
             if (is_dir($f)) {
                 # Call recursiveAdd
                 LogMore::debug('Add dir %s', $f);
                 $this->recursiveAddDir($f, $basename);
             } else {
                 LogMore::debug('Add file %s', $basename . $f);
                 $rc = $this->addFile($f, $basename . $f);
                 LogMore::debug('RC: %d', $rc);
             }
         }
         # Switch back to current working directory
         chdir($working_directory);
         $rc = true;
     }
     return $rc;
 }
コード例 #5
0
ファイル: JuggleCode.php プロジェクト: codeless/jugglecode
 private function switchDirectory($newDirectory)
 {
     LogMore::debug('attempt to switch directory: %s', $newDirectory);
     $masterDirectory = null;
     if ($newDirectory && $newDirectory != '.') {
         LogMore::debug('switching to directory %s', $newDirectory);
         $masterDirectory = getcwd();
         $rc = chdir($newDirectory);
         if ($rc) {
             LogMore::debug('directory switching attempt successfull; masterdir: %s', $masterDirectory);
         }
     }
     return $masterDirectory;
 }