Make the instantiation tests actually work.
authorMark A. Hershberger <mah@users.mediawiki.org>
Wed, 27 Jan 2010 06:51:42 +0000 (06:51 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Wed, 27 Jan 2010 06:51:42 +0000 (06:51 +0000)
includes/HttpFunctions.php
tests/HttpTest.php

index d575a88..8070b01 100644 (file)
@@ -171,7 +171,7 @@ class HttpRequest {
         * Generate a new request object
         * @see HttpRequest::__construct
         */
-       public static function factory( $url, $options ) {
+       public static function factory( $url, $options = null ) {
                if ( !Http::$httpEngine ) {
                        Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
                } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
@@ -315,10 +315,6 @@ class CurlHttpRequest extends HttpRequest {
                if ( !$this->status->isOK() ) {
                        return $this->status;
                }
-
-               // A lot of the action up front should probably be in
-               // set* methods, but we'll leave that for another time.
-
                $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
                $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
                $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
@@ -387,9 +383,6 @@ class PhpHttpRequest extends HttpRequest {
                        return $this->status;
                }
 
-               // A lot of the action up front should probably be in
-               // set* methods, but we'll leave that for another time.
-
                $this->reqHeaders['Accept'] = "*/*";
                if ( $this->method == 'POST' ) {
                        // Required for HTTP 1.0 POSTs
index f4f85eb..4d0731f 100644 (file)
@@ -65,26 +65,26 @@ class HttpTest extends PhpUnit_Framework_TestCase {
        function testInstantiation() {
                Http::$httpEngine = false;
 
-           $r = new HttpRequest("http://www.example.com/");
+           $r = HttpRequest::factory("http://www.example.com/");
                if ( self::$has_curl ) {
-                       $this->isInstanceOf( $r, 'CurlHttpRequest' );
+                       $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
                } else {
-                       $this->isInstanceOf( $r, 'PhpHttpRequest' );
+                       $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
                }
                unset($r);
 
                Http::$httpEngine = 'php';
-               $r = new HttpRequest("http://www.example.com/");
-               $this->isInstanceOf( $r, 'PhpHttpRequest' );
+               $r = HttpRequest::factory("http://www.example.com/");
+               $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
                unset($r);
 
                if( !self::$has_curl ) {
                        $this->setExpectedException( 'MWException' );
                }
                Http::$httpEngine = 'curl';
-               $r = new HttpRequest("http://www.example.com/");
+               $r = HttpRequest::factory("http://www.example.com/");
                if( self::$has_curl ) {
-                       $this->isInstanceOf( $r, 'CurlHttpRequest' );
+                       $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
                }
        }