Skip to content

Commit 3cfa046

Browse files
committed
Merge pull request #107 from rmccue/speedy-tests
Speed up test running by using local server
2 parents 011d3d4 + eb34a29 commit 3cfa046

File tree

8 files changed

+100
-75
lines changed

8 files changed

+100
-75
lines changed

.travis.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
language: php
22
before_script:
3-
- phpenv local 5.4
4-
- composer install --dev --no-interaction
3+
# Setup Coveralls and httpbin-php
4+
- phpenv local 5.5
5+
- composer install --dev --no-interaction --prefer-dist
6+
7+
- TESTPHPBIN=$(phpenv which php)
8+
- sudo PHPBIN=$TESTPHPBIN vendor/bin/start.sh
9+
- export REQUESTS_TEST_HOST_HTTP=localhost
510
- phpenv local --unset
11+
12+
# Work out of the tests directory
613
- cd tests
714
script:
815
- phpunit --coverage-clover clover.xml
916
after_script:
1017
- cd ..
11-
- phpenv local 5.4
18+
- phpenv local 5.5
19+
- sudo PATH=$PATH vendor/bin/stop.sh
1220
- php vendor/bin/coveralls -v
1321
- phpenv local --unset
1422
php:

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"php": ">=5.2"
1515
},
1616
"require-dev": {
17-
"satooshi/php-coveralls": "dev-master"
17+
"satooshi/php-coveralls": "dev-master",
18+
"requests/test-server": "dev-master"
1819
},
1920
"type": "library",
2021
"autoload": {

tests/Auth/Basic.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testUsingArray($transport) {
2222
'auth' => array('user', 'passwd'),
2323
'transport' => $transport,
2424
);
25-
$request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
25+
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
2626
$this->assertEquals(200, $request->status_code);
2727

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

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

7171
$result = json_decode($request->body);

tests/Cookies.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testReceivingCookies() {
7979
$options = array(
8080
'follow_redirects' => false,
8181
);
82-
$url = 'http://httpbin.org/cookies/set?requests-testcookie=testvalue';
82+
$url = httpbin('/cookies/set?requests-testcookie=testvalue');
8383

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

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

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

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

110110
$data = json_decode($response->body, true);
111111
$this->assertInternalType('array', $data);

tests/Requests.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function testInvalidProtocol() {
99
}
1010

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

@@ -143,6 +143,6 @@ public function test30xWithoutLocation() {
143143
*/
144144
public function testTimeoutException() {
145145
$options = array('timeout' => 0.5);
146-
$response = Requests::get('http://httpbin.org/delay/3', array(), $options);
146+
$response = Requests::get(httpbin('/delay/3'), array(), $options);
147147
}
148148
}

tests/Session.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ public function testPropertyUsage() {
4747
}
4848

4949
public function testURLResolution() {
50-
$session = new Requests_Session('http://httpbin.org/');
50+
$session = new Requests_Session(httpbin('/'));
5151

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

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

6363
public function testSharedCookies() {
64-
$session = new Requests_Session('http://httpbin.org/');
64+
$session = new Requests_Session(httpbin('/'));
6565

6666
$options = array(
6767
'follow_redirects' => false

0 commit comments

Comments
 (0)