AndyRussG has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/143009

Change subject: ConnectionType, getOrCreateCampaignEnsureUrlKey()
......................................................................

ConnectionType, getOrCreateCampaignEnsureUrlKey()

Modify domain and persistence classes to use ConnectionType to set
whether DB_MASTER or DB_SLAVE is used, instead of boolean
parameters, and add
ICampaignRepository::getOrCreateCampaignEnsureUrlKey()
to guarantee a campaign for a given URL key.

Change-Id: I3d315b24cd07a0ae00d265401fe4f49973042fca
---
M Campaigns.php
A includes/ConnectionType.php
M includes/domain/ICampaignRepository.php
M includes/domain/internal/CampaignRepository.php
M includes/persistence/IPersistenceManager.php
M includes/persistence/internal/db/DBPersistenceManager.php
M tests/phpunit/domain/internal/CampaignRepositoryTest.php
M tests/phpunit/persistence/internal/db/DBPersistenceManagerTest.php
8 files changed, 192 insertions(+), 159 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Campaigns 
refs/changes/09/143009/1

diff --git a/Campaigns.php b/Campaigns.php
index fc29480..862b4f2 100644
--- a/Campaigns.php
+++ b/Campaigns.php
@@ -34,6 +34,7 @@
 $wgAutoloadClasses['Campaigns\Setup\Setup'] = $dir . 
'/includes/setup/Setup.php';
 $wgAutoloadClasses['Campaigns\TypesafeEnum']  = $dir . 
'/includes/TypesafeEnum.php';
 $wgAutoloadClasses['Campaigns\ITypesafeEnum']  = $dir . 
'/includes/ITypesafeEnum.php';
+$wgAutoloadClasses['Campaigns\ConnectionType']  = $dir . 
'/includes/ConnectionType.php';
 
 $wgAutoloadClasses['Campaigns\Domain\ICampaign']  = $dir . 
'/includes/domain/ICampaign.php';
 $wgAutoloadClasses['Campaigns\Domain\IParticipation']  = $dir . 
'/includes/domain/IParticipation.php';
diff --git a/includes/ConnectionType.php b/includes/ConnectionType.php
new file mode 100644
index 0000000..0d147a7
--- /dev/null
+++ b/includes/ConnectionType.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Campaigns;
+
+/**
+ * A connection type for a persistence store. When using DB persistence,
+ * this maps to DB_MASTER and DB_SLAVE.
+ */
+final class ConnectionType extends TypesafeEnum {
+
+       static $MASTER; /* For fully up-to-date data */
+       static $SLAVE;  /* For data that may be laggy */
+}
+
+ConnectionType::setUp();
\ No newline at end of file
diff --git a/includes/domain/ICampaignRepository.php 
b/includes/domain/ICampaignRepository.php
index 991b780..0541d00 100644
--- a/includes/domain/ICampaignRepository.php
+++ b/includes/domain/ICampaignRepository.php
@@ -2,6 +2,8 @@
 
 namespace Campaigns\Domain;
 
+use Campaigns\ConnectionType;
+
 interface ICampaignRepository {
 
        /**
@@ -55,31 +57,36 @@
         * Get a campaign by ID.
         *
         * @param int $id
-        * @param boolean $useMaster Set to true to query the master persistence
-        *   store, which should be up-to-date with all transactions. (In the DB
-        *   implementation, this forces the query to use DB_MASTER.)
+        * @param ConnectionType $connectionType Set to MASTER for data that is
+        *   guaranteed to be the latest. Default is SLAVE, which may provide
+        *   slightly laggy data. (In the DB implementation, these map to
+        *   DB_MASTER and DB_SLAVE.)
         */
-       public function getCampaignById( $id, $useMaster=false );
+       public function getCampaignById( $id, ConnectionType 
$connectionType=null );
 
        /**
         * Get a campaign by URL key.
         *
         * @param string $urlKey
-        * @param boolean $useMaster Set to true to query the master persistence
-        *   store, which should be up-to-date with all transactions. (In the DB
-        *   implementation, this forces the query to use DB_MASTER.)
+        * @param ConnectionType $connectionType Set to MASTER for data that is
+        *   guaranteed to be the latest. Default is SLAVE, which may provide
+        *   slightly laggy data. (In the DB implementation, these map to
+        *   DB_MASTER and DB_SLAVE.)
         */
-       public function getCampaignByUrlKey( $urlKey, $useMaster=false );
+       public function getCampaignByUrlKey( $urlKey,
+               ConnectionType $connectionType=null );
 
        /**
         * Get a campaign by name.
         *
         * @param string $name
-        * @param boolean $useMaster Set to true to query the master persistence
-        *   store, which should be up-to-date with all transactions. (In the DB
-        *   implementation, this forces the query to use DB_MASTER.)
+        * @param ConnectionType $connectionType Set to MASTER for data that is
+        *   guaranteed to be the latest. Default is SLAVE, which may provide
+        *   slightly laggy data. (In the DB implementation, these map to
+        *   DB_MASTER and DB_SLAVE.)
         */
-       public function getCampaignByName( $name, $useMaster=false );
+       public function getCampaignByName( $name,
+               ConnectionType $connectionType=null );
 
        /**
         * Get a list of campaigns. Include only campaigns whose name starts
@@ -112,6 +119,26 @@
                &$continueKey=null );
 
        /**
+        * Get a campaign with the provided URL key over 
ConnectionType::$MASTER.
+        * If one does not exist, create one with a name similar to 
$suggestedName.
+        * If a campaign is created, it will be automatically persisted; it is 
not
+        * necessary to call ITranscationManager::flush().
+        *
+        * The purpose of this method is to guarantee a Campaign with this URL 
key.
+        *
+        * @param string $urlKey
+        * @param string $suggestedName
+        * @param int $maxAttempts The maximum number of times to attempt to 
create
+        *   a campaign with a name similar to $suggestedName. It is unlikely 
that
+        *   several attempts will ever be needed.
+        *
+        * @throws MWException In the very unlikely event that it was not 
possible
+        *   to ensure a campaign with this URL key.
+        */
+       public function getOrCreateCampaignEnsureUrlKey( $urlKey, 
$suggestedName,
+               $maxAttempts );
+
+       /**
         * The maximum number of campaigns that may be retrieved at once using
         * getCampaigns(). If that method is called with a higher $fetchLimit,
         * an exception will be thrown.
diff --git a/includes/domain/internal/CampaignRepository.php 
b/includes/domain/internal/CampaignRepository.php
index 195cd48..5d60e3a 100644
--- a/includes/domain/internal/CampaignRepository.php
+++ b/includes/domain/internal/CampaignRepository.php
@@ -3,6 +3,7 @@
 namespace Campaigns\Domain\Internal;
 
 use MWException;
+use Campaigns\ConnectionType;
 use Campaigns\Domain\ICampaign;
 use Campaigns\Domain\ICampaignRepository;
 use Campaigns\Domain\CampaignNameNotUniqueException;
@@ -110,14 +111,17 @@
        /**
         * @see ICampaignRepository::getCampaignById()
         */
-       public function getCampaignById( $id, $useMaster=false ) {
-               return $this->pm->getOneById( 'ICampaign', $id, $useMaster );
+       public function getCampaignById( $id,
+               ConnectionType $connectionType=null ) {
+
+               return $this->pm->getOneById( 'ICampaign', $id, $connectionType 
);
        }
 
        /**
         * @see ICampaignRepository::getCampaignByUrlKey()
         */
-       public function getCampaignByUrlKey( $urlKey, $useMaster=false ) {
+       public function getCampaignByUrlKey( $urlKey,
+               ConnectionType $connectionType=null ) {
 
                $condition = new Condition(
                        CampaignField::$URL_KEY,
@@ -125,13 +129,14 @@
                        $urlKey
                );
 
-               return $this->pm->getOne( 'ICampaign', $condition, $useMaster );
+               return $this->pm->getOne( 'ICampaign', $condition, 
$connectionType );
        }
 
        /**
         * @see ICampaignRepository::getCampaignByName()
         */
-       public function getCampaignByName( $name, $useMaster=false ) {
+       public function getCampaignByName( $name,
+               ConnectionType $connectionType=null ) {
 
                $condition = new Condition(
                        CampaignField::$NAME,
@@ -139,7 +144,7 @@
                        $name
                );
 
-               return $this->pm->getOne( 'ICampaign', $condition, $useMaster );
+               return $this->pm->getOne( 'ICampaign', $condition, 
$connectionType );
        }
 
        /**
@@ -168,6 +173,69 @@
        }
 
        /**
+        * @see ICampaignRepository::getOrCreateCampaignEnsureUrlKey()
+        */
+       public function getOrCreateCampaignEnsureUrlKey( $urlKey, 
$suggestedName,
+               $maxAttempts ) {
+
+               $campaign =
+                       $this->getCampaignByUrlKey( $urlKey, 
ConnectionType::$MASTER );
+
+               if ( is_null( $campaign ) ) {
+
+                       $nameSuffix = '';
+                       $attempts = 0;
+
+                       // Go through this loop until we successfully create a 
campaign
+                       // or hit a brick wall.
+                       do {
+
+                               $name = $suggestedName . $nameSuffix;
+                               $attempts++;
+                               $campaign = $this->createCampaign( $urlKey, 
$name );
+
+                               try {
+
+                                       // This will throw an exception on 
duplicate name. We are
+                                       // already sure that our $urlKey is 
unique.
+                                       // TODO Double-check details of locking 
to be sure this is
+                                       // true.
+                                       $this->pm->flush();
+
+                                       // If we got here, the campaign was 
correctly saved and we
+                                       // can return it.
+                                       break;
+
+                               } catch ( CampaignNameNotUniqueException $nameE 
) {
+
+                                       // Hmmm, our name was not unique. If 
we've tried too many
+                                       // times, throw an exception.
+                                       if ( $attempts >= $maxAttempts ) {
+
+                                               throw new MWException( 'Too 
many attempts to find a ' .
+                                                       'unique campaign name 
for URL key ' . $urlKey );
+                                       }
+
+                                       // If we haven't tried enough yet, try 
with another name.
+                                       $nameSuffix = uniqid( '-', true );
+                                       continue;
+                               }
+
+                               // We should have met a break or continue by 
now, so if we're
+                               // here there's an unexpected problem.
+                               throw new MWException( 'Unable to get a 
campaign for URL key ' .
+                                       $urlKey . '.' );
+
+                       // In theory this check is redundant and we could just 
say
+                       // while(true). But let's leave the check in to guard 
against a
+                       // mistake in the above code causing an infinite loop. 
:)
+                       } while ( $attempts < $maxAttempts );
+               }
+
+               return $campaign;
+       }
+
+       /**
         * @see ICampaignRepository::getMaxFetchLimit()
         */
        public function getMaxFetchLimit() {
diff --git a/includes/persistence/IPersistenceManager.php 
b/includes/persistence/IPersistenceManager.php
index b7ee3cd..e49b811 100644
--- a/includes/persistence/IPersistenceManager.php
+++ b/includes/persistence/IPersistenceManager.php
@@ -1,6 +1,7 @@
 <?php
 namespace Campaigns\Persistence;
 
+use Campaigns\ConnectionType;
 use Campaigns\Persistence\Order;
 use Campaigns\Persistence\IField;
 
@@ -117,13 +118,15 @@
         *
         * @param Condition|array $conditions A single Condition or an array of 
them
         *
-        * @param boolean $useMaster Set to true to query the master persistence
-        *   store, which should be up-to-date with all transactions. (In the DB
-        *   implementation, this forces the query to use DB_MASTER.)
+        * @param ConnectionType $connectionType Set to MASTER for data that is
+        *   guaranteed to be the latest. Default is SLAVE, which may provide
+        *   slightly laggy data. (In the DB implementation, these map to
+        *   DB_MASTER and DB_SLAVE.)
         *
         * @return mixed $obj
         */
-       public function getOne( $type, $conditions, $useMaster=false );
+       public function getOne( $type, $conditions,
+                       ConnectionType $connectionType=null );
 
        /**
         * Get a single entity of this $type with this $id.
@@ -132,13 +135,15 @@
         *
         * @param mixed $id
         *
-        * @param boolean $useMaster Set to true to query the master persistence
-        *   store, which should be up-to-date with all transactions. (In the DB
-        *   implementation, this forces the query to use DB_MASTER.)
+        * @param ConnectionType $connectionType Set to MASTER for data that is
+        *   guaranteed to be the latest. Default is SLAVE, which may provide
+        *   slightly laggy data. (In the DB implementation, these map to
+        *   DB_MASTER and DB_SLAVE.)
         *
         * @return mixed $obj
         */
-       public function getOneById( $type, $id, $useMaster=false );
+       public function getOneById( $type, $id,
+               ConnectionType $connectionType=null );
 
        /**
         * Count the entities of this $type, identified by $conditions. If
@@ -148,13 +153,9 @@
         *
         * @param array $conditions An array of Conditions
         *
-        * @param string $useMaster Set to true to query the master persistence
-        *   store, which should be up-to-date with all transactions. (In the DB
-        *   implementation, this forces the query to use DB_MASTER.)
-        *
         * @return int
         */
-       public function count( $type, $conditions=null, $useMaster=false);
+       public function count( $type, $conditions=null );
 
        /**
         * Get an array of entities of this $type, identified by $conditions,
diff --git a/includes/persistence/internal/db/DBPersistenceManager.php 
b/includes/persistence/internal/db/DBPersistenceManager.php
index 04ec792..a12f99a 100644
--- a/includes/persistence/internal/db/DBPersistenceManager.php
+++ b/includes/persistence/internal/db/DBPersistenceManager.php
@@ -6,6 +6,7 @@
 use MWException;
 use ApiBase;
 use Campaigns\TypesafeEnum;
+use Campaigns\ConnectionType;
 use Campaigns\Persistence\IPersistenceManager;
 use Campaigns\Persistence\Condition;
 use Campaigns\Persistence\Operator;
@@ -125,26 +126,27 @@
        /**
         * @see IPersistenceManager::existsWithConditions()
         */
-       public function existsWithConditions( $type, $conditions,
-                       $useMaster=false) {
+       public function existsWithConditions( $type, $conditions ) {
 
-               $count = $this->count( $type, $conditions, $useMaster );
+               $count = $this->count( $type, $conditions );
                return $count > 0;
        }
 
        /**
         * @see IPersistenceManager::getOne()
         */
-       public function getOne( $type, $conditions, $useMaster=false ) {
+       public function getOne( $type, $conditions,
+               ConnectionType $connectionType=null ) {
 
-               $db = $this->getDb( $useMaster );
+               $db = $this->getDb( $connectionType );
                return $this->getOneInternal( $type, $conditions, $db );
        }
 
        /**
         * @see IPersistenceManager::getOneById()
         */
-       public function getOneById( $type, $id, $useMaster=false ) {
+       public function getOneById( $type, $id,
+               ConnectionType $connectionType=null ) {
 
                $condition = new Condition(
                        $this->mapper->getIdFieldForType( $type ),
@@ -152,15 +154,15 @@
                        $id
                );
 
-               return $this->getOne( $type, $condition, $useMaster );
+               return $this->getOne( $type, $condition, $connectionType );
        }
 
        /**
         * @see IPersistenceManager::count()
         */
-       public function count( $type, $conditions=null, $useMaster=false) {
+       public function count( $type, $conditions=null ) {
 
-               $db = $this->getDb( $useMaster );
+               $db = $this->getDb();
                $tableName = $this->mapper->getTableNameForType( $type );
 
                if ( is_null( $conditions ) ) {
@@ -202,7 +204,7 @@
                        throw new MWException( '$orderByField must be unique or 
an id.' );
                }
 
-               $dbr = $this->getDb( false );
+               $dbr = $this->getDb();
                $tableName = $this->mapper->getTableNameForType( $type );
                $orderByCol = $this->mapper->getDbColumn( $orderByField );
 
@@ -310,7 +312,7 @@
         * @see IPersistenceManager::getAnyStringForLikeOperator()
         */
        public function getAnyStringForLikeOperator() {
-               return $this->getDb( false )->anyString();
+               return $this->getDb()->anyString();
        }
 
        /**
@@ -327,7 +329,7 @@
                // throw an exception if there's a problem.
                $this->mapper->verifyRequiredFields( $obj );
 
-               $dbw = $this->getDb( true );
+               $dbw = $this->getDb( ConnectionType::$MASTER );
 
                // Get the table name and prepare the columns
                $tableName = $this->mapper->getTableNameForObj( $obj );
@@ -508,7 +510,7 @@
                // throw an exception if there's a problem.
                $this->mapper->verifyRequiredFields( $obj );
 
-               $dbw = $this->getDb( true );
+               $dbw = $this->getDb( ConnectionType::$MASTER );
 
                // Get the table name, prepare columns and values for insert
                $tableName = $this->mapper->getTableNameForObj( $obj );
@@ -549,7 +551,7 @@
         */
        protected function delete( DeleteOperation $op ) {
 
-               $dbw = $this->getDb( true );
+               $dbw = $this->getDb( ConnectionType::$MASTER );
 
                $condForQuery = $this->prepareConditions( $op->conditions, $dbw 
);
 
@@ -564,15 +566,22 @@
        /**
         * Get a database abstraction object (a DatabaseBase).
         *
-        * @param boolean $writeDb Set to true for DB_MASTER, false for DB_SLAVE
+        * @param ConnectionType $connectionType Set to MASTER for DB_MASTER, 
SLAVE
+        *   for DB_SLAVE
+        *
         * @return DatabaseBase
         */
-       protected function getDb( $writeDb ) {
-               if ( $writeDb ) {
-                       return wfGetDB( DB_MASTER );
-               }
+       protected function getDb( ConnectionType $connectionType=null ) {
 
-               return wfGetDB( DB_SLAVE );
+               switch ( $connectionType ) {
+
+                       case ConnectionType::$MASTER:
+                               return wfGetDB( DB_MASTER );
+
+                       case ConnectionType::$SLAVE: // Fall-through is 
intentional
+                       default:
+                               return wfGetDB( DB_SLAVE );
+               }
        }
 
        /**
diff --git a/tests/phpunit/domain/internal/CampaignRepositoryTest.php 
b/tests/phpunit/domain/internal/CampaignRepositoryTest.php
index ade81a5..cd76e3b 100644
--- a/tests/phpunit/domain/internal/CampaignRepositoryTest.php
+++ b/tests/phpunit/domain/internal/CampaignRepositoryTest.php
@@ -3,6 +3,7 @@
 namespace Campaigns\PHPUnit\Domain\Internal;
 
 use MediaWikiTestCase;
+use Campaigns\ConnectionType;
 use Campaigns\PHPUnit\TestHelper;
 use Campaigns\Domain\ICampaign;
 use Campaigns\Domain\Internal\CampaignRepository;
@@ -218,11 +219,11 @@
                        ->with(
                                $this->equalTo( 'ICampaign' ),
                                $this->equalTo( 7 ),
-                               $this->equalTo( true ) )
+                               $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $repoAndM->c ) );
 
                $this->assertSame( $repoAndM->c,
-                       $repoAndM->cRepo->getCampaignById( 7, true ) );
+                       $repoAndM->cRepo->getCampaignById( 7, 
ConnectionType::$MASTER ) );
        }
 
        public function testGetCampaignByUrlKey() {
@@ -235,11 +236,12 @@
                        ->with(
                                $this->equalTo( 'ICampaign' ),
                                $this->captureArg( $condition ),
-                               $this->equalTo( true ) )
+                               $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $repoAndM->c ) );
 
                $this->assertSame( $repoAndM->c,
-                       $repoAndM->cRepo->getCampaignByUrlKey( 'urlKey', true ) 
);
+                       $repoAndM->cRepo->getCampaignByUrlKey(
+                       'urlKey', ConnectionType::$MASTER ) );
 
                // Test the condition
                $this->assertCondition(
@@ -260,11 +262,12 @@
                        ->with(
                                $this->equalTo( 'ICampaign' ),
                                $this->captureArg( $condition ),
-                               $this->equalTo( true ) )
+                               $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $repoAndM->c ) );
 
                $this->assertSame( $repoAndM->c,
-                       $repoAndM->cRepo->getCampaignByName( 'name', true ) );
+                       $repoAndM->cRepo->getCampaignByName(
+                       'name', ConnectionType::$MASTER ) );
 
                // Test the condition
                $this->assertCondition(
@@ -350,6 +353,8 @@
                        $repoAndM->cRepo->getMaxFetchLimit() );
        }
 
+       // TODO: test getOrCreateCampaignEnsureUrlKey()
+
        /**
         * Create and set up a fresh CampaignRepository and some mocks, and 
return
         * them wrapped in a stdClass.
diff --git a/tests/phpunit/persistence/internal/db/DBPersistenceManagerTest.php 
b/tests/phpunit/persistence/internal/db/DBPersistenceManagerTest.php
index 27be520..c94e6eb 100644
--- a/tests/phpunit/persistence/internal/db/DBPersistenceManagerTest.php
+++ b/tests/phpunit/persistence/internal/db/DBPersistenceManagerTest.php
@@ -3,6 +3,7 @@
 namespace Campaigns\PHPUnit\Persistence\Internal\Db;
 
 use MediaWikiTestCase;
+use Campaigns\ConnectionType;
 use Campaigns\PHPUnit\TestHelper;
 use Campaigns\TypesafeEnum;
 use Campaigns\Persistence\IField;
@@ -87,7 +88,7 @@
                // This is the call that we're testing
                $pmAndM->pm->expects( $this->once() )
                        ->method( 'getDb' )
-                       ->with( $this->equalTo( true ) ) // requesting master
+                       ->with( $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $this->db ) );
 
                // Queue and perform the save
@@ -562,7 +563,7 @@
                // This is the call that we're testing
                $pmAndM->pm->expects( $this->once() )
                        ->method( 'getDb' )
-                       ->with( $this->equalTo( true ) ) // requesting master
+                       ->with( $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $this->db ) );
 
                // Queue and perform the update-or-create
@@ -697,7 +698,7 @@
                // This is the call that we're testing
                $pmAndM->pm->expects( $this->once() )
                        ->method( 'getDb' )
-                       ->with( $this->equalTo( true ) ) // requesting master
+                       ->with( $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $this->db ) );
 
                // Make condition and queue and perform the delete
@@ -866,52 +867,6 @@
                        $pmAndM->pm->existsWithConditions( 'MockEntity', 
$condition ) );
        }
 
-       public function testExistsWithConditionsGetsMasterDbWhenRequested() {
-
-               $val = 'ExistsWithConditionsGetsMasterDbWhenRequested';
-               $pmAndM = $this->getPersistenceManagerAndMocks();
-
-               // Set up everything _except_ the call to getDb
-               $this->prepareMocks( null, $pmAndM, null, 'getDb' );
-
-               // This is the call that we're testing
-               $pmAndM->pm->expects( $this->once() )
-                       ->method( 'getDb' )
-                       ->with( $this->equalTo( true ) ) // requesting master
-                       ->will( $this->returnValue( $this->db ) );
-
-               $condition = new Condition(
-                       $pmAndM->field1,
-                       Operator::$EQUAL,
-                       $val
-               );
-
-               $pmAndM->pm->existsWithConditions( 'MockEntity', $condition, 
true );
-       }
-
-       public function testExistsWithConditionsGetsSlaveDbWhenRequested() {
-
-               $val = 'ExistsWithConditionsGetsSlaveDbWhenRequested';
-               $pmAndM = $this->getPersistenceManagerAndMocks();
-
-               // Set up everything _except_ the call to getDb
-               $this->prepareMocks( null, $pmAndM, null, 'getDb' );
-
-               // This is the call that we're testing
-               $pmAndM->pm->expects( $this->once() )
-                       ->method( 'getDb' )
-                       ->with( $this->equalTo( false ) ) // not requesting 
master
-                       ->will( $this->returnValue( $this->db ) );
-
-               $condition = new Condition(
-                       $pmAndM->field1,
-                       Operator::$EQUAL,
-                       $val
-               );
-
-               $pmAndM->pm->existsWithConditions( 'MockEntity', $condition );
-       }
-
        public function testGetOneGetsMasterDbWhenRequested() {
 
                $val = 'GetOneGetsMasterDbWhenRequested';
@@ -924,7 +879,7 @@
                // This is the call that we're testing
                $pmAndM->pm->expects( $this->once() )
                        ->method( 'getDb' )
-                       ->with( $this->equalTo( true ) ) // requesting master
+                       ->with( $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $this->db ) );
 
                $condition = new Condition(
@@ -933,7 +888,7 @@
                        $val
                );
 
-               $pmAndM->pm->getOne( 'MockEntity', $condition, true );
+               $pmAndM->pm->getOne( 'MockEntity', $condition, 
ConnectionType::$MASTER );
        }
 
        public function testGetOneGetsSlaveDbWhenRequested() {
@@ -1056,7 +1011,7 @@
                        ->with( $this->equalTo( 'MockEntity' ) )
                        ->will( $this->returnValue( $pmAndM->idField ) );
 
-               $pmAndM->pm->getOneById( 'MockEntity', $r->id, true );
+               $pmAndM->pm->getOneById( 'MockEntity', $r->id, 
ConnectionType::$MASTER );
        }
 
        public function testGetOneByIdGetsMasterDbWhenRequested() {
@@ -1071,10 +1026,10 @@
                // This is the call that we're testing
                $pmAndM->pm->expects( $this->once() )
                        ->method( 'getDb' )
-                       ->with( $this->equalTo( true ) ) // requesting master
+                       ->with( $this->equalTo( ConnectionType::$MASTER ) )
                        ->will( $this->returnValue( $this->db ) );
 
-               $pmAndM->pm->getOneById( 'MockEntity', $r->id, true );
+               $pmAndM->pm->getOneById( 'MockEntity', $r->id, 
ConnectionType::$MASTER );
        }
 
        public function testGetOneByIdGetsSlaveDbWhenRequested() {
@@ -1114,54 +1069,6 @@
 
                // Send in very unlikely ID
                $this->assertNull( $pmAndM->pm->getOneById( 'MockEntity', 
241231 ) );
-       }
-
-       public function testCountGetsMasterDbWhenRequested() {
-
-               $val = 'CountGetsMasterDbWhenRequested';
-               $this->insertRow( $val );
-               $pmAndM = $this->getPersistenceManagerAndMocks();
-
-               // Set up everything _except_ the call to getDb
-               $this->prepareMocks( null, $pmAndM, null, 'getDb' );
-
-               // This is the call that we're testing
-               $pmAndM->pm->expects( $this->once() )
-                       ->method( 'getDb' )
-                       ->with( $this->equalTo( true ) ) // requesting master
-                       ->will( $this->returnValue( $this->db ) );
-
-               $condition = new Condition(
-                       $pmAndM->field1,
-                       Operator::$EQUAL,
-                       $val
-               );
-
-               $pmAndM->pm->count( 'MockEntity', $condition, true );
-       }
-
-       public function testCountGetsSlaveDbWhenRequested() {
-
-               $val = 'CountGetsSlaveDbWhenRequested';
-               $this->insertRow( $val );
-               $pmAndM = $this->getPersistenceManagerAndMocks();
-
-               // Set up everything _except_ the call to getDb
-               $this->prepareMocks( null, $pmAndM, null, 'getDb' );
-
-               // This is the call that we're testing
-               $pmAndM->pm->expects( $this->once() )
-                       ->method( 'getDb' )
-                       ->with( $this->equalTo( false ) ) // not requesting 
master
-                       ->will( $this->returnValue( $this->db ) );
-
-               $condition = new Condition(
-                       $pmAndM->field1,
-                       Operator::$EQUAL,
-                       $val
-               );
-
-               $pmAndM->pm->count( 'MockEntity', $condition );
        }
 
        public function testCountGetsTableNameForType() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d315b24cd07a0ae00d265401fe4f49973042fca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Campaigns
Gerrit-Branch: wip/editorcampaigns
Gerrit-Owner: AndyRussG <andrew.green...@gmail.com>

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

Reply via email to