Ejemplo n.º 1
0
 /**
  * Compiles all projects into one-file scripts
  * and checks if the output is as wanted.
  */
 public function testProjects()
 {
     $numberOfProjects = 5;
     for ($i = 1; $i <= $numberOfProjects; $i++) {
         $p = new ScriptJoiner();
         # Compile filenames:
         $testdir = 'tests/project';
         $masterfile = $testdir . $i . '/file1.php';
         $outfile = $testdir . $i . '_outfile.php';
         $valid_outfile = $testdir . $i . '_valid.php';
         # Initialize ScriptJoiner:
         $p->masterfile = $masterfile;
         $p->outfile = $outfile;
         $p->run();
         # Get md5-hashes of outfiles
         $md5_outnow = md5_file($outfile);
         $md5_outvalid = md5_file($valid_outfile);
         # Comparison of files via md5-hash
         echo '*** Comparing project ', $i, PHP_EOL;
         $this->assertEquals($md5_outnow, $md5_outvalid);
         unset($p);
     }
 }
Ejemplo n.º 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);
    }
}
# To be able to use ScriptJoiner directly from the commandline, the
# first argument must be set to the current filename:
if (isset($argv) && isset($argv[0]) && basename($argv[0]) == 'ScriptJoiner.php') {
    # If a mainfile has been passed:
    if (isset($argv[1])) {
        LogMore::debug('Running ScriptJoiner from the commandline');
        $mainfile = $argv[1];
        # Run ScripJoiner:
        $s = new ScriptJoiner($mainfile);
        $s->run();
    }
}