From 361a516270fd657ef854c4e756a2cea8ce1696b2 Mon Sep 17 00:00:00 2001 From: Jack Blower Date: Sat, 7 Dec 2019 19:53:00 +0000 Subject: [PATCH] Fixes a bug whereby `0` is interpreted as falsy * Fixes a bug whereby an input of `0` wouldn't clear the buffer and wouldn't reset the `readIntent` status leading to pipelines potentially becoming completely blocked on reading * Changes a `false` to `null` in QueueBuffer * Adds all the new PHP 7 versions to the Travis build * Ignores the `.vscode` folder * Corrects build script (how was this working before???) * Adds a test to show the above behaviour is fixed --- .gitignore | 1 + .travis.yml | 6 +++- bin/runtests.sh | 2 +- examples/LoopExample.php | 42 +++++++++++++++++++++++++ src/PipeSys/Command/AbstractCommand.php | 3 +- src/PipeSys/IO/IOableTrait.php | 2 +- src/PipeSys/IO/QueueBuffer.php | 2 +- 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 examples/LoopExample.php diff --git a/.gitignore b/.gitignore index 446cf6a..ed51c2f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /bin/sca/phpcs.txt /bin/sca/phpmd.html composer.lock +/.vscode diff --git a/.travis.yml b/.travis.yml index 4766b19..82a1f5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,13 @@ language: php php: - '5.6' - '7.0' + - '7.1' + - '7.2' + - '7.3' + - '7.4' - hhvm - nightly - + before_install: - git config --global github.accesstoken $GITHUB_OAUTH_TOKEN - composer config github-oauth.github.com $GITHUB_OAUTH_TOKEN diff --git a/bin/runtests.sh b/bin/runtests.sh index a08f324..e77e45e 100755 --- a/bin/runtests.sh +++ b/bin/runtests.sh @@ -2,4 +2,4 @@ BASEDIR=$(dirname $0) -php BASEDIR/../tests/TestRig.php +php $BASEDIR/../tests/TestRig.php diff --git a/examples/LoopExample.php b/examples/LoopExample.php new file mode 100644 index 0000000..902251b --- /dev/null +++ b/examples/LoopExample.php @@ -0,0 +1,42 @@ +#!/usr/bin/env php +i--) + { + yield new IO\OutputIntent('0'); + echo (yield new IO\ReadIntent), "\n"; + } + } +} + +$loopBuffer = new IO\QueueBuffer; + +$start = new LoopSystem; +$end = new LoopSystem; + +$start->setStdIn($loopBuffer); +$end->setStdOut($loopBuffer); + +$c = new PS\Scheduler(new Command\StandardConnector); +$c->addCommand($start); +$c->addCommand($end); +$c->run(); diff --git a/src/PipeSys/Command/AbstractCommand.php b/src/PipeSys/Command/AbstractCommand.php index ba7e03a..3080435 100644 --- a/src/PipeSys/Command/AbstractCommand.php +++ b/src/PipeSys/Command/AbstractCommand.php @@ -4,6 +4,7 @@ use ElvenSpellmaker\PipeSys\Command\CommandInterface; use ElvenSpellmaker\PipeSys\IO\BufferInterface; +use ElvenSpellmaker\PipeSys\IO\EOF; use ElvenSpellmaker\PipeSys\IO\InvalidBufferException; use ElvenSpellmaker\PipeSys\IO\IOableTrait; use ElvenSpellmaker\PipeSys\IO\OutputIntent; @@ -89,7 +90,7 @@ private function attemptRun($firstRun) $this->generator->next(); } - $genResponse = $data + $genResponse = $data !== null ? $this->generator->send($data) : $this->generator->current(); diff --git a/src/PipeSys/IO/IOableTrait.php b/src/PipeSys/IO/IOableTrait.php index b10174d..64f313a 100644 --- a/src/PipeSys/IO/IOableTrait.php +++ b/src/PipeSys/IO/IOableTrait.php @@ -93,7 +93,7 @@ protected function attemptRead() { $data = $this->read($this->readIntent->getChannel()); - if ($data) + if ($data !== null) { $this->readIntent = null; } diff --git a/src/PipeSys/IO/QueueBuffer.php b/src/PipeSys/IO/QueueBuffer.php index c85f52d..8a97f20 100644 --- a/src/PipeSys/IO/QueueBuffer.php +++ b/src/PipeSys/IO/QueueBuffer.php @@ -98,7 +98,7 @@ public function read() } catch (RuntimeException $e) { - return false; + return null; } if (isset($this->block))