Skip to content

Commit 48610e0

Browse files
Merge pull request #38 from utopia-php/refactor-stdin-to-input
Variable refactoring
2 parents 89f3d5d + 6785f25 commit 48610e0

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

src/CLI/Console.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ public static function exit(int $status = 0): void
125125
* This function was inspired by: https://stackoverflow.com/a/13287902/2299554
126126
*
127127
* @param string $cmd
128-
* @param string $stdin
128+
* @param string $input
129129
* @param string $output
130130
* @param int $timeout
131131
* @return int
132132
*/
133-
public static function execute(string $cmd, string $stdin, string &$output, int $timeout = -1, callable $onProgress = null): int
133+
public static function execute(string $cmd, string $input, string &$output, int $timeout = -1, callable $onProgress = null): int
134134
{
135135
$cmd = '( '.$cmd.' ) 3>/dev/null ; echo $? >&3';
136136

@@ -150,7 +150,7 @@ public static function execute(string $cmd, string $stdin, string &$output, int
150150
\stream_set_blocking($pipes[2], false);
151151
\stream_set_blocking($pipes[3], false);
152152

153-
\fwrite($pipes[0], $stdin);
153+
\fwrite($pipes[0], $input);
154154
\fclose($pipes[0]);
155155
}
156156

tests/CLI/ConsoleTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function testLogs()
2929
public function testExecuteBasic()
3030
{
3131
$output = '';
32-
$stdin = '';
33-
$code = Console::execute('php -r "echo \'hello world\';"', $stdin, $output, 10);
32+
$input = '';
33+
$code = Console::execute('php -r "echo \'hello world\';"', $input, $output, 10);
3434

3535
$this->assertEquals('hello world', $output);
3636
$this->assertEquals(0, $code);
@@ -39,10 +39,10 @@ public function testExecuteBasic()
3939
public function testExecuteStream()
4040
{
4141
$output = '';
42-
$stdin = '';
42+
$input = '';
4343

4444
$outputStream = '';
45-
$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) {
45+
$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) {
4646
$outputStream .= $output;
4747
});
4848

@@ -54,8 +54,8 @@ public function testExecuteStream()
5454
public function testExecuteStdOut()
5555
{
5656
$output = '';
57-
$stdin = '';
58-
$code = Console::execute('>&1 echo "success"', $stdin, $output, 3);
57+
$input = '';
58+
$code = Console::execute('>&1 echo "success"', $input, $output, 3);
5959

6060
$this->assertEquals("success\n", $output);
6161
$this->assertEquals(0, $code);
@@ -64,8 +64,8 @@ public function testExecuteStdOut()
6464
public function testExecuteStdErr()
6565
{
6666
$output = '';
67-
$stdin = '';
68-
$code = Console::execute('>&2 echo "error"', $stdin, $output, 3);
67+
$input = '';
68+
$code = Console::execute('>&2 echo "error"', $input, $output, 3);
6969

7070
$this->assertEquals("error\n", $output);
7171
$this->assertEquals(0, $code);
@@ -74,15 +74,15 @@ public function testExecuteStdErr()
7474
public function testExecuteExitCode()
7575
{
7676
$output = '';
77-
$stdin = '';
78-
$code = Console::execute('php -r "echo \'hello world\'; exit(2);"', $stdin, $output, 10);
77+
$input = '';
78+
$code = Console::execute('php -r "echo \'hello world\'; exit(2);"', $input, $output, 10);
7979

8080
$this->assertEquals('hello world', $output);
8181
$this->assertEquals(2, $code);
8282

8383
$output = '';
84-
$stdin = '';
85-
$code = Console::execute('php -r "echo \'hello world\'; exit(100);"', $stdin, $output, 10);
84+
$input = '';
85+
$code = Console::execute('php -r "echo \'hello world\'; exit(100);"', $input, $output, 10);
8686

8787
$this->assertEquals('hello world', $output);
8888
$this->assertEquals(100, $code);
@@ -91,15 +91,15 @@ public function testExecuteExitCode()
9191
public function testExecuteTimeout()
9292
{
9393
$output = '';
94-
$stdin = '';
95-
$code = Console::execute('php -r "sleep(1); echo \'hello world\'; exit(0);"', $stdin, $output, 3);
94+
$input = '';
95+
$code = Console::execute('php -r "sleep(1); echo \'hello world\'; exit(0);"', $input, $output, 3);
9696

9797
$this->assertEquals('hello world', $output);
9898
$this->assertEquals(0, $code);
9999

100100
$output = '';
101-
$stdin = '';
102-
$code = Console::execute('php -r "sleep(4); echo \'hello world\'; exit(0);"', $stdin, $output, 3);
101+
$input = '';
102+
$code = Console::execute('php -r "sleep(4); echo \'hello world\'; exit(0);"', $input, $output, 3);
103103

104104
$this->assertEquals('', $output);
105105
$this->assertEquals(1, $code);
@@ -108,9 +108,9 @@ public function testExecuteTimeout()
108108
public function testLoop()
109109
{
110110
$file = __DIR__.'/../resources/loop.php';
111-
$stdin = '';
111+
$input = '';
112112
$output = '';
113-
$code = Console::execute('php '.$file, $stdin, $output, 30);
113+
$code = Console::execute('php '.$file, $input, $output, 30);
114114

115115
$this->assertGreaterThan(30, count(explode("\n", $output)));
116116
$this->assertLessThan(50, count(explode("\n", $output)));

0 commit comments

Comments
 (0)