From b7cf7974299f9db3bf87f45047491fde5fa75b64 Mon Sep 17 00:00:00 2001 From: ozh Date: Sun, 19 Apr 2015 11:04:17 +0200 Subject: [PATCH 01/10] Rename test & update its test URL --- tests/Transport/Base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index b9bd437e0..5d5749fe4 100755 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -672,8 +672,8 @@ public function testMultipleToFile() { unlink($requests['post']['options']['filename']); } - public function testHostHeader() { - $request = Requests::get('http://portquiz.positon.org:8080/', array(), $this->getOptions()); + public function testAlternatePort() { + $request = Requests::get('http://portquiz.net:8080/', array(), $this->getOptions()); $responseDoc = new DOMDocument; $responseDoc->loadHTML($request->body); $portXpath = new DOMXPath($responseDoc); From 80bff2c243829a208839f0a357e16fb68898210f Mon Sep 17 00:00:00 2001 From: ozh Date: Tue, 21 Apr 2015 00:06:53 +0200 Subject: [PATCH 02/10] Use mock to test success/failure on status code This will save **260** outgoing queries to httpbin.org --- tests/Transport/Base.php | 37 ++++++++++++++++++++++++++++++++----- tests/bootstrap.php | 7 ++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index 5d5749fe4..9df93e5cd 100755 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -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,7 +350,7 @@ 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); } @@ -349,9 +358,13 @@ public function testStatusCodeThrow($code, $success) { * @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) { @@ -359,12 +372,19 @@ public function testStatusCodeThrowAllowRedirects($code, $success) { $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); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ad95f5f8c..41b94e98d 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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) { From c50bc4c1217124c9f372356a2b7001ba3a5fec64 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 2 Oct 2015 13:36:53 +1000 Subject: [PATCH 03/10] Use regex to match port string DOMDocument is prone to crashing with HTML errors, and since we only care about this tiny bit, might as well use a simpler regex. --- tests/Transport/Base.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index 9df93e5cd..352728612 100755 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -701,10 +701,9 @@ public function testMultipleToFile() { public function testAlternatePort() { $request = Requests::get('http://portquiz.net: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); + $this->assertEquals(200, $request->status_code); + $num = preg_match('#You have reached this page on port (\d+)#i', $request->body, $matches); + $this->assertEquals(1, $num, 'Response should contain the port number'); + $this->assertEquals(8080, $matches[1]); } } From e5784a644f16767f76ad13738dcfcf2eab819570 Mon Sep 17 00:00:00 2001 From: ozh Date: Thu, 30 Apr 2015 23:28:51 +0200 Subject: [PATCH 04/10] Test with PHP 5.6 and 7.0 nightlies --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7aae19aab..319561c0b 100755 --- a/.travis.yml +++ b/.travis.yml @@ -24,4 +24,6 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 + - 7.0 - hhvm From f38dc4ad1669d8b82dab9d2dc22a3feb121be95c Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 2 Oct 2015 13:54:14 +1000 Subject: [PATCH 05/10] Allow PHP 7.0 to fail, but still test it --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 319561c0b..c1a76f1d2 100755 --- a/.travis.yml +++ b/.travis.yml @@ -27,3 +27,6 @@ php: - 5.6 - 7.0 - hhvm +matrix: + allow_failures: + - php: 7.0 From 42ac4a2b3935f080b127b8bf490ab45815054f5e Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 2 Oct 2015 13:57:44 +1000 Subject: [PATCH 06/10] Allow finishing the matrix early [ci skip] --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c1a76f1d2..643274b15 100755 --- a/.travis.yml +++ b/.travis.yml @@ -28,5 +28,6 @@ php: - 7.0 - hhvm matrix: + fast_finish: true allow_failures: - php: 7.0 From b9d1d014b10d60a70bb49d3717030cb4e6d78992 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 2 Oct 2015 14:07:12 +1000 Subject: [PATCH 07/10] Only send test coverage on 5.6 --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 643274b15..c84ea208b 100755 --- a/.travis.yml +++ b/.travis.yml @@ -17,17 +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 - - 5.6 + # 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 From 3e1d4f75ff0e9903cea6067c4ae6dfcee8fffb2b Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 2 Oct 2015 14:13:58 +1000 Subject: [PATCH 08/10] Switch to Codecov for coverage reports --- .travis.yml | 4 ++-- composer.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c84ea208b..81e7f2a0e 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php before_script: - # Setup Coveralls and httpbin-php + # Setup the test server - phpenv local 5.5 - composer install --dev --no-interaction @@ -17,7 +17,7 @@ after_script: - cd .. - phpenv local 5.5 - sudo PATH=$PATH vendor/bin/stop.sh - - test $TEST_COVERAGE && php vendor/bin/coveralls -v + - test $TEST_COVERAGE && bash <(curl -s https://codecov.io/bash) - phpenv local --unset php: - 5.2 diff --git a/composer.json b/composer.json index 6422b8ccc..79744ceeb 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,6 @@ "php": ">=5.2" }, "require-dev": { - "satooshi/php-coveralls": "dev-master", "requests/test-server": "dev-master" }, "type": "library", From 2accbe0283c800b29bafd8dd0965686059a0c596 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 2 Oct 2015 14:14:23 +1000 Subject: [PATCH 09/10] Reformat the Travis config --- .travis.yml | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 81e7f2a0e..4c8233330 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,18 @@ language: php +matrix: + fast_finish: true + allow_failures: + - php: 7.0 + include: + - php: 5.2 + - php: 5.3 + - php: 5.4 + - php: 5.5 + - php: 5.6 + env: TEST_COVERAGE=1 + - php: 7.0 + - php: hhvm + before_script: # Setup the test server - phpenv local 5.5 @@ -19,18 +33,3 @@ after_script: - sudo PATH=$PATH vendor/bin/stop.sh - test $TEST_COVERAGE && bash <(curl -s https://codecov.io/bash) - 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 From cea419c6aac882a347bf243b4b8e46446ca14fd3 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 2 Oct 2015 14:19:12 +1000 Subject: [PATCH 10/10] Switch to Codecov in the README too --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3ff6ab646..8e28ac497 100755 --- a/README.md +++ b/README.md @@ -115,12 +115,12 @@ issue](https://github.com/rmccue/Requests/issues/new)! Testing ------- [![Build Status](https://secure.travis-ci.org/rmccue/Requests.png?branch=master)](http://travis-ci.org/rmccue/Requests) -[![Coverage Status](https://coveralls.io/repos/rmccue/Requests/badge.png?branch=master)][coveralls] +[![codecov.io](http://codecov.io/github/rmccue/Requests/coverage.svg?branch=master)](http://codecov.io/github/rmccue/Requests?branch=master) Requests strives to have 100% code-coverage of the library with an extensive -set of tests. We're not quite there yet, but [we're getting close][coveralls]. +set of tests. We're not quite there yet, but [we're getting close][codecov]. -[coveralls]: https://coveralls.io/r/rmccue/Requests?branch=master +[codecov]: http://codecov.io/github/rmccue/Requests To run the test suite, first check that you have the [PHP JSON extension ](http://php.net/manual/en/book.json.php) enabled. Then