From 380d17583b0d1cef258e10c31fbb757cb99eb01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 21 May 2019 17:35:26 +0200 Subject: [PATCH 1/2] Add tests instructions and add PHPUnit to require-dev --- .travis.yml | 6 ++++-- README.md | 15 +++++++++++++++ composer.json | 3 +++ tests/FunctionalTest.php | 9 +++++++-- tests/ProcessLauncherTest.php | 10 +++++----- tests/bootstrap.php | 18 ++++-------------- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6e1dfe..c51caba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ php: - 5.3 - 5.6 - hhvm + install: - - composer install --prefer-source --no-interaction + - composer install --no-interaction + script: - - phpunit --coverage-text + - vendor/bin/phpunit --coverage-text diff --git a/README.md b/README.md index c34b70b..994ceed 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,21 @@ The recommended way to install this library is [through composer](http://getcomp } ``` +## Tests + +To run the test suite, you first need to clone this repo and then install all +dependencies [through Composer](https://getcomposer.org): + +```bash +$ composer install +``` + +To run the test suite, go to the project root and run: + +```bash +$ php vendor/bin/phpunit +``` + ## License MIT diff --git a/composer.json b/composer.json index 040bd50..ed0dc96 100644 --- a/composer.json +++ b/composer.json @@ -19,5 +19,8 @@ "react/child-process": "~0.3.0|~0.4.0", "react/stream": "~0.3.0|~0.4.0", "react/event-loop": "~0.3.0|~0.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35" } } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index c744f25..7d37099 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -14,6 +14,9 @@ public function setUp() $this->launcher = new ProcessLauncher($this->loop); } + /** + * @doesNotPerformAssertions + */ public function testEndEmptyClosesImmediately() { $shell = $this->launcher->createDeferredShell('cat'); @@ -23,6 +26,9 @@ public function testEndEmptyClosesImmediately() $this->loop->run(); } + /** + * @doesNotPerformAssertions + */ public function testCloseEmpty() { $shell = $this->launcher->createDeferredShell('cat'); @@ -106,8 +112,7 @@ public function testExitingShellWillRejectAllExecutes() public function testPhpShell() { - // TODO: skipped for lack of compatibility with HHVM - return; + $this->markTestSkipped(); $shell = $this->launcher->createDeferredShell('php -a'); $shell->setBounding('echo "{{ bounding }}";'); diff --git a/tests/ProcessLauncherTest.php b/tests/ProcessLauncherTest.php index b5f7db0..b6bac57 100644 --- a/tests/ProcessLauncherTest.php +++ b/tests/ProcessLauncherTest.php @@ -10,15 +10,15 @@ class ProcessLauncherTest extends TestCase public function setUp() { - $this->loop = $this->getMock('React\EventLoop\LoopInterface'); + $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $this->processLauncher = new ProcessLauncher($this->loop); } public function testProcessWillBeStarted() { $process = $this->getMockBuilder('React\ChildProcess\Process')->disableOriginalConstructor()->getMock(); - $process->stdout = $this->getMock('React\Stream\ReadableStreamInterface'); - $process->stdin = $this->getMock('React\Stream\WritableStreamInterface'); + $process->stdout = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $process->stdin = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $process->expects($this->once())->method('start'); @@ -31,7 +31,7 @@ public function testClosingStreamTerminatesRunningProcess() { $process = $this->getMockBuilder('React\ChildProcess\Process')->disableOriginalConstructor()->getMock(); $process->stdout = new ReadableStream(); - $process->stdin = $this->getMock('React\Stream\WritableStreamInterface'); + $process->stdin = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $process->expects($this->once())->method('isRunning')->will($this->returnValue(true)); $process->expects($this->once())->method('terminate')->with($this->equalTo(SIGKILL)); @@ -45,7 +45,7 @@ public function testClosingStreamOfNonRunningProcessWillNotTerminate() { $process = $this->getMockBuilder('React\ChildProcess\Process')->disableOriginalConstructor()->getMock(); $process->stdout = new ReadableStream(); - $process->stdin = $this->getMock('React\Stream\WritableStreamInterface'); + $process->stdin = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $process->expects($this->once())->method('isRunning')->will($this->returnValue(false)); $process->expects($this->never())->method('terminate'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fed1e6d..3e3aaee 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,7 +7,7 @@ error_reporting(-1); -class TestCase extends PHPUnit_Framework_TestCase +class TestCase extends PHPUnit\Framework\TestCase { protected function expectCallableOnce() { @@ -27,7 +27,7 @@ protected function expectCallableOnceWith($value) $mock ->expects($this->once()) ->method('__invoke') - ->with($this->equalTo($value)); + ->with($value); return $mock; } @@ -44,6 +44,7 @@ protected function expectCallableNever() protected function expectCallableOnceParameter($type) { + throw new \BadMethodCallException(); $mock = $this->createCallableMock(); $mock ->expects($this->once()) @@ -53,12 +54,9 @@ protected function expectCallableOnceParameter($type) return $mock; } - /** - * @link https://github.com/reactphp/react/blob/master/tests/React/Tests/Socket/TestCase.php (taken from reactphp/react) - */ protected function createCallableMock() { - return $this->getMock('CallableStub'); + return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); } protected function expectPromiseResolve($promise) @@ -106,11 +104,3 @@ protected function waitFor(PromiseInterface $promise, LoopInterface $loop) return $resolved; } } - -class CallableStub -{ - public function __invoke() - { - } -} - From 7f0ccc2b689c9246b937011731682f3e1a92091a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 21 May 2019 17:48:13 +0200 Subject: [PATCH 2/2] Support legacy PHP 5.3 through PHP 7.3+ --- .travis.yml | 20 ++++++++++++++++++-- README.md | 21 +++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index c51caba..9fbb7fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,24 @@ language: php + php: - - 5.3 +# - 5.3 # requires old distro, see below + - 5.4 + - 5.5 - 5.6 - - hhvm + - 7.0 + - 7.1 + - 7.2 + - 7.3 + +# lock distro so future defaults will not break the build +dist: trusty + +matrix: + include: + - php: 5.3 + dist: precise + +sudo: false install: - composer install --no-interaction diff --git a/README.md b/README.md index 994ceed..57fd59d 100644 --- a/README.md +++ b/README.md @@ -36,16 +36,21 @@ See also the [examples](examples): ## Install -The recommended way to install this library is [through composer](http://getcomposer.org). [New to composer?](http://getcomposer.org/doc/00-intro.md) - -```JSON -{ - "require": { - "clue/shell-react": "~0.2.0" - } -} +The recommended way to install this library is [through Composer](https://getcomposer.org). +[New to Composer?](https://getcomposer.org/doc/00-intro.md) + +This will install the latest supported version: + +```bash +$ composer require clue/shell-react:^0.2 ``` +See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades. + +This project aims to run on any platform and thus does not require any PHP +extensions and supports running on legacy PHP 5.3 through current PHP 7+. +It's *highly recommended to use PHP 7+* for this project. + ## Tests To run the test suite, you first need to clone this repo and then install all