Skip to content

Commit a1055e0

Browse files
committed
Use clue/block-react for blocking tests
1 parent 55623c9 commit a1055e0

3 files changed

Lines changed: 11 additions & 31 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"require-dev": {
2424
"clue/tar-react": "~0.1.0",
25-
"clue/caret-notation": "~0.2.0"
25+
"clue/caret-notation": "~0.2.0",
26+
"clue/block-react": "~0.3.0"
2627
}
2728
}

tests/FunctionalClientTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Clue\React\Docker\Client;
44
use React\EventLoop\Factory as LoopFactory;
55
use Clue\React\Docker\Factory;
6+
use Clue\React\Block;
67

78
class FunctionalClientTest extends TestCase
89
{
@@ -19,7 +20,7 @@ public function setUp()
1920
$promise = $this->client->ping();
2021

2122
try {
22-
$this->waitFor($promise, $this->loop);
23+
Block\await($promise, $this->loop);
2324
} catch (Exception $e) {
2425
$this->markTestSkipped('Unable to connect to docker ' . $e->getMessage());
2526
}
@@ -40,18 +41,18 @@ public function testCreateStartAndRemoveContainer()
4041
);
4142

4243
$promise = $this->client->containerCreate($config);
43-
$container = $this->waitFor($promise, $this->loop);
44+
$container = Block\await($promise, $this->loop);
4445

4546
$this->assertNotNull($container['Id']);
4647
$this->assertNull($container['Warnings']);
4748

4849
$promise = $this->client->containerStart($container['Id']);
49-
$ret = $this->waitFor($promise, $this->loop);
50+
$ret = Block\await($promise, $this->loop);
5051

5152
$this->assertEquals('', $ret);
5253

5354
$promise = $this->client->containerRemove($container['Id'], false, true);
54-
$ret = $this->waitFor($promise, $this->loop);
55+
$ret = Block\await($promise, $this->loop);
5556

5657
$this->assertEquals('', $ret);
5758
}
@@ -62,13 +63,13 @@ public function testCreateStartAndRemoveContainer()
6263
public function testContainerRemoveInvalid()
6364
{
6465
$promise = $this->client->containerRemove('invalid123');
65-
$this->waitFor($promise, $this->loop);
66+
Block\await($promise, $this->loop);
6667
}
6768

6869
public function testImageSearch()
6970
{
7071
$promise = $this->client->imageSearch('clue');
71-
$ret = $this->waitFor($promise, $this->loop);
72+
$ret = Block\await($promise, $this->loop);
7273

7374
$this->assertGreaterThan(9, count($ret));
7475
}
@@ -77,11 +78,11 @@ public function testImageTag()
7778
{
7879
// create new tag "bb:now" on "busybox:latest"
7980
$promise = $this->client->imageTag('busybox', 'bb', 'now');
80-
$ret = $this->waitFor($promise, $this->loop);
81+
$ret = Block\await($promise, $this->loop);
8182

8283
// delete tag "bb:now" again
8384
$promise = $this->client->imageRemove('bb:now');
84-
$ret = $this->waitFor($promise, $this->loop);
85+
$ret = Block\await($promise, $this->loop);
8586
}
8687

8788
public function testImageCreateStreamMissingWillEmitJsonError()

tests/bootstrap.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,6 @@ protected function expectPromiseReject($promise)
8484

8585
return $promise;
8686
}
87-
88-
protected function waitFor(PromiseInterface $promise, LoopInterface $loop)
89-
{
90-
$resolved = null;
91-
$exception = null;
92-
93-
$promise->then(function ($c) use (&$resolved) {
94-
$resolved = $c;
95-
}, function($error) use (&$exception) {
96-
$exception = $error;
97-
});
98-
99-
while ($resolved === null && $exception === null) {
100-
$loop->tick();
101-
}
102-
103-
if ($exception !== null) {
104-
throw $exception;
105-
}
106-
107-
return $resolved;
108-
}
10987
}
11088

11189
class CallableStub

0 commit comments

Comments
 (0)