jenkins-bot has submitted this change and it was merged.

Change subject: Implement ManagerGroup::clear
......................................................................


Implement ManagerGroup::clear

Adds a ManagerGroup helper for ObjectManager::clear to simplify
clearing multiple managers.

Change-Id: I04feebe2e83f9e376fe5e5a13b404ca5605ec269
---
M includes/Data/ManagerGroup.php
A tests/phpunit/Data/ManagerGroupTest.php
2 files changed, 71 insertions(+), 11 deletions(-)

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



diff --git a/includes/Data/ManagerGroup.php b/includes/Data/ManagerGroup.php
index 4f45078..1c4f06b 100644
--- a/includes/Data/ManagerGroup.php
+++ b/includes/Data/ManagerGroup.php
@@ -16,9 +16,15 @@
        protected $container;
 
        /**
-        * @var string[] Map from ObjectManager alias to container key holding 
that object manager.
+        * @var string[] Map from FQCN or short name to key in container that 
holds
+        *  the relevant ObjectManager
         */
        protected $classMap;
+
+       /**
+        * @var string[] List of container keys that have been used
+        */
+       protected $used = array();
 
        /**
         * @param Container $container
@@ -31,6 +37,17 @@
        }
 
        /**
+        * Runs ObjectManager::clear on all managers that have been accessed 
since
+        * the last clear.
+        */
+       public function clear() {
+               foreach ( array_keys( $this->used ) as $key ) {
+                       $this->container[$key]->clear();
+               }
+               $this->used = array();
+       }
+
+       /**
         * @param string $className
         * @return ObjectManager
         * @throws DataModelException
@@ -39,17 +56,10 @@
                if ( !isset( $this->classMap[$className] ) ) {
                        throw new DataModelException( "Request for '$className' 
is not in classmap: " . implode( ', ', array_keys( $this->classMap ) ), 
'process-data' );
                }
+               $key = $this->classMap[$className];
+               $this->used[$key] = true;
 
-               return $this->container[$this->classMap[$className]];
-       }
-
-       /**
-        * Purge all cached data related to this object
-        *
-        * @param object $object
-        */
-       public function cachePurge( $object ) {
-               $this->getStorage( get_class( $object ) )->cachePurge( $object 
);
+               return $this->container[$key];
        }
 
        /**
diff --git a/tests/phpunit/Data/ManagerGroupTest.php 
b/tests/phpunit/Data/ManagerGroupTest.php
new file mode 100644
index 0000000..83873d8
--- /dev/null
+++ b/tests/phpunit/Data/ManagerGroupTest.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Flow\Tests\Data;
+
+use Flow\Container;
+use Flow\Data\ManagerGroup;
+
+/**
+ * @group Flow
+ */
+class ManagerGroupTest extends \MediaWikiTestCase {
+       protected function mockStorage() {
+               $container = new Container;
+               foreach ( range( 'A', 'D' ) as $letter ) {
+                       $container[$letter] = $this->getMockBuilder( 
'Flow\Data\ObjectManager' )
+                               ->disableOriginalConstructor()
+                               ->getMock();
+               }
+
+               $storage = new ManagerGroup( $container, array(
+                       'A' => 'A',
+                       'B' => 'B',
+                       'C' => 'C',
+                       'D' => 'D',
+               ) );
+
+               return array( $storage, $container );
+       }
+
+       public function testClearOnlyCallsRequestedManagers() {
+               list( $storage, $container ) = $this->mockStorage();
+               $container['A']->expects( $this->never() )->method( 'clear' );
+               $container['B']->expects( $this->once() )->method( 'clear' );
+               $container['C']->expects( $this->never() )->method( 'clear' );
+               $container['D']->expects( $this->never() )->method( 'clear' );
+
+               $storage->getStorage( 'B' );
+               $storage->clear();
+       }
+
+       public function testClearCallsNoManagersWhenUnused() {
+               list( $storage, $container ) = $this->mockStorage();
+               $container['A']->expects( $this->never() )->method( 'clear' );
+               $container['B']->expects( $this->never() )->method( 'clear' );
+               $container['C']->expects( $this->never() )->method( 'clear' );
+               $container['D']->expects( $this->never() )->method( 'clear' );
+
+               $storage->clear();
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I04feebe2e83f9e376fe5e5a13b404ca5605ec269
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to