-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from xp-forge/feature/timeout
Add possibility to modify read and connect timeouts
- Loading branch information
Showing
4 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/php/webservices/rest/unittest/TimeoutTest.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php namespace webservices\rest\unittest; | ||
|
||
use peer\http\HttpConnection; | ||
use unittest\{Assert, Before, Test}; | ||
use webservices\rest\{Endpoint, RestRequest}; | ||
|
||
class TimeoutTest { | ||
const API = 'https://api.example.com'; | ||
|
||
private $endpoint, $conn; | ||
|
||
#[Before] | ||
public function endpoint() { | ||
$this->endpoint= new Endpoint(self::API); | ||
$this->conn= new HttpConnection(self::API); | ||
} | ||
|
||
#[Test] | ||
public function takes_timeouts_from_httpconnection() { | ||
$endpoint= (clone $this->endpoint)->connecting(function($uri) { | ||
$c= new HttpConnection($uri); | ||
$c->setTimeout(600); | ||
$c->setConnectTimeout(30); | ||
return $c; | ||
}); | ||
$conn= $endpoint->open(new RestRequest('GET', '/'))->connection(); | ||
|
||
Assert::equals(600, $conn->getTimeout(), 'read'); | ||
Assert::equals(30, $conn->getConnectTimeout(), 'connect'); | ||
} | ||
|
||
#[Test] | ||
public function default_timeouts() { | ||
$conn= $this->endpoint->open(new RestRequest('GET', '/'))->connection(); | ||
|
||
Assert::equals($this->conn->getTimeout(), $conn->getTimeout(), 'read'); | ||
Assert::equals($this->conn->getConnectTimeout(), $conn->getConnectTimeout(), 'connect'); | ||
} | ||
|
||
#[Test] | ||
public function change_read_timeout() { | ||
$conn= $this->endpoint->open((new RestRequest('GET', '/'))->waiting(600, null))->connection(); | ||
|
||
Assert::equals(600, $conn->getTimeout(), 'read'); | ||
Assert::equals($this->conn->getConnectTimeout(), $conn->getConnectTimeout(), 'connect'); | ||
} | ||
|
||
#[Test] | ||
public function change_connect_timeout() { | ||
$conn= $this->endpoint->open((new RestRequest('GET', '/'))->waiting(null, 30))->connection(); | ||
|
||
Assert::equals($this->conn->getTimeout(), $conn->getTimeout(), 'read'); | ||
Assert::equals(30, $conn->getConnectTimeout(), 'connect'); | ||
} | ||
|
||
#[Test] | ||
public function usage_via_resource_request_method() { | ||
$conn= $this->endpoint->open($this->endpoint->resource('/')->request('GET')->waiting(600, 30))->connection(); | ||
|
||
Assert::equals(600, $conn->getTimeout(), 'read'); | ||
Assert::equals(30, $conn->getConnectTimeout(), 'connect'); | ||
} | ||
} |