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

Change subject: Convenience functions to initialize test datastores
......................................................................

Convenience functions to initialize test datastores

Change-Id: I8fc43379cc5aff32fb8d3d95e92deff2191e4bf1
---
M Core/Context.php
M PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php
M PaymentProviders/Adyen/Tests/phpunit/CaptureResponseActionTest.php
M PaymentProviders/Adyen/Tests/phpunit/PaymentCaptureActionTest.php
M PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php
M PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php
M PaymentProviders/Adyen/Tests/phpunit/RequeueMessageTest.php
M PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
M Tests/BaseSmashPigUnitTestCase.php
M Tests/DamagedDatabaseTest.php
M Tests/PaymentsInitialDatabaseTest.php
M Tests/PendingDatabaseTest.php
M Tests/PendingQueueConsumerTest.php
M Tests/QueueConsumerTest.php
M Tests/SmashPigDatabaseTest.php
M Tests/TestingContext.php
M Tests/TestingDatabase.php
17 files changed, 30 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/04/356304/1

diff --git a/Core/Context.php b/Core/Context.php
index d7d4670..2be82d2 100644
--- a/Core/Context.php
+++ b/Core/Context.php
@@ -35,7 +35,7 @@
 
        /**
         * Obtains the current context object
-        * @return Context
+        * @return static
         */
        public static function get() {
                return Context::$instance;
diff --git a/PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php 
b/PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php
index 0a76f47..ef6a192 100644
--- a/PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php
+++ b/PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php
@@ -36,7 +36,6 @@
                $this->config = 
AdyenTestConfiguration::createWithSuccessfulApi();
                Context::get()->setProviderConfiguration( $this->config );
                $this->pendingDatabase = PendingDatabase::get();
-               $this->pendingDatabase->createTable();
                $this->pendingMessage = json_decode(
                        file_get_contents( __DIR__ . '/../Data/pending.json' ) 
, true
                );
diff --git a/PaymentProviders/Adyen/Tests/phpunit/CaptureResponseActionTest.php 
b/PaymentProviders/Adyen/Tests/phpunit/CaptureResponseActionTest.php
index 2e114a3..195cc7e 100644
--- a/PaymentProviders/Adyen/Tests/phpunit/CaptureResponseActionTest.php
+++ b/PaymentProviders/Adyen/Tests/phpunit/CaptureResponseActionTest.php
@@ -26,7 +26,6 @@
 
                $this->jobQueue = $context->getGlobalConfiguration()
                        ->object( 'data-store/jobs-adyen' );
-               $this->jobQueue->createTable( 'jobs-adyen' );
        }
 
        public function testSuccessfulCapture() {
diff --git a/PaymentProviders/Adyen/Tests/phpunit/PaymentCaptureActionTest.php 
b/PaymentProviders/Adyen/Tests/phpunit/PaymentCaptureActionTest.php
index b7bdbe2..9667abc 100644
--- a/PaymentProviders/Adyen/Tests/phpunit/PaymentCaptureActionTest.php
+++ b/PaymentProviders/Adyen/Tests/phpunit/PaymentCaptureActionTest.php
@@ -23,7 +23,6 @@
                Context::get()->setProviderConfiguration( $providerConfig );
                $globalConfig = Context::get()->getGlobalConfiguration();
                $this->jobQueue = $globalConfig->object( 
'data-store/jobs-adyen' );
-               $this->jobQueue->createTable( 'jobs-adyen' );
        }
 
        public function testSuccessfulAuth() {
diff --git a/PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php 
b/PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php
index 3b0345d..09d4aa8 100644
--- a/PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php
+++ b/PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php
@@ -30,7 +30,6 @@
                $this->config = 
AdyenTestConfiguration::createWithSuccessfulApi();
                Context::get()->setProviderConfiguration( $this->config );
                $this->pendingDatabase = PendingDatabase::get();
-               $this->pendingDatabase->createTable();
                $this->pendingMessage = json_decode(
                        file_get_contents( __DIR__ . '/../Data/pending.json' ) 
, true
                );
@@ -45,8 +44,6 @@
 
        public function testRecordCapture() {
                $donationsQueue = QueueWrapper::getQueue( 'donations' );
-               $donationsQueue->createTable( 'donations' );
-
                $capture = JsonSerializableObject::fromJsonProxy(
                        
'SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Capture',
                        file_get_contents( __DIR__ . '/../Data/capture.json' )
diff --git a/PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php 
b/PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php
index 077bd25..f5ccb06 100644
--- a/PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php
+++ b/PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php
@@ -28,7 +28,6 @@
                $this->config = 
AdyenTestConfiguration::createWithSuccessfulApi();
                Context::get()->setProviderConfiguration( $this->config );
                $this->jobQueue = QueueWrapper::getQueue( 'jobs-adyen' );
-               $this->jobQueue->createTable( 'jobs-adyen' );
        }
 
        public function testReportAvailable() {
diff --git a/PaymentProviders/Adyen/Tests/phpunit/RequeueMessageTest.php 
b/PaymentProviders/Adyen/Tests/phpunit/RequeueMessageTest.php
index 9cf9d38..bd4977d 100644
--- a/PaymentProviders/Adyen/Tests/phpunit/RequeueMessageTest.php
+++ b/PaymentProviders/Adyen/Tests/phpunit/RequeueMessageTest.php
@@ -19,7 +19,6 @@
                parent::setUp();
                $config = AdyenTestConfiguration::createWithSuccessfulApi();
                Context::get()->setProviderConfiguration( $config );
-               PendingDatabase::get()->createTable();
        }
 
        /**
diff --git 
a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php 
b/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
index 20b9173..a25426d 100644
--- a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
+++ b/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php
@@ -43,10 +43,6 @@
        public function setUp() {
                parent::setUp();
                $this->config = Context::get()->getGlobalConfiguration();
-               // php-queue\PDO complains about pop() from non-existent table
-               $this->config->object( 'data-store/jobs-paypal' )
-                       ->createTable( 'jobs-paypal' );
-
                Context::get()->setProviderConfiguration(
                        PayPalTestConfiguration::get()
                );
@@ -126,7 +122,6 @@
                $job->execute();
 
                $queue = $this->config->object( 'data-store/' . $msg['type'] );
-               $queue->createTable( $msg['type'] );
                $message = $queue->pop();
 
                if ( $job->is_reject() ) {
diff --git a/Tests/BaseSmashPigUnitTestCase.php 
b/Tests/BaseSmashPigUnitTestCase.php
index 25b90df..eb918eb 100644
--- a/Tests/BaseSmashPigUnitTestCase.php
+++ b/Tests/BaseSmashPigUnitTestCase.php
@@ -10,7 +10,7 @@
        public function setUp() {
                parent::setUp();
                $globalConfig = TestingGlobalConfiguration::create();
-               Context::init( $globalConfig );
+               TestingContext::init( $globalConfig );
                // TODO: create tables for all dbs/queues.
                // Standard issue CurlWrapper mock would be nice too
        }
diff --git a/Tests/DamagedDatabaseTest.php b/Tests/DamagedDatabaseTest.php
index 2d48149..4488586 100644
--- a/Tests/DamagedDatabaseTest.php
+++ b/Tests/DamagedDatabaseTest.php
@@ -16,7 +16,6 @@
        public function setUp() {
                parent::setUp();
                $this->db = DamagedDatabase::get();
-               $this->db->createTable();
        }
 
        public function tearDown() {
diff --git a/Tests/PaymentsInitialDatabaseTest.php 
b/Tests/PaymentsInitialDatabaseTest.php
index af94234..4c04d9d 100644
--- a/Tests/PaymentsInitialDatabaseTest.php
+++ b/Tests/PaymentsInitialDatabaseTest.php
@@ -16,7 +16,6 @@
        public function setUp() {
                parent::setUp();
                $this->db = PaymentsInitialDatabase::get();
-               $this->db->createTable();
        }
 
        public function tearDown() {
diff --git a/Tests/PendingDatabaseTest.php b/Tests/PendingDatabaseTest.php
index 2c7426e..8382eeb 100644
--- a/Tests/PendingDatabaseTest.php
+++ b/Tests/PendingDatabaseTest.php
@@ -16,7 +16,6 @@
        public function setUp() {
                parent::setUp();
                $this->db = PendingDatabase::get();
-               $this->db->createTable();
        }
 
        public function tearDown() {
diff --git a/Tests/PendingQueueConsumerTest.php 
b/Tests/PendingQueueConsumerTest.php
index 12ee100..4c36657 100644
--- a/Tests/PendingQueueConsumerTest.php
+++ b/Tests/PendingQueueConsumerTest.php
@@ -22,9 +22,7 @@
        public function setUp() {
                parent::setUp();
                $this->pendingDb = PendingDatabase::get();
-               $this->pendingDb->createTable();
                $this->paymentsInitialDb = PaymentsInitialDatabase::get();
-               $this->paymentsInitialDb->createTable();
        }
 
        public function tearDown() {
diff --git a/Tests/QueueConsumerTest.php b/Tests/QueueConsumerTest.php
index 60c5df6..25265f5 100644
--- a/Tests/QueueConsumerTest.php
+++ b/Tests/QueueConsumerTest.php
@@ -23,9 +23,7 @@
        public function setUp() {
                parent::setUp();
                $this->queue = QueueWrapper::getQueue( 'test' );
-               $this->queue->createTable( 'test' );
                $damagedDb = DamagedDatabase::get();
-               $damagedDb->createTable();
                $this->damaged = $damagedDb->getDatabase();
        }
 
diff --git a/Tests/SmashPigDatabaseTest.php b/Tests/SmashPigDatabaseTest.php
index b8c0e2b..b8992f5 100644
--- a/Tests/SmashPigDatabaseTest.php
+++ b/Tests/SmashPigDatabaseTest.php
@@ -22,9 +22,7 @@
                parent::setUp();
 
                $this->pendingDb = PendingDatabase::get();
-               $this->pendingDb->createTable();
                $this->paymentsInitialDb = PaymentsInitialDatabase::get();
-               $this->paymentsInitialDb->createTable();
        }
 
        public function tearDown() {
diff --git a/Tests/TestingContext.php b/Tests/TestingContext.php
index b82ec9f..e06f781 100644
--- a/Tests/TestingContext.php
+++ b/Tests/TestingContext.php
@@ -3,6 +3,7 @@
 namespace SmashPig\Tests;
 
 use SmashPig\Core\Context;
+use SmashPig\Core\DataStores\QueueWrapper;
 use SmashPig\Core\GlobalConfiguration;
 
 class TestingContext extends Context {
@@ -18,6 +19,19 @@
                }
                Context::$instance->setProviderConfiguration( $providerConfig );
                Context::$instance->setGlobalConfiguration( $config );
+               TestingDatabase::createTables();
+               self::initializeQueues( $config );
+       }
+
+       protected static function initializeQueues( GlobalConfiguration $config 
) {
+               foreach ( $config->val( 'data-store' ) as $name => $definition 
) {
+                       if (
+                               array_key_exists( 'class', $definition ) &&
+                               is_subclass_of( $definition['class'], 
'\PHPQueue\Backend\PDO' )
+                       ) {
+                               QueueWrapper::getQueue( $name )->createTable();
+                       }
+               }
        }
 
        public function getProviderConfiguration() {
@@ -26,4 +40,5 @@
                }
                return parent::getProviderConfiguration();
        }
+
 }
\ No newline at end of file
diff --git a/Tests/TestingDatabase.php b/Tests/TestingDatabase.php
index 48e0e87..78eb4a7 100644
--- a/Tests/TestingDatabase.php
+++ b/Tests/TestingDatabase.php
@@ -2,6 +2,10 @@
 
 namespace SmashPig\Tests;
 
+use SmashPig\Core\DataStores\DamagedDatabase;
+use SmashPig\Core\DataStores\PaymentsInitialDatabase;
+use SmashPig\Core\DataStores\PendingDatabase;
+
 class TestingDatabase {
        /**
         * @param string|object $classish Database class to reset, as a 
qualified
@@ -14,4 +18,13 @@
                $dbProperty->setAccessible( true );
                $dbProperty->setValue( array() );
        }
+
+       /**
+        * Initialize all the db tables
+        */
+       public static function createTables() {
+               DamagedDatabase::get()->createTable();
+               PaymentsInitialDatabase::get()->createTable();
+               PendingDatabase::get()->createTable();
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fc43379cc5aff32fb8d3d95e92deff2191e4bf1
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
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