Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
},
"require": {
"php": ">=5.3",
"react/event-loop": "~0.3.0|~0.4.0",
"clue/buzz-react": "^0.5",
"react/promise": "~2.0|~1.1",
"clue/json-stream": "~0.1.0",
"rize/uri-template": "^0.3",
"clue/promise-stream-react": "^0.1"
"clue/buzz-react": "^2.0",
"clue/json-stream": "^0.1",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/promise": "^2.0 || ^1.1",
"react/promise-stream": "^1.0",
"react/socket": "^1.0",
"react/stream": "^1.0",
"rize/uri-template": "^0.3"
},
"require-dev": {
"clue/block-react": "~0.3.0",
"clue/caret-notation": "~0.2.0",
"clue/tar-react": "~0.1.0",
"clue/block-react": "^1.0 || ^0.3",
"clue/caret-notation": "^0.2",
"clue/tar-react": "^0.2",
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
}
}
13 changes: 7 additions & 6 deletions examples/exec-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
// displays the streaming output as it happens.

use Clue\React\Docker\Client;
use React\Stream\Stream;
use React\Stream\WritableResourceStream;

require __DIR__ . '/../vendor/autoload.php';

if (DIRECTORY_SEPARATOR === '\\') {
exit('File I/O not supported on Windows' . PHP_EOL);
}

$container = 'asd';
//$cmd = array('echo', 'hello world');
//$cmd = array('sleep', '2');
Expand All @@ -22,11 +26,8 @@
$loop = React\EventLoop\Factory::create();
$client = new Client($loop);

$out = new Stream(STDOUT, $loop);
$out->pause();

$stderr = new Stream(STDERR, $loop);
$stderr->pause();
$out = new WritableResourceStream(STDOUT, $loop);
$stderr = new WritableResourceStream(STDERR, $loop);

// unkown exit code by default
$exit = 1;
Expand Down
9 changes: 6 additions & 3 deletions examples/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
// and how we it can be piped into a output tar file.

use Clue\React\Docker\Client;
use React\Stream\Stream;
use React\Stream\WritableResourceStream;

require __DIR__ . '/../vendor/autoload.php';

if (DIRECTORY_SEPARATOR === '\\') {
exit('File I/O not supported on Windows' . PHP_EOL);
}

$container = isset($argv[1]) ? $argv[1] : 'asd';
$target = isset($argv[2]) ? $argv[2] : ($container . '.tar');
echo 'Exporting whole container "' . $container . '" to "' . $target .'" (pass as arguments to this example)' . PHP_EOL;
Expand All @@ -22,8 +26,7 @@
echo 'ERROR requesting stream' . PHP_EOL . $e;
});

$out = new Stream(fopen($target, 'w'), $loop);
$out->pause();
$out = new WritableResourceStream(fopen($target, 'w'), $loop);
$stream->pipe($out);

$loop->run();
6 changes: 4 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function __construct(LoopInterface $loop, $url = null)

if (substr($url, 0, 7) === 'unix://') {
// send everything through a local unix domain socket
$browser = $browser->withSender(
Sender::createFromLoopUnix($loop, $url)
$connector = new \React\Socket\FixedUriConnector(
$url,
new \React\Socket\UnixConnector($loop)
);

// pretend all HTTP URLs to be on localhost
$browser = new Browser($loop, $connector);
$url = 'http://localhost/';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Io/StreamingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Clue\React\Docker\Io;

use Clue\React\Promise\Stream;
use Psr\Http\Message\ResponseInterface;
use React\Promise\PromiseInterface;
use React\Promise\Deferred;
use React\Promise\PromiseInterface;
use React\Promise\Stream;
use React\Stream\ReadableStreamInterface;
use RuntimeException;

Expand Down
15 changes: 3 additions & 12 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Clue\Tests\React\Docker;

use Clue\React\Buzz\Browser;
use Clue\React\Docker\Client;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -13,7 +12,6 @@
class ClientTest extends TestCase
{
private $loop;
private $sender;
private $browser;

private $parser;
Expand All @@ -23,9 +21,7 @@ class ClientTest extends TestCase
public function setUp()
{
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->sender = $this->getMockBuilder('Clue\React\Buzz\Io\Sender')->disableOriginalConstructor()->getMock();
$this->browser = new Browser($this->loop, $this->sender);
$this->browser = $this->browser->withBase('http://x/');
$this->browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();

$this->parser = $this->getMockBuilder('Clue\React\Docker\Io\ResponseParser')->getMock();
$this->streamingParser = $this->getMockBuilder('Clue\React\Docker\Io\StreamingParser')->getMock();
Expand Down Expand Up @@ -562,13 +558,8 @@ private function expectRequestFlow($method, $url, ResponseInterface $response, $

private function expectRequest($method, $url, ResponseInterface $response)
{
$that = $this;
$this->sender->expects($this->once())->method('send')->with($this->callback(function (RequestInterface $request) use ($that, $method, $url) {
$that->assertEquals(strtoupper($method), $request->getMethod());
$that->assertEquals('http://x' . $url, (string)$request->getUri());

return true;
}))->will($this->returnPromise($response));
$this->browser->expects($this->any())->method('withOptions')->willReturnSelf();
$this->browser->expects($this->once())->method(strtolower($method))->with($url)->willReturn(\React\Promise\resolve($response));
}

private function createResponse($body = '')
Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionalClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Clue\React\Block;
use Clue\React\Docker\Client;
use Clue\React\Promise\Stream;
use React\EventLoop\Factory as LoopFactory;
use React\Promise\Stream;

class FunctionalClientTest extends TestCase
{
Expand Down
7 changes: 3 additions & 4 deletions tests/Io/ReadableDemultiplexStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Clue\React\Docker\Io\ReadableDemultiplexStream;
use Clue\Tests\React\Docker\TestCase;
use React\Stream\ReadableStream;
use React\Stream\WritableStream;
use React\Stream\ThroughStream;

class ReadableDemultiplexStreamTest extends TestCase
{
Expand All @@ -14,7 +13,7 @@ class ReadableDemultiplexStreamTest extends TestCase

public function setUp()
{
$this->stream = new ReadableStream();
$this->stream = new ThroughStream();
$this->parser = new ReadableDemultiplexStream($this->stream);
}

Expand Down Expand Up @@ -106,7 +105,7 @@ public function testCloseTwiceWillEmitCloseOnceAndRemoveAllListeners()

public function testPipeWillBeForwardedToTargetStream()
{
$target = new WritableStream();
$target = new ThroughStream();
$target->on('pipe', $this->expectCallableOnceWith($this->parser));

$this->parser->pipe($target);
Expand Down
7 changes: 3 additions & 4 deletions tests/Io/ReadableJsonStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Clue\React\Docker\Io\ReadableJsonStream;
use Clue\Tests\React\Docker\TestCase;
use React\Stream\ReadableStream;
use React\Stream\WritableStream;
use React\Stream\ThroughStream;

class ReadableJsonStreamTest extends TestCase
{
Expand All @@ -14,7 +13,7 @@ class ReadableJsonStreamTest extends TestCase

public function setUp()
{
$this->stream = new ReadableStream();
$this->stream = new ThroughStream();
$this->parser = new ReadableJsonStream($this->stream);
}

Expand Down Expand Up @@ -129,7 +128,7 @@ public function testCloseTwiceWillEmitCloseOnceAndRemoveAllListeners()

public function testPipeWillBeForwardedToTargetStream()
{
$target = new WritableStream();
$target = new ThroughStream();
$target->on('pipe', $this->expectCallableOnceWith($this->parser));

$this->parser->pipe($target);
Expand Down
16 changes: 8 additions & 8 deletions tests/Io/StreamingParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use React\Promise;
use React\Promise\CancellablePromiseInterface;
use React\Promise\Deferred;
use React\Stream\ReadableStream;
use React\Stream\ThroughStream;

class StreamingParserTest extends TestCase
{
Expand All @@ -20,7 +20,7 @@ public function setUp()

public function testJsonPassingRejectedPromiseResolvesWithClosedStream()
{
$stream = $this->parser->parseJsonStream(Promise\reject());
$stream = $this->parser->parseJsonStream(Promise\reject(new \RuntimeException()));

$this->assertInstanceOf('React\Stream\ReadableStreamInterface', $stream);
$this->assertFalse($stream->isReadable());
Expand Down Expand Up @@ -62,7 +62,7 @@ public function testJsonResolvingPromiseWithWrongValueWillEmitErrorAndCloseEvent

public function testPlainPassingRejectedPromiseResolvesWithClosedStream()
{
$stream = $this->parser->parsePlainStream(Promise\reject());
$stream = $this->parser->parsePlainStream(Promise\reject(new \RuntimeException()));

$this->assertInstanceOf('React\Stream\ReadableStreamInterface', $stream);
$this->assertFalse($stream->isReadable());
Expand All @@ -79,7 +79,7 @@ public function testDeferredClosedStreamWillReject()

public function testDeferredStreamEventsWillBeEmittedAndBuffered()
{
$stream = new ReadableStream();
$stream = new ThroughStream();

$promise = $this->parser->deferredStream($stream);

Expand All @@ -94,20 +94,20 @@ public function testDeferredStreamEventsWillBeEmittedAndBuffered()

public function testDeferredStreamErrorEventWillRejectPromise()
{
$stream = new ReadableStream();
$stream = new ThroughStream();

$promise = $this->parser->deferredStream($stream);

$stream->emit('ignored', array('ignored'));

$stream->emit('data', array('a'));

$stream->emit('error', array('value', 'ignord'));
$stream->emit('error', array(new \RuntimeException()));

$stream->close();

$this->expectPromiseReject($promise);
$promise->then(null, $this->expectCallableOnceWith('value'));
$promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
}

public function testDeferredCancelingPromiseWillCloseStream()
Expand All @@ -126,7 +126,7 @@ public function testDeferredCancelingPromiseWillCloseStream()

public function testDemultiplexStreamWillReturnReadable()
{
$stream = new ReadableStream();
$stream = new ThroughStream();

$out = $this->parser->demultiplexStream($stream);

Expand Down