Skip to content

Commit

Permalink
improve test of Request
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjul17 committed Dec 20, 2015
1 parent 52ccb90 commit c9e4dfe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -114,7 +113,7 @@ public function callAsync ($method, $params) {
$promise->reject($e);
throw $e;
}
}, function (RequestException $reqException) use ($promise, $requestId) {
}, function (\Exception $reqException) use ($promise, $requestId) {
$this->logResponse($requestId, strval($reqException));
$promise->reject($reqException);
return $reqException;
Expand Down
43 changes: 43 additions & 0 deletions tests/Request/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public function testEndPoint () {
$this->assertNull($request->getEndPoint());
$this->assertSame($request, $request->setEndPoint('endPoint'));
$this->assertEquals('endPoint', $request->getEndPoint());
$request = new Request('', '', '', '', 'endPointBis');
$this->assertSame('endPointBis', $request->getEndPoint());
}

public function testCall () {
Expand Down Expand Up @@ -124,4 +126,45 @@ public function testCallAsyncWithRequestError () {
}
}

/**
* @expectedException \RuntimeException
*/
public function testCallWithoutEndPoint () {
$request = $this->createRequest();
$request->call('', []);
}

public function testCallWithoutClientInitialize () {
$request = $this->createRequest();
$request->setEndPoint('http://github.com');
$prop = new \ReflectionProperty($request, 'client');
$prop->setAccessible(TRUE);
$this->assertNull($prop->getValue($request));
try {
$request->call('test', [])->wait();
} catch (\Exception $e) {
}
$this->assertInstanceOf(Client::class, $prop->getValue($request));
}

/**
* TODO : check that the request is not sent
*/
public function testCancelPromise () {
$request = $this->createRequest();
$request->setEndPoint('http://github.com');
$promise = $request->callAsync('method', []);
try {
$promise->cancel();
$promise->wait();
} catch (\Exception $e){

}
$this->assertSame($promise::REJECTED, $promise->getState());
}

public function testErrorResponse() {

}

}

0 comments on commit c9e4dfe

Please sign in to comment.