Skip to content

Update dependencies #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ you should look into also using [clue/block-react](https://github.com/clue/php-b
The resulting blocking code could look something like this:

```php
use Clue\React\Block;

$loop = React\EventLoop\Factory::create();
$browser = new Clue\React\Buzz\Browser($loop);
$blocker = new Clue\React\Block\Blocker($loop);

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

try {
$contents = $blocker->awaitOne($promise);
$contents = Block\await($promise, $loop);
// file contents received
} catch (Exception $e) {
// an error occured while executing the request
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"require": {
"php": ">=5.3",
"react/event-loop": "~0.4.0|~0.3.0",
"clue/buzz-react": "~0.2.0",
"react/promise": "~2.1|~1.1",
"clue/buzz-react": "~0.4.0",
"ext-simplexml": "*",
"neitanod/forceutf8": "~1.4"
},
"require-dev": {
"clue/block-react": "~0.1.0"
"clue/block-react": "~0.3.0"
}
}
14 changes: 3 additions & 11 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use InvalidArgumentException;
use Clue\React\Buzz\Browser;
use Clue\React\Buzz\Message\Response;
use React\Promise\Deferred;
use React\Promise;
use Clue\React\ViewVcApi\Io\Parser;
use Clue\React\ViewVcApi\Io\Loader;

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

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

$url = $path;
Expand Down Expand Up @@ -144,12 +144,4 @@ function ($error) {
}
);
}

private function reject($with)
{
$deferred = new Deferred();
$deferred->reject($with);

return $deferred->promise();
}
}
19 changes: 10 additions & 9 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Clue\React\ViewVcApi\Client;
use Clue\React\Buzz\Message\Response;
use Clue\React\Buzz\Message\Body;
use React\Promise;

class ClientTest extends TestCase
{
Expand Down Expand Up @@ -31,8 +32,8 @@ public function testInvalidFile()

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

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

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

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

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

public function testFetchFileRevision()
{
$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()));
$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()));

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

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

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

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

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

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

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

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

public function testFetchDirectoryRevisionAttic()
{
$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()));
$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()));

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

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

public function testFetchLogRevision()
{
$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()));
$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()));

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

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

public function testFetchPatch()
{
$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()));
$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()));

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

Expand Down
22 changes: 7 additions & 15 deletions tests/FunctionalApacheClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
use Clue\React\ViewVcApi\Client;
use React\EventLoop\Factory as LoopFactory;
use Clue\React\Buzz\Browser;
use React\Promise\PromiseInterface;
use Clue\React\Block\Blocker;
use Clue\React\Block;

class FunctionalApacheClientTest extends TestCase
{
private $loop;
private $viewvc;
private $blocker;

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

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

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

$promise = $this->viewvc->fetchDirectory($path);
$files = $this->waitFor($promise);
$files = Block\await($promise, $this->loop);

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

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

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

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

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

$promise = $this->viewvc->fetchFile($file, $revision);
$this->waitFor($promise);
Block\await($promise, $this->loop);
}

public function testFetchRevisionPrevious()
Expand All @@ -73,7 +70,7 @@ public function testFetchRevisionPrevious()
$revision = '168703';

$promise = $this->viewvc->fetchRevisionPrevious($file, $revision);
$revision = $this->waitFor($promise);
$revision = Block\await($promise, $this->loop);

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

$promise = $this->viewvc->fetchRevisionPrevious($file, $revision);
$this->waitFor($promise);
}

private function waitFor(PromiseInterface $promise)
{
return $this->blocker->awaitOne($promise);
Block\await($promise, $this->loop);
}
}
16 changes: 4 additions & 12 deletions tests/FunctionalGentooClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
use Clue\React\ViewVcApi\Client;
use React\EventLoop\Factory as LoopFactory;
use Clue\React\Buzz\Browser;
use React\Promise\PromiseInterface;
use Clue\React\Block\Blocker;
use Clue\React\Block;

class FunctionalGentooClientTest extends TestCase
{
private $loop;
private $viewvc;
private $blocker;

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

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

// check connectivity to given URL only once
static $checked = null;
if ($checked === null) {
try {
$this->waitFor($browser->head($url));
Block\await($browser->head($url), $this->loop);
$checked = true;
} catch (Exception $e) {
$checked = false;
Expand All @@ -47,7 +44,7 @@ public function testFetchDirectoryAttic()
$path = '/';

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

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

$promise = $this->viewvc->fetchFile($file);
$contents = $this->waitFor($promise);
$contents = Block\await($promise, $this->loop);

$this->assertEquals("robbat2\n", $contents);
}

private function waitFor(PromiseInterface $promise)
{
return $this->blocker->awaitOne($promise);
}
}
18 changes: 0 additions & 18 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use React\Promise\Deferred;

require __DIR__ . '/../vendor/autoload.php';

class TestCase extends PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -73,22 +71,6 @@ protected function expectPromiseReject($promise)

return $promise;
}

protected function createPromiseResolved($value = null)
{
$deferred = new Deferred();
$deferred->resolve($value);

return $deferred->promise();
}

protected function createPromiseRejected($value = null)
{
$deferred = new Deferred();
$deferred->reject($value);

return $deferred->promise();
}
}

class CallableStub
Expand Down