Example #1
0
 public function testParseInTheSameFile()
 {
     $tmp = $this->getTmp();
     file_put_contents($tmp . '_foo.sbp.php', "<?\nif true\n\techo 'Hello'");
     Sbp::fileParse($tmp . '_foo.sbp.php');
     $lines = file($tmp . '_foo.sbp.php');
     unset($lines[0]);
     $contents = trim(implode('', $lines));
     $this->assertSame("if (true) {\n\techo 'Hello';\n}", $contents);
 }
Example #2
0
 protected function emulateFile($from, $to, $expected)
 {
     if (!in_array('fiemulate', stream_get_wrappers())) {
         stream_wrapper_register('fiemulate', 'FileEmulation');
     }
     $message = '';
     $mode = stat('fiemulate://' . $from)['mode'];
     try {
         Sbp::fileParse('fiemulate://' . $from, 'fiemulate://' . $to);
     } catch (SbpException $e) {
         $message = $e->getMessage();
     }
     $this->assertTrue($message !== '', 'Parse ' . $from . ' to ' . $to . ' should throw an exception');
     $this->assertTrue(strpos($message, 'chmod ' . $expected) !== false, 'The following message does not contain "chmod ' . $expected . '":' . "\n" . $message);
 }
Example #3
0
            if (file_exists($from)) {
                $to = __DIR__ . '/tests/sbp/files/' . $name . '.php';
                SbpTestParse::fileParse($from, $to);
                echo "Compilation done in:\n";
                echo realpath($to) . "\n";
                echo filesize($to) . " bytes\n";
                continue;
            }
            echo "File not found at:\n";
            echo "{$from}\n";
            echo "To create a new test with this name, enter:\n";
            echo "{$script} " . CREATE_TEST . " {$name} \n";
        }
        break;
    case COMPILE:
        $from = argn(2);
        if (file_exists($from)) {
            $to = tempnam(sys_get_temp_dir(), 'sbp-compile');
            Sbp::fileParse($from, $to);
            readfile($to);
            unlink($to);
            break;
        }
        echo "File not found at:\n";
        echo "{$from}\n";
        break;
    default:
        echo "Usage:\n  php {$script} <command>\n\n";
        echo "Commands:\n  " . CREATE_TEST . "\n  " . COMPILE_TEST . "\n  " . COMPILE;
        break;
}