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

Change subject: Use new SmashPig global/provider configuration
......................................................................


Use new SmashPig global/provider configuration

Playing around with the new config classes. Seems to work. Made
a tradeoff where it's not super elegant to override provider config
in tests, but at least we don't have ugly test code or unnecessary
factories in the normal use case.

Change-Id: Ibd7173399ae9019436458ce2ff809c26d7cb8ddb
---
M DonationInterface.class.php
M amazon_gateway/amazon.api.php
M composer.lock
M gateway_common/GatewayPage.php
M gateway_common/donation.api.php
M tests/phpunit/Adapter/Adyen/AdyenTest.php
M tests/phpunit/Adapter/Amazon/AmazonApiTest.php
M tests/phpunit/Adapter/Amazon/AmazonTest.php
M tests/phpunit/Adapter/AstroPay/AstroPayTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
M tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
M tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
M tests/phpunit/DonationInterfaceTestCase.php
M tests/phpunit/DonationQueueTest.php
16 files changed, 89 insertions(+), 43 deletions(-)

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



diff --git a/DonationInterface.class.php b/DonationInterface.class.php
index fbb0713..2f2f7db 100644
--- a/DonationInterface.class.php
+++ b/DonationInterface.class.php
@@ -1,7 +1,8 @@
 <?php
 
-use SmashPig\Core\Configuration;
+use SmashPig\Core\GlobalConfiguration;
 use SmashPig\Core\Context;
+use SmashPig\Core\ProviderConfiguration;
 
 class DonationInterface {
        /**
@@ -10,7 +11,8 @@
        public static function registerExtension() {
                global $wgDonationInterfaceTestMode,
                        $wgDonationInterfaceTemplate,
-                       $wgDonationInterfaceErrorTemplate;
+                       $wgDonationInterfaceErrorTemplate,
+                       $IP;
 
                // Test mode (not for production!)
                // Set it if not defined
@@ -34,13 +36,20 @@
                // Include composer's autoload if the vendor directory exists.  
If we have been
                // included via Composer, our dependencies should already be 
autoloaded at the
                // top level.
-               // Note that in WMF's continuous integration, we can still only 
use stuff from
-               // Composer if it is already in Mediawiki's vendor directory, 
such as monolog
                $vendorAutoload = __DIR__ . '/vendor/autoload.php';
                if ( file_exists( $vendorAutoload ) ) {
                        require_once ( $vendorAutoload );
                } else {
                        require_once ( __DIR__ . 
'/gateway_common/WmfFramework.php' );
+               }
+               if ( defined( 'MEDIAWIKI' ) ) {
+                       // If we're the top-level application, initialize the 
SmashPig context
+                       $spConfig = GlobalConfiguration::create();
+                       Context::init( $spConfig );
+                       $context = Context::get();
+                       $context->setSourceName( 'DonationInterface' );
+                       $context->setSourceType( 'payments' );
+                       $context->setVersionFromFile( "$IP/.version-stamp");
                }
        }
 
@@ -89,19 +98,18 @@
        /**
         * Initialize SmashPig context and return configuration object
         *
-        * @param string $view
-        * @return Configuration
+        * @param string $provider
+        * @return ProviderConfiguration
         */
-       public static function initializeSmashPig( $view ) {
-               global $IP;
-               $spConfig = Configuration::createForView( $view );
+       public static function setSmashPigProvider( $provider ) {
+               $ctx = Context::get();
+               $spConfig = ProviderConfiguration::createForProvider(
+                       $provider,
+                       $ctx->getGlobalConfiguration()
+               );
                // FIXME: should set a logger prefix here, but we've got a 
chicken
                // and egg problem with the Gateway constructor
-               Context::initWithLogger( $spConfig );
-               $context = Context::get();
-               $context->setSourceName( 'DonationInterface' );
-               $context->setSourceType( 'payments' );
-               $context->setVersionFromFile( "$IP/.version-stamp");
+               $ctx->setProviderConfiguration( $spConfig );
                return $spConfig;
        }
 }
diff --git a/amazon_gateway/amazon.api.php b/amazon_gateway/amazon.api.php
index 3b9cd54..f482348 100644
--- a/amazon_gateway/amazon.api.php
+++ b/amazon_gateway/amazon.api.php
@@ -11,7 +11,7 @@
        );
 
        public function execute() {
-               DonationInterface::initializeSmashPig( 'amazon' );
+               DonationInterface::setSmashPigProvider( 'amazon' );
                $output = $this->getResult();
                $recurring = $this->getParameter( 'recurring');
                $token = $this->getParameter( 'wmf_token' );
diff --git a/composer.lock b/composer.lock
index 828001b..8a7255c 100644
--- a/composer.lock
+++ b/composer.lock
@@ -985,7 +985,7 @@
             "source": {
                 "type": "git",
                 "url": 
"https://gerrit.wikimedia.org/r/wikimedia/fundraising/SmashPig.git";,
-                "reference": "a8b134cf2cef5cdb0a5960b72335410081a72a5d"
+                "reference": "756898ef42efd9e6ff316823e4b03b6a90c78589"
             },
             "require": {
                 "amzn/login-and-pay-with-amazon-sdk-php": "dev-master",
@@ -1037,7 +1037,7 @@
                 "donations",
                 "payments"
             ],
-            "time": "2017-05-19T17:03:40+00:00"
+            "time": "2017-07-05 15:58:53"
         },
         {
             "name": "zordius/lightncandy",
diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php
index 5805eb6..f2061ea 100644
--- a/gateway_common/GatewayPage.php
+++ b/gateway_common/GatewayPage.php
@@ -81,7 +81,7 @@
 
                $gatewayName = $this->getGatewayIdentifier();
                $className = DonationInterface::getAdapterClassForGateway( 
$gatewayName );
-               DonationInterface::initializeSmashPig( $gatewayName );
+               DonationInterface::setSmashPigProvider( $gatewayName );
 
                try {
                        $this->adapter = new $className();
diff --git a/gateway_common/donation.api.php b/gateway_common/donation.api.php
index c90896b..5d38d3c 100644
--- a/gateway_common/donation.api.php
+++ b/gateway_common/donation.api.php
@@ -17,7 +17,7 @@
                // @todo FIXME: Unused local variable.
                $submethod = $this->donationData['payment_submethod'];
 
-               DonationInterface::initializeSmashPig( $this->gateway );
+               DonationInterface::setSmashPigProvider( $this->gateway );
                $gatewayObj = $this->getGatewayObject();
 
                // FIXME: SmashPig should just use Monolog.
diff --git a/tests/phpunit/Adapter/Adyen/AdyenTest.php 
b/tests/phpunit/Adapter/Adyen/AdyenTest.php
index e76995d..371c800 100644
--- a/tests/phpunit/Adapter/Adyen/AdyenTest.php
+++ b/tests/phpunit/Adapter/Adyen/AdyenTest.php
@@ -14,7 +14,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  */
-
+use SmashPig\PaymentProviders\Adyen\Tests\AdyenTestConfiguration;
+use SmashPig\Tests\TestingContext;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -37,7 +38,10 @@
 
        public function setUp() {
                parent::setUp();
-               DonationInterface::initializeSmashPig( 'adyen' );
+               TestingContext::get()->providerConfigurationOverride =
+                       AdyenTestConfiguration::createWithSuccessfulApi(
+                               $this->smashPigGlobalConfig
+                       );
 
                $this->setMwGlobals( array(
                        'wgAdyenGatewayEnabled' => true,
diff --git a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php 
b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
index 04ca56b..8ee1c83 100644
--- a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
+++ b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
@@ -1,4 +1,6 @@
 <?php
+use SmashPig\Tests\TestingContext;
+use SmashPig\Tests\TestingGlobalConfiguration;
 
 /**
  * @group Amazon
@@ -7,6 +9,8 @@
 class AmazonApiTest extends ApiTestCase {
        public function setUp() {
                parent::setUp();
+               $config = TestingGlobalConfiguration::create();
+               TestingContext::init( $config );
                TestingAmazonAdapter::$mockClient = new MockAmazonClient();
                $this->setMwGlobals( array(
                        'wgDonationInterfaceEnableQueue' => true,
diff --git a/tests/phpunit/Adapter/Amazon/AmazonTest.php 
b/tests/phpunit/Adapter/Amazon/AmazonTest.php
index 527ff70..3b29316 100644
--- a/tests/phpunit/Adapter/Amazon/AmazonTest.php
+++ b/tests/phpunit/Adapter/Amazon/AmazonTest.php
@@ -14,9 +14,11 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  */
+use SmashPig\PaymentProviders\Amazon\Tests\AmazonTestConfiguration;
+use SmashPig\Tests\TestingContext;
 
 /**
- * 
+ *
  * @group Fundraising
  * @group DonationInterface
  * @group Amazon
@@ -35,7 +37,10 @@
 
        public function setUp() {
                parent::setUp();
-               DonationInterface::initializeSmashPig( 'amazon' );
+               TestingContext::get()->providerConfigurationOverride =
+                       AmazonTestConfiguration::instance(
+                               $this->smashPigGlobalConfig
+                       );
 
                TestingAmazonAdapter::$mockClient = new MockAmazonClient();
 
diff --git a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php 
b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
index 38c81fd..59e1185 100644
--- a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
+++ b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
@@ -17,9 +17,9 @@
  */
 
 use \Psr\Log\LogLevel;
-use SmashPig\Core\Configuration;
-use SmashPig\Core\Context;
 use SmashPig\CrmLink\Messages\SourceFields;
+use SmashPig\Tests\TestingContext;
+use SmashPig\Tests\TestingProviderConfiguration;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -45,8 +45,11 @@
                $this->setMwGlobals( array(
                        'wgAstroPayGatewayEnabled' => true,
                ) );
-               $config = Configuration::createForView( 'astropay' );
-               Context::initWithLogger( $config );
+               TestingContext::get()->providerConfigurationOverride =
+                       TestingProviderConfiguration::createForProvider(
+                               'astropay',
+                               $this->smashPigGlobalConfig
+                       );
        }
 
        /**
diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
index 31ede5a..f3738eb 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
@@ -1,5 +1,8 @@
 <?php
 
+use SmashPig\Tests\TestingContext;
+use SmashPig\Tests\TestingGlobalConfiguration;
+
 /**
  * @group Fundraising
  * @group DonationInterface
@@ -10,6 +13,12 @@
 
 class GlobalCollectApiTest extends ApiTestCase {
 
+       public function setUp() {
+               parent::setUp();
+               $config = TestingGlobalConfiguration::create();
+               TestingContext::init( $config );
+       }
+
        public function testGoodSubmit() {
                $init = DonationInterfaceTestCase::getDonorTestData();
                $init['email'] = '[email protected]';
diff --git 
a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
index 3e2ed75..8053400 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
@@ -17,9 +17,9 @@
  */
 
 use Psr\Log\LogLevel;
-use SmashPig\Core\Configuration;
-use SmashPig\Core\Context;
 use SmashPig\CrmLink\Messages\SourceFields;
+use SmashPig\Tests\TestingContext;
+use SmashPig\Tests\TestingProviderConfiguration;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -33,8 +33,12 @@
        public function setUp() {
                parent::setUp();
 
-               $config = Configuration::createForView( 'globalcollect' );
-               Context::initWithLogger( $config );
+               TestingContext::get()->providerConfigurationOverride =
+                       TestingProviderConfiguration::createForProvider(
+                               'globalcollect',
+                               $this->smashPigGlobalConfig
+                       );
+
 
                $this->setMwGlobals( array(
                        'wgGlobalCollectGatewayEnabled' => true,
diff --git 
a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
index 7b3c486..a4dd4e3 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php
@@ -17,9 +17,7 @@
  *
  */
 
-use SmashPig\Core\Context;
 use SmashPig\Core\DataStores\PendingDatabase;
-use SmashPig\Tests\SmashPigDatabaseTestConfiguration;
 
 /**
  * @covers GlobalCollectOrphanRectifier
@@ -60,9 +58,6 @@
                                'globalcollect_orphan' => 
'TestingGlobalCollectOrphanAdapter',
                        ),
                ) );
-
-               $config = SmashPigDatabaseTestConfiguration::instance();
-               Context::init( $config );
 
                $this->pendingDb = PendingDatabase::get();
 
diff --git 
a/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php 
b/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
index b56254c..8359628 100644
--- a/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php
@@ -15,8 +15,8 @@
  * GNU General Public License for more details.
  *
  */
-use SmashPig\Core\Configuration;
-use SmashPig\Core\Context;
+use SmashPig\Tests\TestingContext;
+use SmashPig\Tests\TestingProviderConfiguration;
 
 /**
  * 
@@ -34,8 +34,10 @@
        public function setUp() {
                parent::setUp();
 
-               $config = Configuration::createForView( 'ingenico' );
-               Context::initWithLogger( $config ); // gets torn down in parent
+               $config = TestingProviderConfiguration::createForProvider(
+                       'ingenico', $this->smashPigGlobalConfig
+               );
+               TestingContext::get()->providerConfigurationOverride = $config;
 
                $this->bankPaymentProvider = $this->getMockBuilder(
                        
'\SmashPig\PaymentProviders\Ingenico\BankPaymentProvider'
diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php 
b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
index 3cd130f..35b9b6a 100644
--- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
+++ b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
@@ -6,6 +6,8 @@
  *
  * 
TIMESTAMP=2016%2d05%2d03T21%3a43%3a20Z&CORRELATIONID=f624ed5aa5db0&ACK=Failure&VERSION=124&BUILD=21669447&L_ERRORCODE0=10412&L_SHORTMESSAGE0=Duplicate%20invoice&L_LONGMESSAGE0=Payment%20has%20already%20been%20made%20for%20this%20InvoiceID%2e&L_SEVERITYCODE0=Error
  */
+use SmashPig\PaymentProviders\PayPal\Tests\PayPalTestConfiguration;
+use SmashPig\Tests\TestingContext;
 
 /**
  *
@@ -19,7 +21,9 @@
 
        public function setUp() {
                parent::setUp();
-               DonationInterface::initializeSmashPig( 'paypal' );
+               TestingContext::get()->providerConfigurationOverride = 
PayPalTestConfiguration::get(
+                       $this->smashPigGlobalConfig
+               );
                $this->setMwGlobals( array(
                        'wgDonationInterfaceCancelPage' => 
'https://example.com/tryAgain.php',
                        'wgPaypalExpressGatewayEnabled' => true,
diff --git a/tests/phpunit/DonationInterfaceTestCase.php 
b/tests/phpunit/DonationInterfaceTestCase.php
index 42700a7..c3548ae 100644
--- a/tests/phpunit/DonationInterfaceTestCase.php
+++ b/tests/phpunit/DonationInterfaceTestCase.php
@@ -15,9 +15,11 @@
  * GNU General Public License for more details.
  *
  */
-
 use Psr\Log\LogLevel;
 use SmashPig\Core\Context;
+use SmashPig\Tests\TestingContext;
+use SmashPig\Tests\TestingGlobalConfiguration;
+use SmashPig\Tests\TestingProviderConfiguration;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -53,6 +55,7 @@
         */
        protected $testLogger;
        protected $testAdapterClass = TESTS_ADAPTER_DEFAULT;
+       protected $smashPigGlobalConfig;
 
        /**
         * @param $name string The name of the test case
@@ -79,6 +82,12 @@
                                'type' => 'TestingQueue',
                        ),
                ) );
+               // Replace real SmashPig context with test version that lets us
+               // override provider configurations that may be set in code
+               $this->smashPigGlobalConfig = 
TestingGlobalConfiguration::create();
+               TestingContext::init( $this->smashPigGlobalConfig );
+               Context::get()->setSourceType( 'payments' );
+               Context::get()->setSourceName( 'DonationInterface' );
                parent::setUp();
        }
 
diff --git a/tests/phpunit/DonationQueueTest.php 
b/tests/phpunit/DonationQueueTest.php
index e21be67..6dd1ec0 100644
--- a/tests/phpunit/DonationQueueTest.php
+++ b/tests/phpunit/DonationQueueTest.php
@@ -31,7 +31,6 @@
        public function setUp() {
                parent::setUp();
 
-               DonationInterface::initializeSmashPig( 'default' );
                $this->queue_name = 'test-' . mt_rand();
 
                $this->setMwGlobals( array(

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibd7173399ae9019436458ce2ff809c26d7cb8ddb
Gerrit-PatchSet: 13
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Mepps <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to