Smalyshev has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404602 )

Change subject: Make MWHttpRequest more testable by allowing factory override
......................................................................

Make MWHttpRequest more testable by allowing factory override

This patch allows overriding the return of MWHttpRequest::factory
via $options['httpRequestImplementation'], thus allowing tests
to substitute a mock HTTP class there and make classes relying on
MWHttpRequest more testable.

The mock must extend MWHttpRequest class.

Also made MWHttpRequest abstract class since it doesn't implement
execute anyway. Maybe a good idea to move execute to an abstract
method?

Change-Id: I5c0e035542ff5f791a21a95ed13bed4cea6906d0
---
M includes/http/MWHttpRequest.php
1 file changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/02/404602/1

diff --git a/includes/http/MWHttpRequest.php b/includes/http/MWHttpRequest.php
index 0f0118c..6189c93f 100644
--- a/includes/http/MWHttpRequest.php
+++ b/includes/http/MWHttpRequest.php
@@ -30,7 +30,7 @@
  * Renamed from HttpRequest to MWHttpRequest to avoid conflict with
  * PHP's HTTP extension.
  */
-class MWHttpRequest implements LoggerAwareInterface {
+abstract class MWHttpRequest implements LoggerAwareInterface {
        const SUPPORTS_FILE_POSTS = false;
 
        /**
@@ -178,7 +178,7 @@
         * @param array $options (optional) extra params to pass (see 
Http::request())
         * @param string $caller The method making this request, for profiling
         * @throws DomainException
-        * @return CurlHttpRequest|PhpHttpRequest
+        * @return MWHttpRequest
         * @see MWHttpRequest::__construct
         */
        public static function factory( $url, $options = null, $caller = 
__METHOD__ ) {
@@ -197,6 +197,15 @@
                        $options['logger'] = LoggerFactory::getInstance( 'http' 
);
                }
 
+               if ( !empty( $options['httpRequestImplementation'] ) ) {
+                       if ( $options['httpRequestImplementation'] instanceof 
MWHttpRequest ) {
+                               return $options['httpRequestImplementation'];
+                       } else {
+                               throw new DomainException( __METHOD__ .
+                                                          ': 
$options[\'httpRequestImplementation\'] should be an instace of MWHttpRequest' 
);
+                       }
+               }
+
                switch ( Http::$httpEngine ) {
                        case 'curl':
                                return new CurlHttpRequest( $url, $options, 
$caller, Profiler::instance() );

-- 
To view, visit https://gerrit.wikimedia.org/r/404602
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c0e035542ff5f791a21a95ed13bed4cea6906d0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to