2012-01-22 19:08:29 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
|
|
|
use Composer\Util\ProcessExecutor;
|
2013-09-25 08:14:42 +00:00
|
|
|
use Composer\TestCase;
|
2016-06-21 10:01:09 +00:00
|
|
|
use Composer\IO\BufferIO;
|
|
|
|
use Symfony\Component\Console\Output\StreamOutput;
|
2012-01-22 19:08:29 +00:00
|
|
|
|
|
|
|
class ProcessExecutorTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testExecuteCapturesOutput()
|
|
|
|
{
|
|
|
|
$process = new ProcessExecutor;
|
|
|
|
$process->execute('echo foo', $output);
|
|
|
|
$this->assertEquals("foo".PHP_EOL, $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExecuteOutputsIfNotCaptured()
|
|
|
|
{
|
|
|
|
$process = new ProcessExecutor;
|
|
|
|
ob_start();
|
|
|
|
$process->execute('echo foo');
|
|
|
|
$output = ob_get_clean();
|
|
|
|
$this->assertEquals("foo".PHP_EOL, $output);
|
|
|
|
}
|
|
|
|
|
2016-11-06 04:18:18 +00:00
|
|
|
public function testUseIOIsNotNullAndIfNotCaptured()
|
|
|
|
{
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$io->expects($this->once())
|
|
|
|
->method('write')
|
2016-12-06 15:03:03 +00:00
|
|
|
->with($this->equalTo('foo'.PHP_EOL), false);
|
2016-11-06 04:18:18 +00:00
|
|
|
|
|
|
|
$process = new ProcessExecutor($io);
|
|
|
|
$process->execute('echo foo');
|
|
|
|
}
|
|
|
|
|
2012-02-29 11:05:25 +00:00
|
|
|
public function testExecuteCapturesStderr()
|
|
|
|
{
|
|
|
|
$process = new ProcessExecutor;
|
|
|
|
$process->execute('cat foo', $output);
|
|
|
|
$this->assertNotNull($process->getErrorOutput());
|
|
|
|
}
|
|
|
|
|
2012-02-21 07:59:52 +00:00
|
|
|
public function testTimeout()
|
|
|
|
{
|
|
|
|
ProcessExecutor::setTimeout(1);
|
|
|
|
$process = new ProcessExecutor;
|
|
|
|
$this->assertEquals(1, $process->getTimeout());
|
|
|
|
ProcessExecutor::setTimeout(60);
|
|
|
|
}
|
|
|
|
|
2016-06-21 10:01:09 +00:00
|
|
|
public function testHidePasswords()
|
|
|
|
{
|
|
|
|
$process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG));
|
|
|
|
$process->execute('echo https://foo:bar@example.org/ && echo http://foo@example.org && echo http://abcdef1234567890234578:x-oauth-token@github.com/', $output);
|
|
|
|
|
|
|
|
$this->assertEquals('Executing command (CWD): echo https://foo:***@example.org/ && echo http://foo@example.org && echo http://***:***@github.com/', trim($buffer->getOutput()));
|
|
|
|
}
|
|
|
|
|
2012-01-22 19:08:29 +00:00
|
|
|
public function testSplitLines()
|
|
|
|
{
|
|
|
|
$process = new ProcessExecutor;
|
|
|
|
$this->assertEquals(array(), $process->splitLines(''));
|
|
|
|
$this->assertEquals(array(), $process->splitLines(null));
|
|
|
|
$this->assertEquals(array('foo'), $process->splitLines('foo'));
|
|
|
|
$this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\nbar"));
|
|
|
|
$this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\r\nbar"));
|
2013-06-19 07:43:02 +00:00
|
|
|
$this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\r\nbar\n"));
|
2012-01-22 19:08:29 +00:00
|
|
|
}
|
|
|
|
}
|