Skip to content

Commit ff1ff3c

Browse files
committed
Merge pull request #19 from clue-labs/deps
Update dependencies
2 parents 5e582b8 + b491881 commit ff1ff3c

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
"php": ">=5.3",
1818
"react/event-loop": "~0.4.0|~0.3.0",
1919
"react/promise": "~2.1|~1.1",
20-
"clue/buzz-react": "~0.4.1",
20+
"clue/buzz-react": "^0.5",
2121
"ext-simplexml": "*",
22-
"neitanod/forceutf8": "~1.4"
22+
"neitanod/forceutf8": "~1.4",
23+
"rize/uri-template": "^0.3"
2324
},
2425
"require-dev": {
2526
"clue/block-react": "~0.3.0"

src/Client.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@
77
use SimpleXMLElement;
88
use InvalidArgumentException;
99
use Clue\React\Buzz\Browser;
10-
use Clue\React\Buzz\Message\Response;
10+
use Psr\Http\Message\ResponseInterface;
1111
use React\Promise;
1212
use Clue\React\ViewVcApi\Io\Parser;
1313
use Clue\React\ViewVcApi\Io\Loader;
14+
use Rize\UriTemplate;
1415

1516
class Client
1617
{
1718
private $brower;
19+
private $parser;
20+
private $loader;
21+
private $uri;
1822

19-
public function __construct(Browser $browser, Parser $parser = null, Loader $loader = null)
23+
public function __construct(Browser $browser, Parser $parser = null, Loader $loader = null, UriTemplate $uri = null)
2024
{
2125
if ($parser === null) {
2226
$parser = new Parser();
2327
}
2428
if ($loader === null) {
2529
$loader = new Loader();
2630
}
31+
if ($uri === null) {
32+
$uri = new UriTemplate();
33+
}
2734

2835
// TODO: do not follow redirects
2936
// $browser = $this->browser->withOptions(array(
@@ -33,6 +40,7 @@ public function __construct(Browser $browser, Parser $parser = null, Loader $loa
3340
$this->browser = $browser;
3441
$this->parser = $parser;
3542
$this->loader = $loader;
43+
$this->uri = $uri;
3644
}
3745

3846
public function fetchFile($path, $revision = null)
@@ -47,7 +55,7 @@ public function fetchFile($path, $revision = null)
4755
// TODO: reject all paths with trailing slashes
4856

4957
return $this->fetch(
50-
$this->browser->resolve(
58+
$this->uri->expand(
5159
'{+path}?view=co{&pathrev}',
5260
array(
5361
'path' => $path,
@@ -67,7 +75,7 @@ public function fetchDirectory($path, $revision = null, $showAttic = false)
6775
// TODO: accessing files will redirect to file with relative location URL (not supported by clue/buzz-react)
6876

6977
return $this->fetchXml(
70-
$this->browser->resolve(
78+
$this->uri->expand(
7179
'{+path}{?pathrev,hideattic}',
7280
array(
7381
'path' => $path,
@@ -86,7 +94,7 @@ public function fetchDirectory($path, $revision = null, $showAttic = false)
8694
public function fetchPatch($path, $r1, $r2)
8795
{
8896
return $this->fetch(
89-
$this->browser->resolve(
97+
$this->uri->expand(
9098
'{+path}?view=patch{&r1,r2}',
9199
array(
92100
'path' => $path,
@@ -102,7 +110,7 @@ public function fetchLog($path, $revision = null)
102110
// TODO: invalid revision shows error page, but HTTP 200 OK
103111

104112
return $this->fetchXml(
105-
$this->browser->resolve(
113+
$this->uri->expand(
106114
'{+path}?view=log{&pathrev}',
107115
array(
108116
'path' => $path,
@@ -131,7 +139,7 @@ public function fetchAllPreviousRevisions($path)
131139
private function fetchLogXml($path)
132140
{
133141
return $this->fetchXml(
134-
$this->browser->resolve(
142+
$this->uri->expand(
135143
'{+path}?view=log',
136144
array(
137145
'path' => $path
@@ -148,7 +156,7 @@ private function fetchXml($url)
148156
private function fetch($url)
149157
{
150158
return $this->browser->get($url)->then(
151-
function (Response $response) {
159+
function (ResponseInterface $response) {
152160
return (string)$response->getBody();
153161
},
154162
function ($error) {

tests/ClientTest.php

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

33
use Clue\React\ViewVcApi\Client;
4-
use Clue\React\Buzz\Message\Response;
5-
use Clue\React\Buzz\Message\Body;
64
use React\Promise;
75
use Clue\React\Buzz\Browser;
8-
use Clue\React\Buzz\Message\Request;
6+
use Psr\Http\Message\RequestInterface;
7+
use RingCentral\Psr7\Response;
98

109
class ClientTest extends TestCase
1110
{
@@ -36,7 +35,7 @@ public function testInvalidFile()
3635

3736
public function testFetchFile()
3837
{
39-
$response = new Response('HTTP/1.0', 200, 'OK', array(), new Body('# hello'));
38+
$response = new Response(200, array(), '# hello', '1.0', 'OK');
4039

4140
$this->expectRequest($this->uri . 'README.md?view=co')->will($this->returnValue(Promise\resolve($response)));
4241

@@ -112,7 +111,7 @@ private function expectRequest($uri)
112111
{
113112
$that = $this;
114113

115-
return $this->sender->expects($this->once())->method('send')->with($this->callback(function (Request $request) use ($that, $uri) {
114+
return $this->sender->expects($this->once())->method('send')->with($this->callback(function (RequestInterface $request) use ($that, $uri) {
116115
$that->assertEquals('GET', $request->getMethod());
117116
$that->assertEquals($uri, $request->getUri());
118117

tests/FunctionalGentooClientTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use React\EventLoop\Factory as LoopFactory;
55
use Clue\React\Buzz\Browser;
66
use Clue\React\Block;
7+
use Clue\React\Buzz\Message\ResponseException;
78

89
class FunctionalGentooClientTest extends TestCase
910
{
@@ -22,18 +23,18 @@ public function setUp()
2223
$browser = new Browser($this->loop);
2324

2425
// check connectivity to given URL only once
25-
static $checked = null;
26-
if ($checked === null) {
26+
static $error = null;
27+
if ($error === null) {
2728
try {
28-
Block\await($browser->head($url), $this->loop);
29-
$checked = true;
29+
Block\await($browser->get($url), $this->loop);
30+
$error = false;
3031
} catch (Exception $e) {
31-
$checked = false;
32+
$error = $e->getMessage();
3233
}
3334
}
3435

35-
if (!$checked) {
36-
$this->markTestSkipped('Unable to reach Gentoo ViewVC');
36+
if ($error !== false) {
37+
$this->markTestSkipped('Unable to reach Gentoo ViewVC: ' . $error);
3738
}
3839

3940
$this->viewvc = new Client($browser->withBase($url));

0 commit comments

Comments
 (0)