r61559 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61558‎ | r61559 | r61560 >
Date:06:51, 27 January 2010
Author:mah
Status:ok
Tags:
Comment:
Make the instantiation tests actually work.
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/tests/HttpTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/HttpTest.php
@@ -65,26 +65,26 @@
6666 function testInstantiation() {
6767 Http::$httpEngine = false;
6868
69 - $r = new HttpRequest("http://www.example.com/");
 69+ $r = HttpRequest::factory("http://www.example.com/");
7070 if ( self::$has_curl ) {
71 - $this->isInstanceOf( $r, 'CurlHttpRequest' );
 71+ $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
7272 } else {
73 - $this->isInstanceOf( $r, 'PhpHttpRequest' );
 73+ $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
7474 }
7575 unset($r);
7676
7777 Http::$httpEngine = 'php';
78 - $r = new HttpRequest("http://www.example.com/");
79 - $this->isInstanceOf( $r, 'PhpHttpRequest' );
 78+ $r = HttpRequest::factory("http://www.example.com/");
 79+ $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
8080 unset($r);
8181
8282 if( !self::$has_curl ) {
8383 $this->setExpectedException( 'MWException' );
8484 }
8585 Http::$httpEngine = 'curl';
86 - $r = new HttpRequest("http://www.example.com/");
 86+ $r = HttpRequest::factory("http://www.example.com/");
8787 if( self::$has_curl ) {
88 - $this->isInstanceOf( $r, 'CurlHttpRequest' );
 88+ $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
8989 }
9090 }
9191
Index: trunk/phase3/includes/HttpFunctions.php
@@ -171,7 +171,7 @@
172172 * Generate a new request object
173173 * @see HttpRequest::__construct
174174 */
175 - public static function factory( $url, $options ) {
 175+ public static function factory( $url, $options = null ) {
176176 if ( !Http::$httpEngine ) {
177177 Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
178178 } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
@@ -315,10 +315,6 @@
316316 if ( !$this->status->isOK() ) {
317317 return $this->status;
318318 }
319 -
320 - // A lot of the action up front should probably be in
321 - // set* methods, but we'll leave that for another time.
322 -
323319 $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
324320 $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
325321 $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
@@ -387,9 +383,6 @@
388384 return $this->status;
389385 }
390386
391 - // A lot of the action up front should probably be in
392 - // set* methods, but we'll leave that for another time.
393 -
394387 $this->reqHeaders['Accept'] = "*/*";
395388 if ( $this->method == 'POST' ) {
396389 // Required for HTTP 1.0 POSTs

Status & tagging log