EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/167638
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, 81 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/38/167638/1
diff --git a/includes/Data/ManagerGroup.php b/includes/Data/ManagerGroup.php
index 487fd67..5b2aee2 100644
--- a/includes/Data/ManagerGroup.php
+++ b/includes/Data/ManagerGroup.php
@@ -10,9 +10,37 @@
* ObjectManagers more conveniently.
*/
class ManagerGroup {
+
+ /**
+ * @var Container
+ */
+ protected $container;
+
+ /**
+ * @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();
+
public function __construct( Container $container, array $classMap ) {
$this->container = $container;
$this->classMap = $classMap;
+ }
+
+ /**
+ * 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();
}
/**
@@ -24,17 +52,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];
}
public function put( $object, array $metadata ) {
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: newchange
Gerrit-Change-Id: I04feebe2e83f9e376fe5e5a13b404ca5605ec269
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits