Skip to content

Commit 7c5842a

Browse files
committed
Update to new Promise API (keeping BC)
1 parent 76b4813 commit 7c5842a

File tree

6 files changed

+13
-39
lines changed

6 files changed

+13
-39
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"require": {
1717
"php": ">=5.3",
1818
"react/event-loop": "~0.4.0|~0.3.0",
19+
"react/promise": "~2.1|~1.1",
1920
"clue/buzz-react": "~0.4.0",
2021
"ext-simplexml": "*",
2122
"neitanod/forceutf8": "~1.4"

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: 9 additions & 8 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
{
@@ -32,7 +33,7 @@ public function testInvalidFile()
3233
public function testFetchFile()
3334
{
3435
$response = new Response('HTTP/1.0', 200, 'OK', array(), 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)));
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use Clue\React\ViewVcApi\Client;
44
use React\EventLoop\Factory as LoopFactory;
55
use Clue\React\Buzz\Browser;
6-
use React\Promise\PromiseInterface;
76
use Clue\React\Block;
87

98
class FunctionalApacheClientTest extends TestCase

tests/FunctionalGentooClientTest.php

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

98
class FunctionalGentooClientTest extends TestCase

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)