From 6785f25c55c3e7ea34a30e676dc4b0d3b5aefb9e Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Mon, 6 May 2024 12:05:58 -0400 Subject: [PATCH] refactor: Renaming stdin to input --- src/CLI/Console.php | 6 +++--- tests/CLI/ConsoleTest.php | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/CLI/Console.php b/src/CLI/Console.php index e2a47bd..94407d5 100644 --- a/src/CLI/Console.php +++ b/src/CLI/Console.php @@ -125,12 +125,12 @@ public static function exit(int $status = 0): void * This function was inspired by: https://stackoverflow.com/a/13287902/2299554 * * @param string $cmd - * @param string $stdin + * @param string $input * @param string $output * @param int $timeout * @return int */ - public static function execute(string $cmd, string $stdin, string &$output, int $timeout = -1, callable $onProgress = null): int + public static function execute(string $cmd, string $input, string &$output, int $timeout = -1, callable $onProgress = null): int { $cmd = '( '.$cmd.' ) 3>/dev/null ; echo $? >&3'; @@ -150,7 +150,7 @@ public static function execute(string $cmd, string $stdin, string &$output, int \stream_set_blocking($pipes[2], false); \stream_set_blocking($pipes[3], false); - \fwrite($pipes[0], $stdin); + \fwrite($pipes[0], $input); \fclose($pipes[0]); } diff --git a/tests/CLI/ConsoleTest.php b/tests/CLI/ConsoleTest.php index e37ec63..61e5034 100755 --- a/tests/CLI/ConsoleTest.php +++ b/tests/CLI/ConsoleTest.php @@ -29,8 +29,8 @@ public function testLogs() public function testExecuteBasic() { $output = ''; - $stdin = ''; - $code = Console::execute('php -r "echo \'hello world\';"', $stdin, $output, 10); + $input = ''; + $code = Console::execute('php -r "echo \'hello world\';"', $input, $output, 10); $this->assertEquals('hello world', $output); $this->assertEquals(0, $code); @@ -39,10 +39,10 @@ public function testExecuteBasic() public function testExecuteStream() { $output = ''; - $stdin = ''; + $input = ''; $outputStream = ''; - $code = Console::execute('printf 1 && sleep 1 && printf 2 && sleep 1 && printf 3 && sleep 1 && printf 4 && sleep 1 && printf 5', $stdin, $output, 10, function ($output) use (&$outputStream) { + $code = Console::execute('printf 1 && sleep 1 && printf 2 && sleep 1 && printf 3 && sleep 1 && printf 4 && sleep 1 && printf 5', $input, $output, 10, function ($output) use (&$outputStream) { $outputStream .= $output; }); @@ -54,8 +54,8 @@ public function testExecuteStream() public function testExecuteStdOut() { $output = ''; - $stdin = ''; - $code = Console::execute('>&1 echo "success"', $stdin, $output, 3); + $input = ''; + $code = Console::execute('>&1 echo "success"', $input, $output, 3); $this->assertEquals("success\n", $output); $this->assertEquals(0, $code); @@ -64,8 +64,8 @@ public function testExecuteStdOut() public function testExecuteStdErr() { $output = ''; - $stdin = ''; - $code = Console::execute('>&2 echo "error"', $stdin, $output, 3); + $input = ''; + $code = Console::execute('>&2 echo "error"', $input, $output, 3); $this->assertEquals("error\n", $output); $this->assertEquals(0, $code); @@ -74,15 +74,15 @@ public function testExecuteStdErr() public function testExecuteExitCode() { $output = ''; - $stdin = ''; - $code = Console::execute('php -r "echo \'hello world\'; exit(2);"', $stdin, $output, 10); + $input = ''; + $code = Console::execute('php -r "echo \'hello world\'; exit(2);"', $input, $output, 10); $this->assertEquals('hello world', $output); $this->assertEquals(2, $code); $output = ''; - $stdin = ''; - $code = Console::execute('php -r "echo \'hello world\'; exit(100);"', $stdin, $output, 10); + $input = ''; + $code = Console::execute('php -r "echo \'hello world\'; exit(100);"', $input, $output, 10); $this->assertEquals('hello world', $output); $this->assertEquals(100, $code); @@ -91,15 +91,15 @@ public function testExecuteExitCode() public function testExecuteTimeout() { $output = ''; - $stdin = ''; - $code = Console::execute('php -r "sleep(1); echo \'hello world\'; exit(0);"', $stdin, $output, 3); + $input = ''; + $code = Console::execute('php -r "sleep(1); echo \'hello world\'; exit(0);"', $input, $output, 3); $this->assertEquals('hello world', $output); $this->assertEquals(0, $code); $output = ''; - $stdin = ''; - $code = Console::execute('php -r "sleep(4); echo \'hello world\'; exit(0);"', $stdin, $output, 3); + $input = ''; + $code = Console::execute('php -r "sleep(4); echo \'hello world\'; exit(0);"', $input, $output, 3); $this->assertEquals('', $output); $this->assertEquals(1, $code); @@ -108,9 +108,9 @@ public function testExecuteTimeout() public function testLoop() { $file = __DIR__.'/../resources/loop.php'; - $stdin = ''; + $input = ''; $output = ''; - $code = Console::execute('php '.$file, $stdin, $output, 30); + $code = Console::execute('php '.$file, $input, $output, 30); $this->assertGreaterThan(30, count(explode("\n", $output))); $this->assertLessThan(50, count(explode("\n", $output)));