diff --git a/.travis.yml b/.travis.yml index 3464291..6983d72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ install: - composer install --no-interaction script: - - phpunit --coverage-text + - vendor/bin/phpunit --coverage-text diff --git a/README.md b/README.md index 963263f..2391664 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Async, event-driven and UTF-8 aware console input & output (STDIN, STDOUT), buil * [Stdin](#stdin) * [Pitfalls](#pitfalls) * [Install](#install) +* [Tests](#tests) * [License](#license) * [More](#more) @@ -554,6 +555,21 @@ $ composer require clue/stdio-react:^1.0 More details and upgrade guides can be found in the [CHANGELOG](CHANGELOG.md). +## Tests + +To run the test suite, you first need to clone this repo and then install all +dependencies [through Composer](http://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 706e5db..1216981 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "psr-4": { "Clue\\React\\Stdio\\": "src/" } }, "require-dev": { + "phpunit/phpunit": "^5.0 || ^4.8", "clue/commander": "^1.2", "clue/arguments": "^2.0" } diff --git a/tests/ReadlineTest.php b/tests/ReadlineTest.php index 8355fde..1eb7e8e 100644 --- a/tests/ReadlineTest.php +++ b/tests/ReadlineTest.php @@ -12,7 +12,7 @@ class ReadlineTest extends TestCase public function setUp() { $this->input = new ReadableStream(); - $this->output = $this->getMock('React\Stream\WritableStreamInterface'); + $this->output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $this->readline = new Readline($this->input, $this->output); } @@ -983,7 +983,7 @@ public function testEmitCloseWillEmitClose() public function testClosedStdinWillCloseReadline() { - $this->input = $this->getMock('React\Stream\ReadableStreamInterface'); + $this->input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); $this->input->expects($this->once())->method('isReadable')->willReturn(false); $this->readline = new Readline($this->input, $this->output); @@ -993,7 +993,7 @@ public function testClosedStdinWillCloseReadline() public function testPauseWillBeForwarded() { - $this->input = $this->getMock('React\Stream\ReadableStreamInterface'); + $this->input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); $this->input->expects($this->once())->method('pause'); $this->readline = new Readline($this->input, $this->output); @@ -1003,7 +1003,7 @@ public function testPauseWillBeForwarded() public function testResumeWillBeForwarded() { - $this->input = $this->getMock('React\Stream\ReadableStreamInterface'); + $this->input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); $this->input->expects($this->once())->method('resume'); $this->readline = new Readline($this->input, $this->output); @@ -1013,7 +1013,7 @@ public function testResumeWillBeForwarded() public function testPipeWillReturnDest() { - $dest = $this->getMock('React\Stream\WritableStreamInterface'); + $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $ret = $this->readline->pipe($dest); diff --git a/tests/StdioTest.php b/tests/StdioTest.php index c5c3350..e127dda 100644 --- a/tests/StdioTest.php +++ b/tests/StdioTest.php @@ -23,8 +23,8 @@ public function testCtorDefaultArgs() public function testCtorArgsWillBeReturnedByGetters() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -38,8 +38,8 @@ public function testCtorArgsWillBeReturnedByGetters() public function testWriteEmptyStringWillNotWriteToOutput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -55,8 +55,8 @@ public function testWriteEmptyStringWillNotWriteToOutput() public function testWriteWillClearReadlineWriteOutputAndRestoreReadline() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -77,8 +77,8 @@ public function testWriteWillClearReadlineWriteOutputAndRestoreReadline() public function testWriteAgainWillMoveToPreviousLineWriteOutputAndRestoreReadlinePosition() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -101,8 +101,8 @@ public function testWriteAgainWillMoveToPreviousLineWriteOutputAndRestoreReadlin public function testWriteAgainWithBackspaceWillMoveToPreviousLineWriteOutputAndRestoreReadlinePosition() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -125,8 +125,8 @@ public function testWriteAgainWithBackspaceWillMoveToPreviousLineWriteOutputAndR public function testWriteAgainWithNewlinesWillClearReadlineMoveToPreviousLineWriteOutputAndRestoreReadline() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -149,8 +149,8 @@ public function testWriteAgainWithNewlinesWillClearReadlineMoveToPreviousLineWri public function testWriteAfterReadlineInputWillClearReadlineWriteOutputAndRestoreReadline() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -175,8 +175,8 @@ public function testWriteAfterReadlineInputWillClearReadlineWriteOutputAndRestor public function testOverwriteWillClearReadlineMoveToPreviousLineWriteOutputAndRestoreReadline() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -199,8 +199,8 @@ public function testOverwriteWillClearReadlineMoveToPreviousLineWriteOutputAndRe public function testOverwriteAfterNewlineWillClearReadlineAndWriteOutputAndRestoreReadline() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -223,8 +223,8 @@ public function testOverwriteAfterNewlineWillClearReadlineAndWriteOutputAndResto public function testWriteLineWillClearReadlineWriteOutputAndRestoreReadline() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -245,8 +245,8 @@ public function testWriteLineWillClearReadlineWriteOutputAndRestoreReadline() public function testWriteTwoLinesWillClearReadlineWriteOutputAndRestoreReadline() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -268,8 +268,8 @@ public function testWriteTwoLinesWillClearReadlineWriteOutputAndRestoreReadline( public function testPauseWillBeForwardedToInput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -283,8 +283,8 @@ public function testPauseWillBeForwardedToInput() public function testResumeWillBeForwardedToInput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -298,8 +298,8 @@ public function testResumeWillBeForwardedToInput() public function testReadableWillBeForwardedToInput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -313,15 +313,15 @@ public function testReadableWillBeForwardedToInput() public function testPipeWillReturnDestStream() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); $stdio = new Stdio($this->loop, $input, $output, $readline); - $dest = $this->getMock('React\Stream\WritableStreamInterface'); + $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $ret = $stdio->pipe($dest); @@ -330,8 +330,8 @@ public function testPipeWillReturnDestStream() public function testWritableWillBeForwardedToOutput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -345,8 +345,8 @@ public function testWritableWillBeForwardedToOutput() public function testCloseWillCloseInputAndOutput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -361,8 +361,8 @@ public function testCloseWillCloseInputAndOutput() public function testCloseTwiceWillCloseInputAndOutputOnlyOnce() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -378,8 +378,8 @@ public function testCloseTwiceWillCloseInputAndOutputOnlyOnce() public function testEndWillCloseInputAndEndOutput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -394,8 +394,8 @@ public function testEndWillCloseInputAndEndOutput() public function testEndWithDataWillWriteAndCloseInputAndEndOutput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -412,8 +412,8 @@ public function testEndWithDataWillWriteAndCloseInputAndEndOutput() public function testWriteAfterEndWillNotWriteToOutput() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -428,8 +428,8 @@ public function testWriteAfterEndWillNotWriteToOutput() public function testEndTwiceWillCloseInputAndEndOutputOnce() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -445,8 +445,8 @@ public function testEndTwiceWillCloseInputAndEndOutputOnce() public function testDataEventWillBeForwarded() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -462,7 +462,7 @@ public function testDataEventWillBeForwarded() public function testEndEventWillBeForwarded() { $input = new ReadableStream(); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -477,7 +477,7 @@ public function testEndEventWillBeForwarded() public function testErrorEventFromInputWillBeForwarded() { $input = new ReadableStream(); - $output = $this->getMock('React\Stream\WritableStreamInterface'); + $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); $readline = new Readline($input, $output); @@ -491,7 +491,7 @@ public function testErrorEventFromInputWillBeForwarded() public function testErrorEventFromOutputWillBeForwarded() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); $output = new WritableStream(); //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d701d70..58c5505 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -42,7 +42,7 @@ protected function expectCallableOnceWith($value) */ protected function createCallableMock() { - return $this->getMock('CallableStub'); + return $this->getMockBuilder('CallableStub')->getMock(); } protected function expectPromiseResolve($promise)