Skip to content
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

Speed up test running by using local server #107

Merged
merged 11 commits into from
Mar 27, 2014
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
language: php
before_script:
- phpenv local 5.4
- composer install --dev --no-interaction
# Setup Coveralls and httpbin-php
- phpenv local 5.5
- composer install --dev --no-interaction --prefer-dist

- TESTPHPBIN=$(phpenv which php)
- sudo PHPBIN=$TESTPHPBIN vendor/bin/start.sh
- export REQUESTS_TEST_HOST_HTTP=localhost
- phpenv local --unset

# Work out of the tests directory
- cd tests
script:
- phpunit --coverage-clover clover.xml
after_script:
- cd ..
- phpenv local 5.4
- phpenv local 5.5
- sudo PATH=$PATH vendor/bin/stop.sh
- php vendor/bin/coveralls -v
- phpenv local --unset
php:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"php": ">=5.2"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master"
"satooshi/php-coveralls": "dev-master",
"requests/test-server": "dev-master"
},
"type": "library",
"autoload": {
Expand Down
6 changes: 3 additions & 3 deletions tests/Auth/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testUsingArray($transport) {
'auth' => array('user', 'passwd'),
'transport' => $transport,
);
$request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
$this->assertEquals(200, $request->status_code);

$result = json_decode($request->body);
Expand All @@ -43,7 +43,7 @@ public function testUsingInstantiation($transport) {
'auth' => new Requests_Auth_Basic(array('user', 'passwd')),
'transport' => $transport,
);
$request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
$this->assertEquals(200, $request->status_code);

$result = json_decode($request->body);
Expand All @@ -65,7 +65,7 @@ public function testPOSTUsingInstantiation($transport) {
'transport' => $transport,
);
$data = 'test';
$request = Requests::post('http://httpbin.org/post', array(), $data, $options);
$request = Requests::post(httpbin('/post'), array(), $data, $options);
$this->assertEquals(200, $request->status_code);

$result = json_decode($request->body);
Expand Down
6 changes: 3 additions & 3 deletions tests/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testReceivingCookies() {
$options = array(
'follow_redirects' => false,
);
$url = 'http://httpbin.org/cookies/set?requests-testcookie=testvalue';
$url = httpbin('/cookies/set?requests-testcookie=testvalue');

$response = Requests::get($url, array(), $options);

Expand All @@ -92,7 +92,7 @@ public function testPersistenceOnRedirect() {
$options = array(
'follow_redirects' => true,
);
$url = 'http://httpbin.org/cookies/set?requests-testcookie=testvalue';
$url = httpbin('/cookies/set?requests-testcookie=testvalue');

$response = Requests::get($url, array(), $options);

Expand All @@ -105,7 +105,7 @@ protected function setCookieRequest($cookies) {
$options = array(
'cookies' => $cookies,
);
$response = Requests::get('http://httpbin.org/cookies/set', array(), $options);
$response = Requests::get(httpbin('/cookies/set'), array(), $options);

$data = json_decode($response->body, true);
$this->assertInternalType('array', $data);
Expand Down
4 changes: 2 additions & 2 deletions tests/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function testInvalidProtocol() {
}

public function testDefaultTransport() {
$request = Requests::get('http://httpbin.org/get');
$request = Requests::get(httpbin('/get'));
$this->assertEquals(200, $request->status_code);
}

Expand Down Expand Up @@ -143,6 +143,6 @@ public function test30xWithoutLocation() {
*/
public function testTimeoutException() {
$options = array('timeout' => 0.5);
$response = Requests::get('http://httpbin.org/delay/3', array(), $options);
$response = Requests::get(httpbin('/delay/3'), array(), $options);
}
}
8 changes: 4 additions & 4 deletions tests/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ public function testPropertyUsage() {
}

public function testURLResolution() {
$session = new Requests_Session('http://httpbin.org/');
$session = new Requests_Session(httpbin('/'));

// Set the cookies up
$response = $session->get('/get');
$this->assertTrue($response->success);
$this->assertEquals('http://httpbin.org/get', $response->url);
$this->assertEquals(httpbin('/get'), $response->url);

$data = json_decode($response->body, true);
$this->assertNotNull($data);
$this->assertArrayHasKey('url', $data);
$this->assertEquals('http://httpbin.org/get', $data['url']);
$this->assertEquals(httpbin('/get'), $data['url']);
}

public function testSharedCookies() {
$session = new Requests_Session('http://httpbin.org/');
$session = new Requests_Session(httpbin('/'));

$options = array(
'follow_redirects' => false
Expand Down
Loading