jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/299150 )

Change subject: Use traits to consolidate TestingAdapters
......................................................................


Use traits to consolidate TestingAdapters

Note that traits require PHP 5.4.0 or later.

TODO:
* use reflection to generalize access protection workarounds
* Fix base adapter constructor to deprecate options hack

Change-Id: I501ab91de990304ceca012bc4044495f82af1e68
---
M DonationInterface.class.php
M composer.json
M composer.lock
M tests/phpunit/includes/test_gateway/TestingAdyenAdapter.php
M tests/phpunit/includes/test_gateway/TestingAmazonAdapter.php
M tests/phpunit/includes/test_gateway/TestingAstroPayAdapter.php
M tests/phpunit/includes/test_gateway/TestingGenericAdapter.php
M tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
M tests/phpunit/includes/test_gateway/TestingGlobalCollectOrphanAdapter.php
M tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php
M tests/phpunit/includes/test_gateway/TestingPaypalLegacyAdapter.php
A tests/phpunit/includes/test_gateway/test.adapter.php
12 files changed, 211 insertions(+), 429 deletions(-)

Approvals:
  XenoRyet: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DonationInterface.class.php b/DonationInterface.class.php
index 4282c2b..7f2e2d3 100644
--- a/DonationInterface.class.php
+++ b/DonationInterface.class.php
@@ -84,6 +84,7 @@
                $wgAutoloadClasses['TestingPaypalLegacyAdapter'] = $testDir . 
'includes/test_gateway/TestingPaypalLegacyAdapter.php';
 
                $wgAutoloadClasses['TestingRequest'] = $testDir . 
'includes/test_request/test.request.php';
+               $wgAutoloadClasses['TTestingAdapter'] = $testDir . 
'includes/test_gateway/test.adapter.php';
 
                return true;
        }
diff --git a/composer.json b/composer.json
index b0c1d68..a1b664a 100644
--- a/composer.json
+++ b/composer.json
@@ -26,6 +26,7 @@
                "minfraud/http": "^1.70",
                "monolog/monolog": "~1.18.2",
                "neitanod/forceutf8": "^2.0",
+               "php": ">=5.4",
                "predis/predis": "^1.1",
                "psr/log": "^1.0",
                "zordius/lightncandy": "0.23",
diff --git a/composer.lock b/composer.lock
index 0f8b45e..f4230a3 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at 
https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file";,
         "This file is @generated automatically"
     ],
-    "content-hash": "22b27fd4e340d42c6a3b461f7f1fd7a6",
+    "content-hash": "05fcadc833e6b0e4c9da1a7fc7aba690",
     "packages": [
         {
             "name": "addshore/psr-6-mediawiki-bagostuff-adapter",
@@ -1195,6 +1195,8 @@
     },
     "prefer-stable": false,
     "prefer-lowest": false,
-    "platform": [],
+    "platform": {
+        "php": ">=5.4"
+    },
     "platform-dev": []
 }
diff --git a/tests/phpunit/includes/test_gateway/TestingAdyenAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingAdyenAdapter.php
index bc79ae7..9c46f96 100644
--- a/tests/phpunit/includes/test_gateway/TestingAdyenAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingAdyenAdapter.php
@@ -4,67 +4,5 @@
  * TestingAdyenAdapter
  */
 class TestingAdyenAdapter extends AdyenAdapter {
-
-       //@TODO: That minfraud jerk needs its own isolated tests.
-       function runAntifraudFilters() {
-               //now screw around with the batch settings to trick the fraud 
filters into triggering
-               $is_batch = $this->isBatchProcessor();
-               $this->batch = true;
-
-               parent::runAntifraudFilters();
-
-               $this->batch = $is_batch;
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyGatewayResponseCode( $code ) {
-               $this->dummyGatewayResponseCode = $code;
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyCurlResponseCode( $code ) {
-               $this->dummyCurlResponseCode = $code;
-       }
-
-       /**
-        * Load in some dummy response XML so we can test proper response 
processing
-        */
-       protected function curl_exec( $ch ) {
-               $code = '';
-               if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) {
-                       $code = '_' . $this->dummyGatewayResponseCode;
-               }
-
-               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
-               //but frankly I don't want to write tests that test our dummy 
responses.
-               $file_path = __DIR__ . '/../';
-               $file_path .= 'Responses' . '/' . self::getIdentifier() . '/';
-               $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
-
-               //these are all going to be short, so...
-               if ( file_exists( $file_path ) ) {
-                       return file_get_contents( $file_path );
-               }
-               throw new RuntimeException( "File $file_path does not exist." );
-       }
-
-       /**
-        * Load in some dummy curl response info so we can test proper response 
processing
-        */
-       protected function curl_getinfo( $ch, $opt = null ) {
-               $code = 200; //response OK
-               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
-                       $code = ( int ) $this->dummyCurlResponseCode;
-               }
-
-               //put more here if it ever turns out that we care about it.
-               return array (
-                       'http_code' => $code,
-               );
-       }
-
+       use TTestingAdapter;
 }
diff --git a/tests/phpunit/includes/test_gateway/TestingAmazonAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingAmazonAdapter.php
index a1bf0f6..2671872 100644
--- a/tests/phpunit/includes/test_gateway/TestingAmazonAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingAmazonAdapter.php
@@ -4,16 +4,9 @@
  * TestingAmazonAdapter
  */
 class TestingAmazonAdapter extends AmazonAdapter {
+       use TTestingAdapter;
 
-       public static $fakeGlobals = array();
        public static $mockClient;
-
-       public static function getGlobal( $name ) {
-               if ( array_key_exists( $name, 
TestingAmazonAdapter::$fakeGlobals ) ) {
-                       return TestingAmazonAdapter::$fakeGlobals[$name];
-               }
-               return parent::getGlobal( $name );
-       }
 
        protected function getPwaClient() {
                return self::$mockClient;
diff --git a/tests/phpunit/includes/test_gateway/TestingAstroPayAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingAstroPayAdapter.php
index fcc224c..15d84ee 100644
--- a/tests/phpunit/includes/test_gateway/TestingAstroPayAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingAstroPayAdapter.php
@@ -2,75 +2,7 @@
 
 /**
  * TestingAstroPayAdapter
- *
- * TODO: Add dependency injection to the base class so we don't have to repeat
- * code (or this comment) here.
  */
 class TestingAstroPayAdapter extends AstroPayAdapter {
-
-       public $curled = array();
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyGatewayResponseCode( $code ) {
-               $this->dummyGatewayResponseCode = $code;
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyCurlResponseCode( $code ) {
-               $this->dummyCurlResponseCode = $code;
-       }
-
-       protected function curl_transaction( $data ) {
-               $this->curled[] = $data;
-               return parent::curl_transaction( $data );
-       }
-
-       /**
-        * Load in some dummy response JSON so we can test proper response 
processing
-        * @throws RuntimeException
-        */
-       protected function curl_exec( $ch ) {
-               $code = '';
-               if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) {
-                       $code = '_' . $this->dummyGatewayResponseCode;
-                       if ( $this->dummyGatewayResponseCode === 'Exception' ) {
-                               throw new RuntimeException( 'blah!' );
-                       }
-               }
-
-               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
-               //but frankly I don't want to write tests that test our dummy 
responses.
-               $file_path = __DIR__
-                       . '/../Responses/'
-                       . self::getIdentifier()
-                       . '/'
-                       . $this->getCurrentTransaction()
-                       . $code
-                       . '.testresponse';
-
-               //these are all going to be short, so...
-               if ( file_exists( $file_path ) ) {
-                       return file_get_contents( $file_path );
-               }
-               throw new RuntimeException( "File $file_path does not exist." );
-       }
-
-       /**
-        * Load in some dummy curl response info so we can test proper response 
processing
-        */
-       protected function curl_getinfo( $ch, $opt = null ) {
-               $code = 200; //response OK
-               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
-                       $code = ( int ) $this->dummyCurlResponseCode;
-               }
-
-               //put more here if it ever turns out that we care about it.
-               return array (
-                       'http_code' => $code,
-               );
-       }
+       use TTestingAdapter;
 }
diff --git a/tests/phpunit/includes/test_gateway/TestingGenericAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingGenericAdapter.php
index c228f1e..5ea6b09 100644
--- a/tests/phpunit/includes/test_gateway/TestingGenericAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingGenericAdapter.php
@@ -20,10 +20,14 @@
  * A really dumb adapter.
  */
 class TestingGenericAdapter extends GatewayAdapter {
+       use TTestingAdapter;
 
-       public static $fakeGlobals = array();
+       /**
+        * A list of fake errors that is returned each time revalidate() is 
called.
+        */
+       public $errorsForRevalidate = array();
 
-       public static $fakeIdentifier;
+       public $revalidateCount = 0;
 
        public static $acceptedCurrencies = array();
 
@@ -31,22 +35,20 @@
                return 'xml';
        }
 
+       public function revalidate($check_not_empty = array()) {
+               if ( !empty( $this->errorsForRevalidate ) ) {
+                       $fakeErrors = 
$this->errorsForRevalidate[$this->revalidateCount];
+                       if ( $fakeErrors !== null ) {
+                               $this->revalidateCount++;
+                               $this->setValidationErrors( $fakeErrors );
+                               return empty( $fakeErrors );
+                       }
+               }
+               return parent::revalidate($check_not_empty);
+       }
+
        public function normalizeOrderID( $override = null, $dataObj = null ) {
                return '12345';
-       }
-
-       public static function getGlobal( $name ) {
-               if ( array_key_exists( $name, 
TestingGenericAdapter::$fakeGlobals ) ) {
-                       return TestingGenericAdapter::$fakeGlobals[$name];
-               }
-               return parent::getGlobal( $name );
-       }
-
-       public static function getIdentifier() {
-               if ( self::$fakeIdentifier ) {
-                       return self::$fakeIdentifier;
-               }
-               return GatewayAdapter::getIdentifier();
        }
 
        public function loadConfig() {
@@ -80,6 +82,9 @@
        public function defineVarMap() {
        }
 
+       public function processResponse( $response ) {
+       }
+
        public function setGatewayDefaults( $options = array() ) {
        }
 
diff --git 
a/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
index a936b6c..14b90b9 100644
--- a/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
@@ -2,14 +2,9 @@
 
 /**
  * TestingGlobalCollectAdapter
- *
- * TODO: Add dependency injection to the base class so we don't have to repeat 
code here.
  */
 class TestingGlobalCollectAdapter extends GlobalCollectAdapter {
-
-       public $curled = array ( );
-
-       public $dummyGatewayResponseCode;
+       use TTestingAdapter;
 
        /**
         * Also set a useful MerchantID.
@@ -33,85 +28,4 @@
 
                parent::__construct( $this->options );
        }
-
-       /**
-        * @TODO: Get rid of this and the override mechanism as soon as you
-        * refactor the constructor into something reasonable.
-        */
-       public function defineOrderIDMeta() {
-               if ( isset( $this->order_id_meta ) ) {
-                       return;
-               }
-               parent::defineOrderIDMeta();
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyGatewayResponseCode( $code ) {
-               $this->dummyGatewayResponseCode = $code;
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyCurlResponseCode( $code ) {
-               $this->dummyCurlResponseCode = $code;
-       }
-
-       protected function curl_transaction( $data ) {
-               $this->curled[] = $data;
-               return parent::curl_transaction( $data );
-       }
-
-       /**
-        * Load in some dummy response XML so we can test proper response 
processing
-        * @throws RuntimeException
-        */
-       protected function curl_exec( $ch ) {
-               $code = '';
-               if ( $this->dummyGatewayResponseCode ) {
-                       if ( is_array( $this->dummyGatewayResponseCode ) ) {
-                               $code = array_shift( 
$this->dummyGatewayResponseCode );
-                       } elseif ( is_callable( $this->dummyGatewayResponseCode 
) ) {
-                               $code = call_user_func( 
$this->dummyGatewayResponseCode, $this );
-                       } else {
-                               $code = $this->dummyGatewayResponseCode;
-                       }
-               }
-               if ( $code ) {
-                       if ( $code === 'Exception' ) {
-                               throw new RuntimeException('blah!');
-                       }
-                       $code = '_' . $code;
-               }
-
-               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
-               //but frankly I don't want to write tests that test our dummy 
responses.
-               $file_path = __DIR__ . '/../';
-               $file_path .= 'Responses' . '/' . self::getIdentifier() . '/';
-               $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
-
-               //these are all going to be short, so...
-               if ( file_exists( $file_path ) ) {
-                       return file_get_contents( $file_path );
-               }
-               throw new RuntimeException( "File $file_path does not exist." );
-       }
-
-       /**
-        * Load in some dummy curl response info so we can test proper response 
processing
-        */
-       protected function curl_getinfo( $ch, $opt = null ) {
-               $code = 200; //response OK
-               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
-                       $code = ( int ) $this->dummyCurlResponseCode;
-               }
-
-               //put more here if it ever turns out that we care about it.
-               return array (
-                       'http_code' => $code,
-               );
-       }
-
 }
diff --git 
a/tests/phpunit/includes/test_gateway/TestingGlobalCollectOrphanAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingGlobalCollectOrphanAdapter.php
index 2b155f2..0ec3b54 100644
--- a/tests/phpunit/includes/test_gateway/TestingGlobalCollectOrphanAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingGlobalCollectOrphanAdapter.php
@@ -1,13 +1,11 @@
 <?php
 
 /**
- * Test wrapper for the orphan adapter
- *
- * TODO: This is beyond silly.  Use traits or whatever it takes.
+ * TestingGlobalCollectOrphanAdapter
  */
-class TestingGlobalCollectOrphanAdapter extends GlobalCollectOrphanAdapter {
 
-       public $curled = array ( );
+class TestingGlobalCollectOrphanAdapter extends GlobalCollectOrphanAdapter {
+       use TTestingAdapter;
 
        /**
         * Also set a useful MerchantID.
@@ -31,72 +29,4 @@
 
                parent::__construct( $this->options );
        }
-
-       /**
-        * @TODO: Get rid of this and the override mechanism as soon as you
-        * refactor the constructor into something reasonable.
-        */
-       public function defineOrderIDMeta() {
-               if ( isset( $this->order_id_meta ) ) {
-                       return;
-               }
-               parent::defineOrderIDMeta();
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyGatewayResponseCode( $code ) {
-               $this->dummyGatewayResponseCode = $code;
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyCurlResponseCode( $code ) {
-               $this->dummyCurlResponseCode = $code;
-       }
-
-       protected function curl_transaction( $data ) {
-               $this->curled[] = $data;
-               return parent::curl_transaction( $data );
-       }
-
-       /**
-        * Load in some dummy response XML so we can test proper response 
processing
-        */
-       protected function curl_exec( $ch ) {
-               $code = '';
-               if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) {
-                       $code = '_' . $this->dummyGatewayResponseCode;
-               }
-
-               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
-               //but frankly I don't want to write tests that test our dummy 
responses.
-               $file_path = __DIR__ . '/../';
-               $file_path .= 'Responses' . '/' . self::getIdentifier() . '/';
-               $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
-
-               //these are all going to be short, so...
-               if ( file_exists( $file_path ) ) {
-                       return file_get_contents( $file_path );
-               }
-               throw new RuntimeException( "File $file_path does not exist." );
-       }
-
-       /**
-        * Load in some dummy curl response info so we can test proper response 
processing
-        */
-       protected function curl_getinfo( $ch, $opt = null ) {
-               $code = 200; //response OK
-               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
-                       $code = ( int ) $this->dummyCurlResponseCode;
-               }
-
-               //put more here if it ever turns out that we care about it.
-               return array (
-                       'http_code' => $code,
-               );
-       }
-
 }
diff --git 
a/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php
index 18b3f4b..f7f780a 100644
--- a/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php
@@ -1,59 +1,12 @@
 <?php
 
 /**
- * FIXME so much: DRY
+ * TestingPaypalExpressAdapter
  */
 class TestingPaypalExpressAdapter extends PaypalExpressAdapter {
-       protected $dummyGatewayResponseCode = 'OK';
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyGatewayResponseCode( $code ) {
-               $this->dummyGatewayResponseCode = $code;
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyCurlResponseCode( $code ) {
-               $this->dummyCurlResponseCode = $code;
-       }
-
-       /**
-        * Load in some dummy response XML so we can test proper response 
processing
-        */
-       protected function curl_exec( $ch ) {
-               $code = '';
-               if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) {
-                       $code = '_' . $this->dummyGatewayResponseCode;
-               }
-
-               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
-               //but frankly I don't want to write tests that test our dummy 
responses.
-               $file_path = __DIR__ . '/../';
-               $file_path .= 'Responses' . '/' . self::getIdentifier() . '/';
-               $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
-
-               //these are all going to be short, so...
-               if ( file_exists( $file_path ) ) {
-                       return file_get_contents( $file_path );
-               }
-               throw new RuntimeException( "File $file_path does not exist." );
-       }
-
-       /**
-        * Load in some dummy curl response info so we can test proper response 
processing
-        */
-       protected function curl_getinfo( $ch, $opt = null ) {
-               $code = 200; //response OK
-               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
-                       $code = ( int ) $this->dummyCurlResponseCode;
-               }
-
-               //put more here if it ever turns out that we care about it.
-               return array (
-                       'http_code' => $code,
-               );
+       use TTestingAdapter;
+       public function __construct( array $options = array() ) {
+               $this->setDummyGatewayResponseCode( 'OK' );
+               parent::__construct( $options );
        }
 }
diff --git a/tests/phpunit/includes/test_gateway/TestingPaypalLegacyAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingPaypalLegacyAdapter.php
index 2f654c2..8c16d61 100644
--- a/tests/phpunit/includes/test_gateway/TestingPaypalLegacyAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingPaypalLegacyAdapter.php
@@ -4,63 +4,5 @@
  * @TODO: Extend/damage things here. I'm sure we'll need it eventually...
  */
 class TestingPaypalLegacyAdapter extends PaypalLegacyAdapter {
-       public static $fakeGlobals = array();
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyGatewayResponseCode( $code ) {
-               $this->dummyGatewayResponseCode = $code;
-       }
-
-       /**
-        * Set the error code you want the dummy response to return
-        */
-       public function setDummyCurlResponseCode( $code ) {
-               $this->dummyCurlResponseCode = $code;
-       }
-
-       /**
-        * Load in some dummy response XML so we can test proper response 
processing
-        */
-       protected function curl_exec( $ch ) {
-               $code = '';
-               if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) {
-                       $code = '_' . $this->dummyGatewayResponseCode;
-               }
-
-               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
-               //but frankly I don't want to write tests that test our dummy 
responses.
-               $file_path = __DIR__ . '/../';
-               $file_path .= 'Responses' . '/' . self::getIdentifier() . '/';
-               $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
-
-               //these are all going to be short, so...
-               if ( file_exists( $file_path ) ) {
-                       return file_get_contents( $file_path );
-               }
-               throw new RuntimeException( "File $file_path does not exist." );
-       }
-
-       /**
-        * Load in some dummy curl response info so we can test proper response 
processing
-        */
-       protected function curl_getinfo( $ch, $opt = null ) {
-               $code = 200; //response OK
-               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
-                       $code = ( int ) $this->dummyCurlResponseCode;
-               }
-
-               //put more here if it ever turns out that we care about it.
-               return array (
-                       'http_code' => $code,
-               );
-       }
-
-       public static function getGlobal( $name ) {
-               if ( array_key_exists( $name, self::$fakeGlobals ) ) {
-                       return self::$fakeGlobals[$name];
-               }
-               return parent::getGlobal( $name );
-       }
+       use TTestingAdapter;
 }
diff --git a/tests/phpunit/includes/test_gateway/test.adapter.php 
b/tests/phpunit/includes/test_gateway/test.adapter.php
new file mode 100644
index 0000000..3f299bf
--- /dev/null
+++ b/tests/phpunit/includes/test_gateway/test.adapter.php
@@ -0,0 +1,171 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+trait TTestingAdapter {
+       public static $fakeGlobals = array();
+
+       public static $fakeIdentifier;
+
+       public $curled = array();
+
+       public static function getIdentifier() {
+               if ( static::$fakeIdentifier ) {
+                       return static::$fakeIdentifier;
+               }
+               return parent::getIdentifier();
+       }
+
+       public static function getGlobal( $name ) {
+               if ( array_key_exists( $name, static::$fakeGlobals ) ) {
+                       return static::$fakeGlobals[$name];
+               }
+               return parent::getGlobal( $name );
+       }
+
+       /**
+        * Returns the variable $this->dataObj which should be an instance of
+        * DonationData.
+        *
+        * @returns DonationData
+        */
+       public function getDonationData() {
+               return $this->dataObj;
+       }
+
+       public function _buildRequestParams() {
+               return $this->buildRequestParams();
+       }
+
+       public function _addCodeRange() {
+               return call_user_func_array(array($this, 'addCodeRange'), 
func_get_args());
+       }
+
+       public function _findCodeAction() {
+               return call_user_func_array(array($this, 'findCodeAction'), 
func_get_args());
+       }
+
+       public function _buildRequestXML() {
+               return call_user_func_array( array ( $this, 'buildRequestXML' 
), func_get_args() );
+       }
+
+       public function _getData_Staged() {
+               return call_user_func_array( array ( $this, 'getData_Staged' ), 
func_get_args() );
+       }
+
+       public function _stageData() {
+               $this->stageData();
+       }
+
+       /**
+        * @TODO: Get rid of this and the override mechanism as soon as you
+        * refactor the constructor into something reasonable.
+        */
+       public function defineOrderIDMeta() {
+               if ( isset( $this->order_id_meta ) ) {
+                       return;
+               }
+               parent::defineOrderIDMeta();
+       }
+
+       //@TODO: That minfraud jerk needs its own isolated tests.
+       function runAntifraudFilters() {
+               //now screw around with the batch settings to trick the fraud 
filters into triggering
+               $is_batch = $this->isBatchProcessor();
+               $this->batch = true;
+
+               parent::runAntifraudFilters();
+
+               $this->batch = $is_batch;
+       }
+
+       public function getRiskScore() {
+               return $this->risk_score;
+       }
+
+       /**
+        * Set the error code you want the dummy response to return
+        */
+       public function setDummyGatewayResponseCode( $code ) {
+               $this->dummyGatewayResponseCode = $code;
+       }
+
+       /**
+        * Set the error code you want the dummy response to return
+        */
+       public function setDummyCurlResponseCode( $code ) {
+               $this->dummyCurlResponseCode = $code;
+       }
+
+       protected function curl_transaction( $data ) {
+               $this->curled[] = $data;
+               return parent::curl_transaction( $data );
+       }
+
+       /**
+        * Load in some dummy response XML so we can test proper response 
processing
+        */
+       protected function curl_exec( $ch ) {
+               $code = '';
+               if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) {
+                       if ( is_array( $this->dummyGatewayResponseCode ) ) {
+                               $code = array_shift( 
$this->dummyGatewayResponseCode );
+                       } elseif ( is_callable( $this->dummyGatewayResponseCode 
) ) {
+                               $code = call_user_func( 
$this->dummyGatewayResponseCode, $this );
+                       } else {
+                               $code = $this->dummyGatewayResponseCode;
+                       }
+               }
+               if ( $code ) {
+                       if ( $code === 'Exception' ) {
+                               throw new RuntimeException('blah!');
+                       }
+                       $code = '_' . $code;
+               }
+
+               //could start stashing these in a further-down subdir if 
payment type starts getting in the way,
+               //but frankly I don't want to write tests that test our dummy 
responses.
+               $file_path = __DIR__ . '/../';
+               $file_path .= 'Responses/' . static::getIdentifier() . '/';
+               $file_path .= $this->getCurrentTransaction() . $code . 
'.testresponse';
+
+               //these are all going to be short, so...
+               if ( file_exists( $file_path ) ) {
+                       return file_get_contents( $file_path );
+               } else {
+                       // FIXME: Throw an assertion instead.
+                       echo "File $file_path does not exist.\n"; //<-That will 
deliberately break the test.
+                       return false;
+               }
+       }
+
+       /**
+        * Load in some dummy curl response info so we can test proper response 
processing
+        */
+       protected function curl_getinfo( $ch, $opt = null ) {
+               $code = 200; //response OK
+               if ( property_exists( $this, 'dummyCurlResponseCode' ) ) {
+                       $code = ( int ) $this->dummyCurlResponseCode;
+               }
+
+               //put more here if it ever turns out that we care about it.
+               return array (
+                       'http_code' => $code,
+               );
+       }
+
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I501ab91de990304ceca012bc4044495f82af1e68
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Ssmith <ssm...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to