From 9d2e479d6da9c4215bde3ce389688eb99f7195b2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 22 Jan 2012 20:08:29 +0100 Subject: [PATCH] Add ProcessExecutor tests --- .../Test/Util/ProcessExecutorTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Composer/Test/Util/ProcessExecutorTest.php diff --git a/tests/Composer/Test/Util/ProcessExecutorTest.php b/tests/Composer/Test/Util/ProcessExecutorTest.php new file mode 100644 index 000000000..c7445308d --- /dev/null +++ b/tests/Composer/Test/Util/ProcessExecutorTest.php @@ -0,0 +1,46 @@ + + * Jordi Boggiano + * + * 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; +use Composer\Test\TestCase; + +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); + } + + 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")); + $this->assertEquals(array('foo', 'bar', ''), $process->splitLines("foo\r\nbar\n")); + } +}