Permalink
Browse files

Merge b9d1d01 into d3e6e43

  • Loading branch information...
rmccue committed Oct 2, 2015
2 parents d3e6e43 + b9d1d01 commit 4c5e5bbe9120ca53f8ce7ab185ffa59fc55bc7e5
Showing with 54 additions and 14 deletions.
  1. +10 −1 .travis.yml
  2. +38 −12 tests/Transport/Base.php
  3. +6 −1 tests/bootstrap.php
View
@@ -17,11 +17,20 @@ after_script:
- cd ..
- phpenv local 5.5
- sudo PATH=$PATH vendor/bin/stop.sh
- php vendor/bin/coveralls -v
- test $TEST_COVERAGE && php vendor/bin/coveralls -v
- phpenv local --unset
php:
- 5.2
- 5.3
- 5.4
- 5.5
# We include 5.6 too, but in the matrix to enable coverage too
- 7.0
- hhvm
matrix:
fast_finish: true
allow_failures:
- php: 7.0
include:
- php: 5.6
env: TEST_COVERAGE=1
View
@@ -315,11 +315,16 @@ public static function statusCodeSuccessProvider() {
* @dataProvider statusCodeSuccessProvider
*/
public function testStatusCode($code, $success) {
$transport = new MockTransport();
$transport->code = $code;
$url = sprintf(httpbin('/status/%d'), $code);
$options = array(
'follow_redirects' => false,
'transport' => $transport,
);
$request = Requests::get($url, array(), $this->getOptions($options));
$request = Requests::get($url, array(), $options);
$this->assertEquals($code, $request->status_code);
$this->assertEquals($success, $request->success);
}
@@ -328,9 +333,13 @@ public function testStatusCode($code, $success) {
* @dataProvider statusCodeSuccessProvider
*/
public function testStatusCodeThrow($code, $success) {
$transport = new MockTransport();
$transport->code = $code;
$url = sprintf(httpbin('/status/%d'), $code);
$options = array(
'follow_redirects' => false,
'transport' => $transport,
);
if (!$success) {
@@ -341,30 +350,41 @@ public function testStatusCodeThrow($code, $success) {
$this->setExpectedException('Requests_Exception');
}
}
$request = Requests::get($url, array(), $this->getOptions($options));
$request = Requests::get($url, array(), $options);
$request->throw_for_status(false);
}
/**
* @dataProvider statusCodeSuccessProvider
*/
public function testStatusCodeThrowAllowRedirects($code, $success) {
$transport = new MockTransport();
$transport->code = $code;
$url = sprintf(httpbin('/status/%d'), $code);
$options = array(
'follow_redirects' => false,
'transport' => $transport,
);
if (!$success) {
if ($code >= 400) {
$this->setExpectedException('Requests_Exception_HTTP_' . $code, $code);
}
}
$request = Requests::get($url, array(), $this->getOptions($options));
$request = Requests::get($url, array(), $options);
$request->throw_for_status(true);
}
public function testStatusCodeUnknown(){
$request = Requests::get(httpbin('/status/599'), array(), $this->getOptions());
$transport = new MockTransport();
$transport->code = 599;
$options = array(
'transport' => $transport,
);
$request = Requests::get(httpbin('/status/599'), array(), $options);
$this->assertEquals(599, $request->status_code);
$this->assertEquals(false, $request->success);
}
@@ -373,7 +393,14 @@ public function testStatusCodeUnknown(){
* @expectedException Requests_Exception_HTTP_Unknown
*/
public function testStatusCodeThrowUnknown(){
$request = Requests::get(httpbin('/status/599'), array(), $this->getOptions());
$transport = new MockTransport();
$transport->code = 599;
$options = array(
'transport' => $transport,
);
$request = Requests::get(httpbin('/status/599'), array(), $options);
$request->throw_for_status(true);
}
@@ -672,12 +699,11 @@ public function testMultipleToFile() {
unlink($requests['post']['options']['filename']);
}
public function testHostHeader() {
$request = Requests::get('http://portquiz.positon.org:8080/', array(), $this->getOptions());
$responseDoc = new DOMDocument;
$responseDoc->loadHTML($request->body);
$portXpath = new DOMXPath($responseDoc);
$portXpathMatches = $portXpath->query('//p/b');
$this->assertEquals(8080, $portXpathMatches->item(0)->nodeValue);
public function testAlternatePort() {
$request = Requests::get('http://portquiz.net:8080/', array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$num = preg_match('#You have reached this page on port <b>(\d+)</b>#i', $request->body, $matches);
$this->assertEquals(1, $num, 'Response should contain the port number');
$this->assertEquals(8080, $matches[1]);
}
}
View
@@ -74,16 +74,21 @@ class MockTransport implements Requests_Transport {
415 => '415 Unsupported Media Type',
416 => '416 Requested Range Not Satisfiable',
417 => '417 Expectation Failed',
418 => '418 I\'m a teapot',
428 => '428 Precondition Required',
429 => '429 Too Many Requests',
431 => '431 Request Header Fields Too Large',
500 => '500 Internal Server Error',
501 => '501 Not Implemented',
502 => '502 Bad Gateway',
503 => '503 Service Unavailable',
504 => '504 Gateway Timeout',
505 => '505 HTTP Version Not Supported',
511 => '511 Network Authentication Required',
);
public function request($url, $headers = array(), $data = array(), $options = array()) {
$status = self::$messages[$this->code];
$status = isset(self::$messages[$this->code]) ? self::$messages[$this->code] : $this->code . ' unknown';
$response = "HTTP/1.0 $status\r\n";
$response .= "Content-Type: text/plain\r\n";
if ($this->chunked) {

0 comments on commit 4c5e5bb

Please sign in to comment.