Пример #1
0
 public function testLaunch()
 {
     $file_name = '/tmp/output';
     setOutputDestination($file_name);
     $return = Terminus::launch("ls tests/ > {$file_name}");
     $output = retrieveOutput($file_name);
     $this->assertTrue(strpos($output, 'unit_tests') !== false);
     $this->assertEquals($return, 0);
     resetOutputDestination($file_name);
 }
Пример #2
0
/**
 * Launch system's $EDITOR to edit text
 *
 * @param [string] $input Text to be put into the temp file for changing
 * @param [string] $title Name for the temporary file
 * @return [string] $output Output string if input has changed, false otherwise
 */
function launch_editor_for_input($input, $title = 'Terminus')
{
    $tmpfile = wp_tempnam($title);
    if (!$tmpfile) {
        \Terminus::error('Error creating temporary file.');
    }
    $output = '';
    file_put_contents($tmpfile, $input);
    $editor = getenv('EDITOR');
    if (!$editor) {
        if (isset($_SERVER['OS']) && strpos($_SERVER['OS'], 'indows') !== false) {
            $editor = 'notepad';
        } else {
            $editor = 'vi';
        }
    }
    \Terminus::launch("{$editor} " . escapeshellarg($tmpfile));
    $output = file_get_contents($tmpfile);
    unlink($tmpfile);
    if ($output == $input) {
        return false;
    }
    return $output;
}