Ejegg has submitted this change and it was merged.

Change subject: Helper to clear *Database singletons
......................................................................


Helper to clear *Database singletons

Change-Id: Ie0f2c5f03ce440917feed73c74078efa275f2688
---
M Tests/PaymentsInitialDatabaseTest.php
M Tests/PendingDatabaseTest.php
M Tests/PendingQueueConsumerTest.php
A Tests/TestingDatabase.php
4 files changed, 29 insertions(+), 10 deletions(-)

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



diff --git a/Tests/PaymentsInitialDatabaseTest.php 
b/Tests/PaymentsInitialDatabaseTest.php
index 377bc15..0a477ec 100644
--- a/Tests/PaymentsInitialDatabaseTest.php
+++ b/Tests/PaymentsInitialDatabaseTest.php
@@ -22,11 +22,7 @@
        }
 
        public function tearDown() {
-               // Reset PDO static member
-               $klass = new \ReflectionClass( 
'SmashPig\Core\DataStores\PaymentsInitialDatabase' );
-               $dbProperty = $klass->getProperty( 'db' );
-               $dbProperty->setAccessible( true );
-               $dbProperty->setValue( null );
+               TestingDatabase::clearStatics( $this->db );
 
                parent::tearDown();
        }
diff --git a/Tests/PendingDatabaseTest.php b/Tests/PendingDatabaseTest.php
index 0d87f77..f87873b 100644
--- a/Tests/PendingDatabaseTest.php
+++ b/Tests/PendingDatabaseTest.php
@@ -22,11 +22,7 @@
        }
 
        public function tearDown() {
-               // Reset PDO static member
-               $klass = new \ReflectionClass( 
'SmashPig\Core\DataStores\PendingDatabase' );
-               $dbProperty = $klass->getProperty( 'db' );
-               $dbProperty->setAccessible( true );
-               $dbProperty->setValue( null );
+               TestingDatabase::clearStatics( $this->db );
 
                parent::tearDown();
        }
diff --git a/Tests/PendingQueueConsumerTest.php 
b/Tests/PendingQueueConsumerTest.php
index 9f51897..17b6bc1 100644
--- a/Tests/PendingQueueConsumerTest.php
+++ b/Tests/PendingQueueConsumerTest.php
@@ -35,6 +35,16 @@
                $this->paymentsInitialDb->createTable();
        }
 
+       public function tearDown() {
+               // FIXME: huh.  I guess we should use class names to avoid 
possible
+               // incomplete destruction in the case that paymentsInitialDb 
was never
+               // initialized.
+               TestingDatabase::clearStatics( $this->paymentsInitialDb );
+               TestingDatabase::clearStatics( $this->pendingDb );
+
+               parent::tearDown();
+       }
+
        /**
         * We consume a message normally if there's nothing in the 
payments_initial
         * table.
diff --git a/Tests/TestingDatabase.php b/Tests/TestingDatabase.php
new file mode 100644
index 0000000..6173a22
--- /dev/null
+++ b/Tests/TestingDatabase.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace SmashPig\Tests;
+
+class TestingDatabase {
+       /**
+        * @param string|object $classish Database class to reset, as a 
qualified
+        * class name or example object.  Must be a subtype of SmashPigDatabase 
for
+        * the statics to make sense.
+        */
+       public static function clearStatics( $classish ) {
+               $klass = new \ReflectionClass( $classish );
+               $dbProperty = $klass->getProperty( 'db' );
+               $dbProperty->setAccessible( true );
+               $dbProperty->setValue( null );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie0f2c5f03ce440917feed73c74078efa275f2688
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Ejegg <eeggles...@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