Skip to content

Commit

Permalink
BC - corrections, name changes, revert, bug fix - have parent output …
Browse files Browse the repository at this point in the history
…on `wait()` call
  • Loading branch information
TheTechsTech committed Feb 15, 2020
1 parent 9167ab3 commit 2c7a2de
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"cSpell.words": [
"Commandline",
"Symplely",
"autoload",
"opis",
"pcntl",
"phpunit",
"symfony"
]
}
20 changes: 12 additions & 8 deletions Processor/Launcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function start(): self
$this->startTime = \microtime(true);

$this->process->start(function ($type, $buffer) {
$this->realTimeOutput = $buffer;
$this->realTimeOutput .= $buffer;
});

$this->pid = $this->process->getPid();
Expand Down Expand Up @@ -101,6 +101,11 @@ public function wait($waitTimer = 1000, bool $useYield = false)
return $this->triggerTimeout();
}

if ($this->showOutput) {
\printf('%s', $this->getRealOutput());
$this->realOutput = $this->realTimeOutput = null;
}

if ($useYield)
$this->yieldLiveUpdate($this->getRealOutput());
else
Expand Down Expand Up @@ -145,12 +150,7 @@ public function isTimedOut(): bool

public function isRunning(): bool
{
$isRunning = $this->process->isRunning();
if ($isRunning && $this->showOutput) {
echo $this->getRealOutput();
}

return $isRunning;
return $this->process->isRunning();
}

public function showOutput(): self
Expand Down Expand Up @@ -198,10 +198,14 @@ public function getRealOutput()
$this->realOutput = $processOutput;
}
} elseif ($this->realTimeOutput) {
$this->realOutput .= @\unserialize(\base64_decode((string) $this->realTimeOutput));
$this->realOutput = @\unserialize(\base64_decode((string) $this->realTimeOutput));
$this->realTimeOutput = null;
}

$this->realOutput = \is_string($this->realOutput)
? \rtrim($this->realOutput, 'Tjs=')
: $this->realOutput;

return $this->realOutput;
}

Expand Down
2 changes: 1 addition & 1 deletion Processor/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function spawn($shellCallable, int $timeout = 300, $processChannel = null): Laun
return Processor::create($shellCallable, $timeout, $processChannel);
}

function await_spawn(LauncherInterface $process)
function spawn_run(LauncherInterface $process)
{
return $process->run();
}
Expand Down
8 changes: 0 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ install:
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
- IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini
- IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini
- IF %PHP%==1 echo extension=php_sockets.dll >> php.ini
- ps: >-
If ($env:PHP -eq "1") {
Invoke-WebRequest "https://windows.php.net/downloads/pecl/releases/uv/0.2.4/php_uv-0.2.4-7.3-nts-vc15-x64.zip" -OutFile "php_uv-0.2.4-7.3-nts-vc15-x64.zip"
7z x -y php_uv-0.2.4-7.3-nts-vc15-x64.zip libuv.dll php_uv.dll
copy php_uv.dll ext\php_uv.dll
del php_uv.dll
del php_uv-0.2.4-7.3-nts-vc15-x64.zip
Invoke-WebRequest "https://xdebug.org/files/php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll" -OutFile "C:\tools\php73\ext\php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll"
}
- IF %PHP%==1 echo extension=php_uv.dll >> php.ini
- IF %PHP%==1 echo [xdebug] >> php.ini
- IF %PHP%==1 echo zend_extension=php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll >> php.ini
- IF %PHP%==1 echo zend.assertions=1 >> php.ini
Expand All @@ -51,7 +44,6 @@ install:
- IF %PHP%==1 echo xdebug.remote_autostart=1 >> php.ini
- IF %PHP%==1 echo xdebug.profiler_enable=off >> php.ini
- cd c:\projects\php-project-workspace
- php -m
- composer self-update

on_success:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
},
"require-dev": {
"phpunit/phpunit": ">5.7"
"phpunit/phpunit": "^6 | ^7 | ^8"
},
"autoload-dev": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions tests/ErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testIt_can_handle_exceptions_via_catch_callback()
$this->assertRegExp('/test/', $e->getMessage());
});

await_spawn($process);
spawn_run($process);
$this->assertFalse($process->isSuccessful());
$this->assertTrue($process->isTerminated());
}
Expand All @@ -35,7 +35,7 @@ public function testIt_can_handle_exceptions_via_catch_callback_yield()
$this->assertNull($pause->current());
$this->assertTrue($process->isTerminated());
}

public function testIt_handles_stderr_as_processor_error()
{
$process = spawn(function () {
Expand All @@ -44,7 +44,7 @@ public function testIt_handles_stderr_as_processor_error()
$this->assertStringContainsString('test', $error->getMessage());
});

await_spawn($process);
spawn_run($process);
$this->assertTrue($process->isSuccessful());
$this->assertEquals('test', $process->getErrorOutput());
$this->assertNull($process->getOutput());
Expand Down
25 changes: 12 additions & 13 deletions tests/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testIt_can_handle_success()
$counter = $output;
});

await_spawn($process);
spawn_run($process);
$this->assertTrue($process->isSuccessful());

$this->assertEquals(2, $counter);
Expand Down Expand Up @@ -103,9 +103,8 @@ public function testLiveOutput()
$process = Processor::create(function () {
echo 'hello child';
});
$this->expectOutputRegex('/hello child/');
$process->showOutput()->start();;
$process->wait();
$this->expectOutputString('hello child');
$process->showOutput()->run();
}

public function testGetOutputShell()
Expand Down Expand Up @@ -147,7 +146,7 @@ public function testGetErrorOutput()
$this->assertEquals(3, preg_match_all('/ERROR/', $error->getMessage(), $matches));
});

await_spawn($p);
spawn_run($p);
}

public function testGetErrorOutputYield()
Expand Down Expand Up @@ -266,13 +265,13 @@ public function testPhpPathExecutable()
$this->assertEquals('default', $result);
}

public function testLargeOutputs()
{
$process = Processor::create(function () {
return str_repeat('abcd', 1024 * 512);
});
public function testLargeOutputs()
{
$process = Processor::create(function () {
return str_repeat('abcd', 1024 * 512);
});

$process->run();
$this->assertEquals(str_repeat('abcd', 1024 * 512), $process->getOutput());
}
$process->run();
$this->assertEquals(str_repeat('abcd', 1024 * 512), $process->getOutput());
}
}

0 comments on commit 2c7a2de

Please sign in to comment.