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

Change subject: Use dependency injection to get BankPaymentProvider
......................................................................

Use dependency injection to get BankPaymentProvider

This way we don't need to mock the low-level cURL response.
Unfortunately, we need to write a substitute class. Would it really
be so bad to use SmashPig's Configuration::object in DonationInterface
code?

Bug: T128692
Change-Id: I3b35350bf944207786e8bded33d04caf1f287dbf
---
M DonationInterface.class.php
M extension.json
M globalcollect_gateway/globalcollect.adapter.php
M tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
4 files changed, 40 insertions(+), 36 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/77/338277/1

diff --git a/DonationInterface.class.php b/DonationInterface.class.php
index 5ffe3ba..d6756c9 100644
--- a/DonationInterface.class.php
+++ b/DonationInterface.class.php
@@ -74,12 +74,21 @@
                return true;
        }
 
-       public static function getAdapterClassForGateway( $gateway ) {
+       public static function getAdapterClassForGateway( $gateway, 
$payment_method = null ) {
                global $wgDonationInterfaceGatewayAdapters;
                if ( !key_exists( $gateway, $wgDonationInterfaceGatewayAdapters 
) ) {
                        throw new OutOfRangeException( "No adapter configured 
for $gateway" );
                }
-               return $wgDonationInterfaceGatewayAdapters[$gateway];
+               $entry = $wgDonationInterfaceGatewayAdapters[$gateway];
+               if ( !is_array( $entry ) ) {
+                       return $entry;
+               }
+               if ( !key_exists( $payment_method, $entry ) ) {
+                       throw new OutOfRangeException(
+                               "$gateway has no payment provider for 
$payment_method configured"
+                       );
+               }
+               return $entry[ $payment_method ];
        }
 
        /**
diff --git a/extension.json b/extension.json
index dc2b360..908c221 100644
--- a/extension.json
+++ b/extension.json
@@ -451,7 +451,10 @@
                        "adyen": "AdyenAdapter",
                        "astropay": "AstroPayAdapter",
                        "paypal_ec": "PaypalExpressAdapter",
-                       "paypal": "PaypalLegacyAdapter"
+                       "paypal": "PaypalLegacyAdapter",
+                       "ingenico": {
+                               "rtbt": 
"SmashPig\\PaymentProviders\\Ingenico\\BankPaymentProvider"
+                       }
                },
                "DonationInterfaceAllowedHtmlForms": []
        },
diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index aadbedc..6ea54f6 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -1759,7 +1759,11 @@
                        return;
                }
                try {
-                       $provider = new BankPaymentProvider();
+                       $providerClass = 
DonationInterface::getAdapterClassForGateway(
+                               'ingenico',
+                               'rtbt'
+                       );
+                       $provider = new $providerClass();
                        $banks = $provider->getBankList( $country, $currency );
                        $meta['issuers'] = $banks;
                }
diff --git 
a/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php 
b/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
index 426999c..a0f8e73 100644
--- a/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
@@ -17,6 +17,7 @@
  */
 use SmashPig\Core\Configuration;
 use SmashPig\Core\Context;
+use SmashPig\PaymentProviders\Ingenico\BankPaymentProvider;
 
 /**
  * 
@@ -26,42 +27,17 @@
  * @group RealTimeBankTransfer
  */
 class DonationInterface_Adapter_GlobalCollect_RealTimeBankTransferIdealTest 
extends DonationInterfaceTestCase {
-       /**
-        * @var PHPUnit_Framework_MockObject_MockObject
-        */
-       protected $cache;
-       protected $curlWrapper;
 
        public function setUp() {
                parent::setUp();
-
-               $config = Configuration::createForView( 'ingenico' );
-               Context::initWithLogger( $config ); // gets torn down in parent
-
-               $this->cache = new HashBagOStuff();
-               $cacheWrapper = new 
Addshore\Psr\Cache\MWBagOStuffAdapter\BagOStuffPsrCache( $this->cache );
-               $config->overrideObjectInstance( 'cache', $cacheWrapper );
-
-               // FIXME: This is all wrong - in this project we should be 
mocking the
-               // parsed API response or even the whole getBankList result.
-               // Definitely shouldn't have to get into the curlWrapper
-               $this->curlWrapper = $this->getMock( 
'\SmashPig\Core\Http\CurlWrapper' );
-               $config->overrideObjectInstance( 'curl/wrapper', 
$this->curlWrapper );
-               $this->curlWrapper->method( 'execute' )
-                       ->willReturn( array(
-                               'body' => '{
-   "entries" : [ {
-      "countryNames" : [ "Nederland" ],
-      "issuerId" : "INGBNL2A",
-      "issuerList" : "short",
-      "issuerName" : "Issuer Simulation V3 - ING"
-   } ]
-}',
-                               'headers' => array(),
-                               'status' => '200'
-                       ) );
-
                $this->setMwGlobals( array(
+                       'wgDonationInterfaceGatewayAdapters' => array(
+                               'globalcollect' => 
'TestingGlobalCollectAdapter',
+                               'ingenico' => array(
+                                       // Still not ideal that we can't use a 
mock here
+                                       'rtbt' => 'FakeBankPaymentProvider'
+                               )
+                       ),
                        'wgGlobalCollectGatewayEnabled' => true,
                        'wgDonationInterfaceAllowedHtmlForms' => array(
                                'rtbt-ideal' => array(
@@ -375,3 +351,15 @@
 
 }
 
+class FakeBankPaymentProvider extends BankPaymentProvider {
+       public function __construct() {
+               // FIXME: Also not elegant. We're avoiding SmashPig context.
+       }
+
+       public function getBankList( $country, $currency, $productId = 809 ) {
+               return array(
+                       "test1234" => "Test Bank 1234",
+                       "test5678" => "Test Bank 5678",
+               );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3b35350bf944207786e8bded33d04caf1f287dbf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

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

Reply via email to