Skip to content

Commit 76b4813

Browse files
committed
Update clue/block-react to v0.3
1 parent 173e2a2 commit 76b4813

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ you should look into also using [clue/block-react](https://github.com/clue/php-b
9090
The resulting blocking code could look something like this:
9191

9292
```php
93+
use Clue\React\Block;
94+
9395
$loop = React\EventLoop\Factory::create();
9496
$browser = new Clue\React\Buzz\Browser($loop);
95-
$blocker = new Clue\React\Block\Blocker($loop);
9697

9798
$client = new Client($url /* change me */, $browser);
9899
$promise = $client->fetchFile($path /* change me */);
99100

100101
try {
101-
$contents = $blocker->awaitOne($promise);
102+
$contents = Block\await($promise, $loop);
102103
// file contents received
103104
} catch (Exception $e) {
104105
// an error occured while executing the request

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
"neitanod/forceutf8": "~1.4"
2222
},
2323
"require-dev": {
24-
"clue/block-react": "~0.1.0"
24+
"clue/block-react": "~0.3.0"
2525
}
2626
}

tests/FunctionalApacheClientTest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
use React\EventLoop\Factory as LoopFactory;
55
use Clue\React\Buzz\Browser;
66
use React\Promise\PromiseInterface;
7-
use Clue\React\Block\Blocker;
7+
use Clue\React\Block;
88

99
class FunctionalApacheClientTest extends TestCase
1010
{
1111
private $loop;
1212
private $viewvc;
13-
private $blocker;
1413

1514
public function setUp()
1615
{
1716
$url = 'http://svn.apache.org/viewvc/';
1817

1918
$this->loop = LoopFactory::create();
20-
$this->blocker = new Blocker($this->loop);
2119
$browser = new Browser($this->loop);
2220

2321
$this->viewvc = new Client($url, $browser);
@@ -28,7 +26,7 @@ public function testFetchDirectory()
2826
$path = 'jakarta/ecs/';
2927

3028
$promise = $this->viewvc->fetchDirectory($path);
31-
$files = $this->waitFor($promise);
29+
$files = Block\await($promise, $this->loop);
3230

3331
$this->assertEquals(array('branches/', 'tags/', 'trunk/'), $files);
3432
}
@@ -39,7 +37,7 @@ public function testFetchFile()
3937
$revision = '168703';
4038

4139
$promise = $this->viewvc->fetchFile($file, $revision);
42-
$recipe = $this->waitFor($promise);
40+
$recipe = Block\await($promise, $this->loop);
4341

4442
$this->assertStringStartsWith('/*', $recipe);
4543
}
@@ -50,7 +48,7 @@ public function testFetchFileOldFileNowDeletedButRevisionAvailable()
5048
$revision = '1';
5149

5250
$promise = $this->viewvc->fetchFile($file, $revision);
53-
$contents = $this->waitFor($promise);
51+
$contents = Block\await($promise, $this->loop);
5452

5553
$this->assertStringStartsWith('APACHE COMMONS', $contents);
5654
}
@@ -64,7 +62,7 @@ public function testFetchFileInvalid()
6462
$revision = '123';
6563

6664
$promise = $this->viewvc->fetchFile($file, $revision);
67-
$this->waitFor($promise);
65+
Block\await($promise, $this->loop);
6866
}
6967

7068
public function testFetchRevisionPrevious()
@@ -73,7 +71,7 @@ public function testFetchRevisionPrevious()
7371
$revision = '168703';
7472

7573
$promise = $this->viewvc->fetchRevisionPrevious($file, $revision);
76-
$revision = $this->waitFor($promise);
74+
$revision = Block\await($promise, $this->loop);
7775

7876
$this->assertEquals('168695', $revision);
7977
}
@@ -87,11 +85,6 @@ public function testFetchRevisionUnknownBase()
8785
$revision = 'xyz';
8886

8987
$promise = $this->viewvc->fetchRevisionPrevious($file, $revision);
90-
$this->waitFor($promise);
91-
}
92-
93-
private function waitFor(PromiseInterface $promise)
94-
{
95-
return $this->blocker->awaitOne($promise);
88+
Block\await($promise, $this->loop);
9689
}
9790
}

tests/FunctionalGentooClientTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
use React\EventLoop\Factory as LoopFactory;
55
use Clue\React\Buzz\Browser;
66
use React\Promise\PromiseInterface;
7-
use Clue\React\Block\Blocker;
7+
use Clue\React\Block;
88

99
class FunctionalGentooClientTest extends TestCase
1010
{
1111
private $loop;
1212
private $viewvc;
13-
private $blocker;
1413

1514
public function setUp()
1615
{
@@ -21,14 +20,13 @@ public function setUp()
2120
$url = 'https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/';
2221

2322
$this->loop = LoopFactory::create();
24-
$this->blocker = new Blocker($this->loop);
2523
$browser = new Browser($this->loop);
2624

2725
// check connectivity to given URL only once
2826
static $checked = null;
2927
if ($checked === null) {
3028
try {
31-
$this->waitFor($browser->head($url));
29+
Block\await($browser->head($url), $this->loop);
3230
$checked = true;
3331
} catch (Exception $e) {
3432
$checked = false;
@@ -47,7 +45,7 @@ public function testFetchDirectoryAttic()
4745
$path = '/';
4846

4947
$promise = $this->viewvc->fetchDirectory($path, null, true);
50-
$files = $this->waitFor($promise);
48+
$files = Block\await($promise, $this->loop);
5149

5250
$this->assertEquals(array('misc/', 'src/', 'users/', 'xml/', '.frozen'), $files);
5351
}
@@ -57,13 +55,8 @@ public function testFetchFileDeletedShowsLastState()
5755
$file = '.frozen';
5856

5957
$promise = $this->viewvc->fetchFile($file);
60-
$contents = $this->waitFor($promise);
58+
$contents = Block\await($promise, $this->loop);
6159

6260
$this->assertEquals("robbat2\n", $contents);
6361
}
64-
65-
private function waitFor(PromiseInterface $promise)
66-
{
67-
return $this->blocker->awaitOne($promise);
68-
}
6962
}

0 commit comments

Comments
 (0)