diff --git a/.gitignore b/.gitignore index de4a392..c8153b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/vendor /composer.lock +/vendor/ diff --git a/README.md b/README.md index 95f3068..033ef8d 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,10 @@ Once [installed](#install), you can use the following code to access the Docker API of your local docker daemon: ```php +imageSearch('clue')->then(function (array $images) { @@ -379,7 +383,7 @@ 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 8+. -It's *highly recommended to use PHP 7+* for this project. +It's *highly recommended to use the latest supported PHP version* for this project. ## Tests @@ -393,7 +397,7 @@ $ composer install To run the test suite, go to the project root and run: ```bash -$ php vendor/bin/phpunit +$ vendor/bin/phpunit ``` ## License diff --git a/composer.json b/composer.json index c98b7c3..d577fc6 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,10 @@ "php": ">=5.3", "clue/json-stream": "^0.1", "react/event-loop": "^1.2", - "react/http": "^1.4", + "react/http": "^1.5", "react/promise": "^2.0 || ^1.1", "react/promise-stream": "^1.0", - "react/socket": "^1.8", + "react/socket": "^1.9", "react/stream": "^1.2", "rize/uri-template": "^0.3" }, diff --git a/examples/archive.php b/examples/archive.php index 06a9b2c..ff962de 100644 --- a/examples/archive.php +++ b/examples/archive.php @@ -4,27 +4,22 @@ // how it can be passed to a TAR decoder and how we can then pipe each // individual file to the console output. -use Clue\CaretNotation\Encoder; -use Clue\React\Docker\Client; -use Clue\React\Tar\Decoder; -use React\Stream\ReadableStreamInterface; - require __DIR__ . '/../vendor/autoload.php'; $container = isset($argv[1]) ? $argv[1] : 'asd'; $path = isset($argv[2]) ? $argv[2] : '/etc/passwd'; echo 'Container "' . $container . '" dumping "' . $path . '" (pass as arguments to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $stream = $client->containerArchiveStream($container, $path); -$tar = new Decoder(); +$tar = new Clue\React\Tar\Decoder(); // use caret notation for any control characters except \t, \r and \n -$caret = new Encoder("\t\r\n"); +$caret = new Clue\CaretNotation\Encoder("\t\r\n"); -$tar->on('entry', function ($header, ReadableStreamInterface $file) use ($caret) { +$tar->on('entry', function ($header, React\Stream\ReadableStreamInterface $file) use ($caret) { // write each entry to the console output echo '########## ' . $caret->encode($header['filename']) . ' ##########' . PHP_EOL; $file->on('data', function ($chunk) use ($caret) { diff --git a/examples/attach-stream.php b/examples/attach-stream.php index d2050fd..cae1035 100644 --- a/examples/attach-stream.php +++ b/examples/attach-stream.php @@ -6,18 +6,15 @@ // $ docker run -it --rm --name=foo busybox sh // $ php examples/attach-stream.php foo -use Clue\CaretNotation\Encoder; -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; $container = isset($argv[1]) ? $argv[1] : 'foo'; echo 'Dumping output of container "' . $container . '" (pass as argument to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); // use caret notation for any control characters except \t, \r and \n -$caret = new Encoder("\t\r\n"); +$caret = new Clue\CaretNotation\Encoder("\t\r\n"); $stream = $client->containerAttachStream($container, true, true); $stream->on('data', function ($data) use ($caret) { diff --git a/examples/benchmark-attach.php b/examples/benchmark-attach.php index 05f7f0c..8164065 100644 --- a/examples/benchmark-attach.php +++ b/examples/benchmark-attach.php @@ -10,7 +10,6 @@ // // $ docker run -i --rm --log-driver=none busybox dd if=/dev/zero bs=1M count=1000 status=none | dd of=/dev/null -use Clue\React\Docker\Client; use React\EventLoop\Loop; require __DIR__ . '/../vendor/autoload.php'; @@ -27,7 +26,7 @@ $cmd = array_slice($argv, 2); } -$client = new Client(); +$client = new Clue\React\Docker\Client(); $client->containerCreate(array( 'Image' => $image, diff --git a/examples/benchmark-exec.php b/examples/benchmark-exec.php index 6f7092c..ee47d6d 100644 --- a/examples/benchmark-exec.php +++ b/examples/benchmark-exec.php @@ -13,7 +13,6 @@ // // $ docker exec foo dd if=/dev/zero bs=1M count=1000 | dd of=/dev/null -use Clue\React\Docker\Client; require __DIR__ . '/../vendor/autoload.php'; @@ -29,7 +28,7 @@ $cmd = array_slice($argv, 2); } -$client = new Client(); +$client = new Clue\React\Docker\Client(); $client->execCreate($container, $cmd)->then(function ($info) use ($client) { $stream = $client->execStartStream($info['Id'], true); diff --git a/examples/events.php b/examples/events.php index e8b54d2..9612abc 100644 --- a/examples/events.php +++ b/examples/events.php @@ -3,11 +3,10 @@ // this simple example displays all docker events that happen in the next 10s. // try starting / removing a container in the meantime to see some output. -use Clue\React\Docker\Client; require __DIR__ . '/../vendor/autoload.php'; -$client = new Client(); +$client = new Clue\React\Docker\Client(); // get a list of all events that happened up until this point // expect this list to be limited to the last 64 (or so) events diff --git a/examples/exec-inspect.php b/examples/exec-inspect.php index aa3d6e9..bc68aba 100644 --- a/examples/exec-inspect.php +++ b/examples/exec-inspect.php @@ -2,9 +2,6 @@ // this simple example executes a "sleep 2" within the given running container -use Clue\React\Buzz\Message\ResponseException; -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; $container = 'asd'; @@ -18,7 +15,7 @@ $cmd = array_slice($argv, 2); } -$client = new Client(); +$client = new Clue\React\Docker\Client(); $client->execCreate($container, $cmd)->then(function ($info) use ($client) { echo 'Created with info: ' . json_encode($info) . PHP_EOL; @@ -38,7 +35,7 @@ }, function (Exception $e) { echo 'ERROR: ' . $e->getMessage() . PHP_EOL; - if ($e instanceof ResponseException) { + if ($e instanceof React\Http\Message\ResponseException) { echo 'Response: ' . $e->getResponse()->getBody() . PHP_EOL; } }); diff --git a/examples/exec-stream.php b/examples/exec-stream.php index 018b569..43ca3b8 100644 --- a/examples/exec-stream.php +++ b/examples/exec-stream.php @@ -3,9 +3,7 @@ // this example executes some commands within the given running container and // displays the streaming output as it happens. -use Clue\React\Docker\Client; use React\EventLoop\Loop; -use React\Stream\WritableResourceStream; require __DIR__ . '/../vendor/autoload.php'; @@ -24,10 +22,10 @@ $cmd = array_slice($argv, 2); } -$client = new Client(); +$client = new Clue\React\Docker\Client(); -$out = new WritableResourceStream(STDOUT); -$stderr = new WritableResourceStream(STDERR); +$out = new React\Stream\WritableResourceStream(STDOUT); +$stderr = new React\Stream\WritableResourceStream(STDERR); // unkown exit code by default $exit = 1; diff --git a/examples/export.php b/examples/export.php index 563ac2a..f45fbe0 100644 --- a/examples/export.php +++ b/examples/export.php @@ -3,9 +3,6 @@ // this example shows how the containerExport() call returns a TAR stream // and how we it can be piped into a output tar file. -use Clue\React\Docker\Client; -use React\Stream\WritableResourceStream; - require __DIR__ . '/../vendor/autoload.php'; if (DIRECTORY_SEPARATOR === '\\') { @@ -16,7 +13,7 @@ $target = isset($argv[2]) ? $argv[2] : ($container . '.tar'); echo 'Exporting whole container "' . $container . '" to "' . $target .'" (pass as arguments to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $stream = $client->containerExportStream($container); @@ -25,5 +22,5 @@ echo 'ERROR requesting stream' . PHP_EOL . $e; }); -$out = new WritableResourceStream(fopen($target, 'w')); + $out = new React\Stream\WritableResourceStream(fopen($target, 'w')); $stream->pipe($out); diff --git a/examples/info.php b/examples/info.php index e04c602..0199c39 100644 --- a/examples/info.php +++ b/examples/info.php @@ -2,11 +2,9 @@ // this simple example displays system wide information from Docker as a simple JSON -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $client->info()->then(function ($info) { echo json_encode($info, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL; diff --git a/examples/logs-stream.php b/examples/logs-stream.php index 05e317d..d031fa0 100644 --- a/examples/logs-stream.php +++ b/examples/logs-stream.php @@ -3,18 +3,15 @@ // this example shows how the containerLogsStream() call can be used to get the logs of the given container. // demonstrates the streaming logs API, which can be used to dump the logs as they arrive -use Clue\CaretNotation\Encoder; -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; $container = isset($argv[1]) ? $argv[1] : 'asd'; echo 'Dumping logs (last 100 lines) of container "' . $container . '" (pass as argument to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); // use caret notation for any control characters except \t, \r and \n -$caret = new Encoder("\t\r\n"); +$caret = new Clue\CaretNotation\Encoder("\t\r\n"); $stream = $client->containerLogsStream($container, true, true, true, 0, false, 100); $stream->on('data', function ($data) use ($caret) { diff --git a/examples/logs.php b/examples/logs.php index f870712..118eee1 100644 --- a/examples/logs.php +++ b/examples/logs.php @@ -15,14 +15,14 @@ $container = isset($argv[1]) ? $argv[1] : 'foo'; echo 'Dumping logs (last 100 lines) of container "' . $container . '" (pass as argument to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $client->containerLogs($container, false, true, true, 0, false, 100)->then( function ($logs) { echo 'Received the following logs:' . PHP_EOL; // escape control characters (dumping logs of vi/nano etc.) - $caret = new Encoder("\t\r\n"); + $caret = new Clue\CaretNotation\Encoder("\t\r\n"); echo $caret->encode($logs); }, function ($error) use ($container) { diff --git a/examples/pull.php b/examples/pull.php index e79f5e2..b8613e6 100644 --- a/examples/pull.php +++ b/examples/pull.php @@ -3,14 +3,12 @@ // this example shows how the imageCreateStream() call can be used to pull a given image. // demonstrates the JSON streaming API, individual progress events will be printed as they happen. -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; $image = isset($argv[1]) ? $argv[1] : 'clue/redis-benchmark'; echo 'Pulling image "' . $image . '" (pass as argument to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $stream = $client->imageCreateStream($image); diff --git a/examples/push.php b/examples/push.php index 3283b25..5d4dd38 100644 --- a/examples/push.php +++ b/examples/push.php @@ -3,15 +3,13 @@ // this example shows how the imagePush() call can be used to publish a given image. // this requires authorization and this example includes some invalid defaults. -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; $image = isset($argv[1]) ? $argv[1] : 'asd'; $auth = json_decode('{"username": "string", "password": "string", "email": "string", "serveraddress" : "string", "auth": ""}'); echo 'Pushing image "' . $image . '" (pass as argument to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $client->imagePush($image, null, null, $auth)->then(function ($result) { echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL; diff --git a/examples/resize.php b/examples/resize.php index 572f1b6..d9f780d 100644 --- a/examples/resize.php +++ b/examples/resize.php @@ -3,13 +3,11 @@ // this example tries to adjust the TTY size of the given container to 10x10. // you can check this via "docker logs". -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; $container = isset($argv[1]) ? $argv[1] : 'asd'; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $client->containerInspect($container)->then(function ($info) use ($client, $container) { $size = $info['HostConfig']['ConsoleSize']; diff --git a/examples/stats.php b/examples/stats.php index 982c487..07e531b 100644 --- a/examples/stats.php +++ b/examples/stats.php @@ -3,14 +3,12 @@ // this example shows how the `containerStatsStream()` method can be used show live container stats. // demonstrates the JSON streaming API, individual stats events will be printed as they happen. -use Clue\React\Docker\Client; - require __DIR__ . '/../vendor/autoload.php'; $container = isset($argv[1]) ? $argv[1] : 'asd'; echo 'Monitoring "' . $container . '" (pass as argument to this example)' . PHP_EOL; -$client = new Client(); +$client = new Clue\React\Docker\Client(); $stream = $client->containerStatsStream($container); diff --git a/src/Client.php b/src/Client.php index e66fe75..d7943d2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -79,7 +79,7 @@ public function __construct(LoopInterface $loop = null, $url = null) throw new \InvalidArgumentException('Invalid Docker Engine API URL given'); } - $browser = new Browser($loop, $connector); + $browser = new Browser($connector, $loop); $this->browser = $browser->withBase($url); $this->parser = new ResponseParser(); $this->streamingParser = new StreamingParser(); diff --git a/tests/FunctionalClientTest.php b/tests/FunctionalClientTest.php index 0a21ef8..1c1fc6e 100644 --- a/tests/FunctionalClientTest.php +++ b/tests/FunctionalClientTest.php @@ -4,7 +4,7 @@ use Clue\React\Block; use Clue\React\Docker\Client; -use React\EventLoop\Factory as LoopFactory; +use React\EventLoop\Loop; use React\Promise\Stream; class FunctionalClientTest extends TestCase @@ -16,13 +16,12 @@ class FunctionalClientTest extends TestCase */ public function setUpClient() { - $this->loop = LoopFactory::create(); - $this->client = new Client($this->loop); + $this->client = new Client(); $promise = $this->client->ping(); try { - Block\await($promise, $this->loop); + Block\await($promise, Loop::get()); } catch (\Exception $e) { $this->markTestSkipped('Unable to connect to docker ' . $e->getMessage()); } @@ -32,7 +31,7 @@ public function testPing() { $this->expectPromiseResolve($this->client->ping(), 'OK'); - $this->loop->run(); + Loop::run(); } /** @@ -43,7 +42,7 @@ public function testImageInspectCheckIfBusyboxExists() $promise = $this->client->imageInspect('busybox:latest'); try { - Block\await($promise, $this->loop); + Block\await($promise, Loop::get()); } catch (\RuntimeException $e) { $this->markTestSkipped('Image "busybox" not downloaded yet'); } @@ -60,7 +59,7 @@ public function testCreateStartAndRemoveContainer() ); $promise = $this->client->containerCreate($config); - $container = Block\await($promise, $this->loop); + $container = Block\await($promise, Loop::get()); $this->assertNotNull($container['Id']); $this->assertEmpty($container['Warnings']); @@ -68,22 +67,22 @@ public function testCreateStartAndRemoveContainer() $start = microtime(true); $promise = $this->client->containerStart($container['Id']); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals('', $ret); $promise = $this->client->containerLogs($container['Id'], false, true, true); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals("test\n", $ret); $promise = $this->client->containerAttach($container['Id'], true, false); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals("test\n", $ret); $promise = $this->client->containerRemove($container['Id'], false, true); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals('', $ret); @@ -91,7 +90,7 @@ public function testCreateStartAndRemoveContainer() // get all events between starting and removing for this container $promise = $this->client->events($start, $end, array('container' => array($container['Id']))); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); // expects "start", "attach", "kill", "die", "destroy" events $this->assertEquals(5, count($ret)); @@ -114,13 +113,13 @@ public function testStartRunning() ); $promise = $this->client->containerCreate($config); - $container = Block\await($promise, $this->loop); + $container = Block\await($promise, Loop::get()); $this->assertNotNull($container['Id']); $this->assertEmpty($container['Warnings']); $promise = $this->client->containerStart($container['Id']); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals('', $ret); @@ -135,7 +134,7 @@ public function testStartRunning() public function testExecCreateWhileRunning($container) { $promise = $this->client->execCreate($container, array('echo', '-n', 'hello', 'world')); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); @@ -150,7 +149,7 @@ public function testExecCreateWhileRunning($container) public function testExecInspectBeforeRunning($exec) { $promise = $this->client->execInspect($exec); - $info = Block\await($promise, $this->loop); + $info = Block\await($promise, Loop::get()); $this->assertTrue(is_array($info)); $this->assertFalse($info['Running']); @@ -164,7 +163,7 @@ public function testExecInspectBeforeRunning($exec) public function testExecStartWhileRunning($exec) { $promise = $this->client->execStart($exec); - $output = Block\await($promise, $this->loop); + $output = Block\await($promise, Loop::get()); $this->assertEquals('hello world', $output); } @@ -176,7 +175,7 @@ public function testExecStartWhileRunning($exec) public function testExecInspectAfterRunning($exec) { $promise = $this->client->execInspect($exec); - $info = Block\await($promise, $this->loop); + $info = Block\await($promise, Loop::get()); $this->assertTrue(is_array($info)); $this->assertFalse($info['Running']); @@ -190,13 +189,13 @@ public function testExecInspectAfterRunning($exec) public function testExecStringCommandWithOutputWhileRunning($container) { $promise = $this->client->execCreate($container, 'echo -n hello world'); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); $promise = $this->client->execStart($exec['Id']); - $output = Block\await($promise, $this->loop); + $output = Block\await($promise, Loop::get()); $this->assertEquals('hello world', $output); } @@ -208,7 +207,7 @@ public function testExecStringCommandWithOutputWhileRunning($container) public function testExecStreamOutputInMultipleChunksWhileRunning($container) { $promise = $this->client->execCreate($container, 'echo -n hello && sleep 0.2 && echo -n world'); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); @@ -217,7 +216,7 @@ public function testExecStreamOutputInMultipleChunksWhileRunning($container) $stream->once('data', $this->expectCallableOnceWith('hello')); $stream->on('end', $this->expectCallableOnce()); - $output = Block\await(Stream\buffer($stream), $this->loop); + $output = Block\await(Stream\buffer($stream), Loop::get()); $this->assertEquals('helloworld', $output); } @@ -229,13 +228,13 @@ public function testExecStreamOutputInMultipleChunksWhileRunning($container) public function testExecUserSpecificCommandWithOutputWhileRunning($container) { $promise = $this->client->execCreate($container, 'whoami', false, false, true, true, 'nobody'); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); $promise = $this->client->execStart($exec['Id']); - $output = Block\await($promise, $this->loop); + $output = Block\await($promise, Loop::get()); $this->assertEquals('nobody', rtrim($output)); } @@ -247,13 +246,13 @@ public function testExecUserSpecificCommandWithOutputWhileRunning($container) public function testExecStringCommandWithStderrOutputWhileRunning($container) { $promise = $this->client->execCreate($container, 'echo -n hello world >&2'); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); $promise = $this->client->execStart($exec['Id']); - $output = Block\await($promise, $this->loop); + $output = Block\await($promise, Loop::get()); $this->assertEquals('hello world', $output); } @@ -265,7 +264,7 @@ public function testExecStringCommandWithStderrOutputWhileRunning($container) public function testExecStreamCommandWithTtyAndStderrOutputWhileRunning($container) { $promise = $this->client->execCreate($container, 'echo -n hello world >&2', true); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); @@ -274,7 +273,7 @@ public function testExecStreamCommandWithTtyAndStderrOutputWhileRunning($contain $stream->once('data', $this->expectCallableOnce('hello world')); $stream->on('end', $this->expectCallableOnce()); - $output = Block\await(Stream\buffer($stream), $this->loop); + $output = Block\await(Stream\buffer($stream), Loop::get()); $this->assertEquals('hello world', $output); } @@ -286,7 +285,7 @@ public function testExecStreamCommandWithTtyAndStderrOutputWhileRunning($contain public function testExecStreamStderrCustomEventWhileRunning($container) { $promise = $this->client->execCreate($container, 'echo -n hello world >&2'); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); @@ -297,7 +296,7 @@ public function testExecStreamStderrCustomEventWhileRunning($container) $stream->on('error', $this->expectCallableNever()); $stream->on('end', $this->expectCallableOnce()); - $output = Block\await(Stream\buffer($stream), $this->loop); + $output = Block\await(Stream\buffer($stream), Loop::get()); $this->assertEquals('', $output); } @@ -309,7 +308,7 @@ public function testExecStreamStderrCustomEventWhileRunning($container) public function testExecStreamEmptyOutputWhileRunning($container) { $promise = $this->client->execCreate($container, array('true')); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); @@ -317,7 +316,7 @@ public function testExecStreamEmptyOutputWhileRunning($container) $stream = $this->client->execStartStream($exec['Id'], true); $stream->on('end', $this->expectCallableOnce()); - $output = Block\await(Stream\buffer($stream), $this->loop); + $output = Block\await(Stream\buffer($stream), Loop::get()); $this->assertEquals('', $output); } @@ -329,13 +328,13 @@ public function testExecStreamEmptyOutputWhileRunning($container) public function testExecDetachedWhileRunning($container) { $promise = $this->client->execCreate($container, array('sleep', '10')); - $exec = Block\await($promise, $this->loop); + $exec = Block\await($promise, Loop::get()); $this->assertTrue(is_array($exec)); $this->assertTrue(is_string($exec['Id'])); $promise = $this->client->execStartDetached($exec['Id'], true); - $output = Block\await($promise, $this->loop); + $output = Block\await($promise, Loop::get()); $this->assertEquals('', $output); } @@ -347,7 +346,7 @@ public function testExecDetachedWhileRunning($container) public function testRemoveRunning($container) { $promise = $this->client->containerRemove($container, true, true); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals('', $ret); } @@ -356,13 +355,13 @@ public function testContainerRemoveInvalid() { $promise = $this->client->containerRemove('invalid123'); $this->setExpectedException('RuntimeException'); - Block\await($promise, $this->loop); + Block\await($promise, Loop::get()); } public function testImageSearch() { $promise = $this->client->imageSearch('clue'); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertGreaterThan(9, count($ret)); } @@ -375,17 +374,17 @@ public function testImageTag() { // create new tag "bb:now" on "busybox:latest" $promise = $this->client->imageTag('busybox', 'bb', 'now'); - Block\await($promise, $this->loop); + Block\await($promise, Loop::get()); // delete tag "bb:now" again $promise = $this->client->imageRemove('bb:now'); - Block\await($promise, $this->loop); + Block\await($promise, Loop::get()); } public function testImageCreateStreamMissingWillEmitJsonError() { $promise = $this->client->version(); - $version = Block\await($promise, $this->loop); + $version = Block\await($promise, Loop::get()); // old API reports a progress with error message, newer API just returns 404 right away // https://docs.docker.com/engine/api/version-history/ @@ -403,28 +402,28 @@ public function testImageCreateStreamMissingWillEmitJsonError() $old || $stream->on('error', $this->expectCallableOnceParameter('React\Http\Message\ResponseException')); $stream->on('close', $this->expectCallableOnce()); - $this->loop->run(); + Loop::run(); } public function testInfo() { $this->expectPromiseResolve($this->client->info()); - $this->loop->run(); + Loop::run(); } public function testVersion() { $this->expectPromiseResolve($this->client->version()); - $this->loop->run(); + Loop::run(); } public function testContainerList() { $this->expectPromiseResolve($this->client->containerList()); - $this->loop->run(); + Loop::run(); } /** @@ -439,39 +438,39 @@ public function testCreateConnectDisconnectAndRemoveNetwork() $networkName = uniqid('reactphp-docker'); $promise = $this->client->containerCreate($containerConfig); - $container = Block\await($promise, $this->loop); + $container = Block\await($promise, Loop::get()); $start = microtime(true); $promise = $this->client->networkCreate($networkName); - $network = Block\await($promise, $this->loop); + $network = Block\await($promise, Loop::get()); $this->assertNotNull($network['Id']); $this->assertEquals('', $network['Warning']); $promise = $this->client->networkConnect($network['Id'], $container['Id']); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals('', $ret); $promise = $this->client->networkDisconnect($network['Id'], $container['Id'], false); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals('', $ret); $promise = $this->client->networkRemove($network['Id']); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); $this->assertEquals('', $ret); $end = microtime(true); $promise = $this->client->containerRemove($container['Id']); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); // get all events between starting and removing for this container $promise = $this->client->events($start, $end, array('network' => array($network['Id']))); - $ret = Block\await($promise, $this->loop); + $ret = Block\await($promise, Loop::get()); // expects "create", "disconnect", "destroy" events ("connect" will be skipped because we don't start the container) $this->assertEquals(3, count($ret)); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index e6cf710..55c0357 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -3,19 +3,18 @@ namespace Clue\Tests\React\Docker; use Clue\React\Docker\Client; -use React\Promise\Deferred; use Psr\Http\Message\ServerRequestInterface; +use React\EventLoop\Loop; +use React\Promise\Deferred; class IntegrationTest extends TestCase { public function testPingCtorWithExplicitUnixUrlSendsRequestToGivenUnixSocket() { - $loop = \React\EventLoop\Factory::create(); - for ($i = 0; $i < 3; ++$i) { $path = sys_get_temp_dir() . '/clue-reactphp-docker.' . mt_rand() . '.sock'; try { - $socket = new \React\Socket\Server('unix://' . $path , $loop); + $socket = new \React\Socket\SocketServer('unix://' . $path); break; } catch (\Exception $e) { $path = null; @@ -26,16 +25,16 @@ public function testPingCtorWithExplicitUnixUrlSendsRequestToGivenUnixSocket() } $deferred = new Deferred(); - $http = new \React\Http\Server($loop, function (ServerRequestInterface $request) use ($deferred) { + $http = new \React\Http\HttpServer(function (ServerRequestInterface $request) use ($deferred) { $deferred->resolve($request->getRequestTarget()); }); $http->listen($socket); - $client = new Client($loop, 'unix://' . $path); + $client = new Client(null, 'unix://' . $path); $client->ping(); - $value = \Clue\React\Block\await($deferred->promise(), $loop, 1.0); + $value = \Clue\React\Block\await($deferred->promise(), Loop::get(), 1.0); unlink($path); $this->assertEquals('/_ping', $value); @@ -43,17 +42,17 @@ public function testPingCtorWithExplicitUnixUrlSendsRequestToGivenUnixSocket() public function testPingCtorWithExplicitHttpUrlSendsRequestToGivenHttpUrlWithBase() { - $loop = \React\EventLoop\Factory::create(); + $loop = Loop::get(); $deferred = new Deferred(); - $http = new \React\Http\Server($loop, function (ServerRequestInterface $request) use ($deferred) { + $http = new \React\Http\HttpServer(function (ServerRequestInterface $request) use ($deferred) { $deferred->resolve($request->getRequestTarget()); }); - $socket = new \React\Socket\Server(0, $loop); + $socket = new \React\Socket\SocketServer('127.0.0.1:0'); $http->listen($socket); - $client = new Client($loop, str_replace('tcp://', 'http://', $socket->getAddress()) . '/base/'); + $client = new Client(null, str_replace('tcp://', 'http://', $socket->getAddress()) . '/base/'); $client->ping(); $value = \Clue\React\Block\await($deferred->promise(), $loop, 1.0);