Skip to content

Commit 98d5c14

Browse files
committed
Merge pull request #16 from clue-labs/update
Update dependencies
2 parents ac3150c + 7c5842a commit 98d5c14

File tree

7 files changed

+30
-69
lines changed

7 files changed

+30
-69
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
"require": {
1717
"php": ">=5.3",
1818
"react/event-loop": "~0.4.0|~0.3.0",
19-
"clue/buzz-react": "~0.2.0",
19+
"react/promise": "~2.1|~1.1",
20+
"clue/buzz-react": "~0.4.0",
2021
"ext-simplexml": "*",
2122
"neitanod/forceutf8": "~1.4"
2223
},
2324
"require-dev": {
24-
"clue/block-react": "~0.1.0"
25+
"clue/block-react": "~0.3.0"
2526
}
2627
}

src/Client.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use InvalidArgumentException;
99
use Clue\React\Buzz\Browser;
1010
use Clue\React\Buzz\Message\Response;
11-
use React\Promise\Deferred;
11+
use React\Promise;
1212
use Clue\React\ViewVcApi\Io\Parser;
1313
use Clue\React\ViewVcApi\Io\Loader;
1414

@@ -40,7 +40,7 @@ public function __construct($url, Browser $browser, Parser $parser = null, Loade
4040
public function fetchFile($path, $revision = null)
4141
{
4242
if (substr($path, -1) === '/') {
43-
return $this->reject(new InvalidArgumentException('File path MUST NOT end with trailing slash'));
43+
return Promise\reject(new InvalidArgumentException('File path MUST NOT end with trailing slash'));
4444
}
4545

4646
$url = $path . '?view=co';
@@ -59,7 +59,7 @@ public function fetchFile($path, $revision = null)
5959
public function fetchDirectory($path, $revision = null, $showAttic = false)
6060
{
6161
if (substr($path, -1) !== '/') {
62-
return $this->reject(new InvalidArgumentException('Directory path MUST end with trailing slash'));
62+
return Promise\reject(new InvalidArgumentException('Directory path MUST end with trailing slash'));
6363
}
6464

6565
$url = $path;
@@ -144,12 +144,4 @@ function ($error) {
144144
}
145145
);
146146
}
147-
148-
private function reject($with)
149-
{
150-
$deferred = new Deferred();
151-
$deferred->reject($with);
152-
153-
return $deferred->promise();
154-
}
155147
}

tests/ClientTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Clue\React\ViewVcApi\Client;
44
use Clue\React\Buzz\Message\Response;
55
use Clue\React\Buzz\Message\Body;
6+
use React\Promise;
67

78
class ClientTest extends TestCase
89
{
@@ -31,8 +32,8 @@ public function testInvalidFile()
3132

3233
public function testFetchFile()
3334
{
34-
$response = new Response('HTTP/1.0', 200, 'OK', null, new Body('# hello'));
35-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=co'))->will($this->returnValue($this->createPromiseResolved($response)));
35+
$response = new Response('HTTP/1.0', 200, 'OK', array(), new Body('# hello'));
36+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=co'))->will($this->returnValue(Promise\resolve($response)));
3637

3738
$promise = $this->client->fetchFile('README.md');
3839

@@ -41,7 +42,7 @@ public function testFetchFile()
4142

4243
public function testFetchFileExcessiveSlashesAreIgnored()
4344
{
44-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=co'))->will($this->returnValue($this->createPromiseRejected()));
45+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=co'))->will($this->returnValue(Promise\reject()));
4546

4647
$client = new Client($this->url . '/', $this->browser);
4748
$promise = $client->fetchFile('/README.md');
@@ -51,7 +52,7 @@ public function testFetchFileExcessiveSlashesAreIgnored()
5152

5253
public function testFetchFileRevision()
5354
{
54-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=co&pathrev=1.0'))->will($this->returnValue($this->createPromiseRejected()));
55+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=co&pathrev=1.0'))->will($this->returnValue(Promise\reject()));
5556

5657
$promise = $this->client->fetchFile('/README.md', '1.0');
5758

@@ -60,7 +61,7 @@ public function testFetchFileRevision()
6061

6162
public function testFetchDirectoryRevision()
6263
{
63-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?pathrev=1.0'))->will($this->returnValue($this->createPromiseRejected()));
64+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?pathrev=1.0'))->will($this->returnValue(Promise\reject()));
6465

6566
$promise = $this->client->fetchDirectory('/directory/', '1.0');
6667

@@ -69,7 +70,7 @@ public function testFetchDirectoryRevision()
6970

7071
public function testFetchDirectoryAttic()
7172
{
72-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?hideattic=0'))->will($this->returnValue($this->createPromiseRejected()));
73+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?hideattic=0'))->will($this->returnValue(Promise\reject()));
7374

7475
$promise = $this->client->fetchDirectory('/directory/', null, true);
7576

@@ -78,7 +79,7 @@ public function testFetchDirectoryAttic()
7879

7980
public function testFetchDirectoryRevisionAttic()
8081
{
81-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?pathrev=1.1&hideattic=0'))->will($this->returnValue($this->createPromiseRejected()));
82+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/directory/?pathrev=1.1&hideattic=0'))->will($this->returnValue(Promise\reject()));
8283

8384
$promise = $this->client->fetchDirectory('/directory/', '1.1', true);
8485

@@ -87,7 +88,7 @@ public function testFetchDirectoryRevisionAttic()
8788

8889
public function testFetchLogRevision()
8990
{
90-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=log&pathrev=1.0'))->will($this->returnValue($this->createPromiseRejected()));
91+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=log&pathrev=1.0'))->will($this->returnValue(Promise\reject()));
9192

9293
$promise = $this->client->fetchLog('/README.md', '1.0');
9394

@@ -96,7 +97,7 @@ public function testFetchLogRevision()
9697

9798
public function testFetchPatch()
9899
{
99-
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=patch&r1=1.0&r2=1.1'))->will($this->returnValue($this->createPromiseRejected()));
100+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://viewvc.example.org/README.md?view=patch&r1=1.0&r2=1.1'))->will($this->returnValue(Promise\reject()));
100101

101102
$promise = $this->client->fetchPatch('/README.md', '1.0', '1.1');
102103

tests/FunctionalApacheClientTest.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
use Clue\React\ViewVcApi\Client;
44
use React\EventLoop\Factory as LoopFactory;
55
use Clue\React\Buzz\Browser;
6-
use React\Promise\PromiseInterface;
7-
use Clue\React\Block\Blocker;
6+
use Clue\React\Block;
87

98
class FunctionalApacheClientTest extends TestCase
109
{
1110
private $loop;
1211
private $viewvc;
13-
private $blocker;
1412

1513
public function setUp()
1614
{
1715
$url = 'http://svn.apache.org/viewvc/';
1816

1917
$this->loop = LoopFactory::create();
20-
$this->blocker = new Blocker($this->loop);
2118
$browser = new Browser($this->loop);
2219

2320
$this->viewvc = new Client($url, $browser);
@@ -28,7 +25,7 @@ public function testFetchDirectory()
2825
$path = 'jakarta/ecs/';
2926

3027
$promise = $this->viewvc->fetchDirectory($path);
31-
$files = $this->waitFor($promise);
28+
$files = Block\await($promise, $this->loop);
3229

3330
$this->assertEquals(array('branches/', 'tags/', 'trunk/'), $files);
3431
}
@@ -39,7 +36,7 @@ public function testFetchFile()
3936
$revision = '168703';
4037

4138
$promise = $this->viewvc->fetchFile($file, $revision);
42-
$recipe = $this->waitFor($promise);
39+
$recipe = Block\await($promise, $this->loop);
4340

4441
$this->assertStringStartsWith('/*', $recipe);
4542
}
@@ -50,7 +47,7 @@ public function testFetchFileOldFileNowDeletedButRevisionAvailable()
5047
$revision = '1';
5148

5249
$promise = $this->viewvc->fetchFile($file, $revision);
53-
$contents = $this->waitFor($promise);
50+
$contents = Block\await($promise, $this->loop);
5451

5552
$this->assertStringStartsWith('APACHE COMMONS', $contents);
5653
}
@@ -64,7 +61,7 @@ public function testFetchFileInvalid()
6461
$revision = '123';
6562

6663
$promise = $this->viewvc->fetchFile($file, $revision);
67-
$this->waitFor($promise);
64+
Block\await($promise, $this->loop);
6865
}
6966

7067
public function testFetchRevisionPrevious()
@@ -73,7 +70,7 @@ public function testFetchRevisionPrevious()
7370
$revision = '168703';
7471

7572
$promise = $this->viewvc->fetchRevisionPrevious($file, $revision);
76-
$revision = $this->waitFor($promise);
73+
$revision = Block\await($promise, $this->loop);
7774

7875
$this->assertEquals('168695', $revision);
7976
}
@@ -87,11 +84,6 @@ public function testFetchRevisionUnknownBase()
8784
$revision = 'xyz';
8885

8986
$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);
87+
Block\await($promise, $this->loop);
9688
}
9789
}

tests/FunctionalGentooClientTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
use Clue\React\ViewVcApi\Client;
44
use React\EventLoop\Factory as LoopFactory;
55
use Clue\React\Buzz\Browser;
6-
use React\Promise\PromiseInterface;
7-
use Clue\React\Block\Blocker;
6+
use Clue\React\Block;
87

98
class FunctionalGentooClientTest extends TestCase
109
{
1110
private $loop;
1211
private $viewvc;
13-
private $blocker;
1412

1513
public function setUp()
1614
{
@@ -21,14 +19,13 @@ public function setUp()
2119
$url = 'https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/';
2220

2321
$this->loop = LoopFactory::create();
24-
$this->blocker = new Blocker($this->loop);
2522
$browser = new Browser($this->loop);
2623

2724
// check connectivity to given URL only once
2825
static $checked = null;
2926
if ($checked === null) {
3027
try {
31-
$this->waitFor($browser->head($url));
28+
Block\await($browser->head($url), $this->loop);
3229
$checked = true;
3330
} catch (Exception $e) {
3431
$checked = false;
@@ -47,7 +44,7 @@ public function testFetchDirectoryAttic()
4744
$path = '/';
4845

4946
$promise = $this->viewvc->fetchDirectory($path, null, true);
50-
$files = $this->waitFor($promise);
47+
$files = Block\await($promise, $this->loop);
5148

5249
$this->assertEquals(array('misc/', 'src/', 'users/', 'xml/', '.frozen'), $files);
5350
}
@@ -57,13 +54,8 @@ public function testFetchFileDeletedShowsLastState()
5754
$file = '.frozen';
5855

5956
$promise = $this->viewvc->fetchFile($file);
60-
$contents = $this->waitFor($promise);
57+
$contents = Block\await($promise, $this->loop);
6158

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

tests/bootstrap.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use React\Promise\Deferred;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

75
class TestCase extends PHPUnit_Framework_TestCase
@@ -73,22 +71,6 @@ protected function expectPromiseReject($promise)
7371

7472
return $promise;
7573
}
76-
77-
protected function createPromiseResolved($value = null)
78-
{
79-
$deferred = new Deferred();
80-
$deferred->resolve($value);
81-
82-
return $deferred->promise();
83-
}
84-
85-
protected function createPromiseRejected($value = null)
86-
{
87-
$deferred = new Deferred();
88-
$deferred->reject($value);
89-
90-
return $deferred->promise();
91-
}
9274
}
9375

9476
class CallableStub

0 commit comments

Comments
 (0)