jenkins-bot has submitted this change and it was merged.
Change subject: StoreUpdater to implement ContextAware
......................................................................
StoreUpdater to implement ContextAware
The context is derived from UpdateObserver together with the object graph
which is now generated from the context rather than assuming a valid
object contract(see line 127).
Definition of the PropertyChangeNotifier class has been moved into the DIC
for proper dependency handling.
Change-Id: I98b95b00f57e123923441c447f7b55e71f55f0a2
---
M includes/StoreUpdater.php
M includes/UpdateObserver.php
M includes/dic/SharedDependencyContainer.php
M tests/phpunit/includes/StoreUpdaterTest.php
M tests/phpunit/includes/UpdateObserverTest.php
M tests/phpunit/includes/dic/SharedDependencyContainerTest.php
M tests/phpunit/includes/jobs/UpdateJobTest.php
7 files changed, 96 insertions(+), 73 deletions(-)
Approvals:
Mwjames: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/StoreUpdater.php b/includes/StoreUpdater.php
index de2fd49..3eed1f7 100644
--- a/includes/StoreUpdater.php
+++ b/includes/StoreUpdater.php
@@ -7,33 +7,40 @@
use User;
/**
- * Initiates update of the Store
+ * Initiates an update of the Store
*
+ * @licence GNU GPL v2+
* @since 1.9
*
- * @license GNU GPL v2+
* @author mwjames
*/
-class StoreUpdater {
-
- /** @var Store */
- protected $store;
+class StoreUpdater implements ContextAware {
/** @var SemanticData */
protected $semanticData;
- /** @var Settings */
- protected $settings;
+ /** @var ContextResource */
+ protected $context;
/** @var $updateJobs */
protected $updateJobs = null;
- public function __construct( Store $store, SemanticData $semanticData,
Settings $settings ) {
- $this->store = $store;
+ public function __construct( SemanticData $semanticData,
ContextResource $context ) {
$this->semanticData = $semanticData;
- $this->settings = $settings;
+ $this->context = $context;
- $this->setUpdateStatus( $settings->get( 'smwgEnableUpdateJobs'
) );
+ $this->setUpdateStatus( $this->context->getSettings()->get(
'smwgEnableUpdateJobs' ) );
+ }
+
+ /**
+ * @see ContextAware::withContext
+ *
+ * @since 1.9
+ *
+ * @return ContextResource
+ */
+ public function withContext() {
+ return $this->context;
}
/**
@@ -102,7 +109,10 @@
$user = User::newFromId( $revision->getUser() );
- $propertyAnnotator = new BasePropertyAnnotator(
$this->semanticData, $this->settings );
+ $propertyAnnotator =
$this->withContext()->getDependencyBuilder()->newObject(
'BasePropertyAnnotator', array(
+ 'SemanticData' => $this->semanticData
+ ) );
+
$propertyAnnotator->addSpecialProperties( $wikiPage,
$revision, $user );
} else {
@@ -113,15 +123,19 @@
// Comparison must happen *before* the storage update;
// even finding uses of a property fails after its type changed.
if ( $this->updateJobs ) {
- $changeNotifier = new PropertyChangeNotifier(
$this->store, $this->semanticData, $this->settings );
- $changeNotifier->setObservableDispatcher( new
ObservableSubjectDispatcher( new UpdateObserver() ) )->detectChanges();
+
+ $changeNotifier =
$this->withContext()->getDependencyBuilder()->newObject(
'PropertyChangeNotifier', array(
+ 'SemanticData' => $this->semanticData
+ ) );
+
+ $changeNotifier->detectChanges();
}
// Actually store semantic data, or at least clear it if needed
if ( $processSemantics ) {
- $this->store->updateData( $this->semanticData );
+ $this->withContext()->getStore()->updateData(
$this->semanticData );
} else {
- $this->store->clearData(
$this->semanticData->getSubject() );
+ $this->withContext()->getStore()->clearData(
$this->semanticData->getSubject() );
}
Profiler::Out( __METHOD__, true );
@@ -138,7 +152,7 @@
* @return boolean
*/
protected function isValid( Title $title ) {
- return NamespaceExaminer::newFromArray( $this->settings->get(
'smwgNamespacesWithSemanticLinks' ) )->isSemanticEnabled(
$title->getNamespace() );
+ return $this->withContext()->getDependencyBuilder()->newObject(
'NamespaceExaminer' )->isSemanticEnabled( $title->getNamespace() );
}
}
diff --git a/includes/UpdateObserver.php b/includes/UpdateObserver.php
index 2a50f8b..c2519f6 100644
--- a/includes/UpdateObserver.php
+++ b/includes/UpdateObserver.php
@@ -64,19 +64,14 @@
*
* @since 1.9
*
- * @param ParserData $subject
+ * @param ParserData $parserData
*
* @return true
*/
- public function runStoreUpdater( ParserData $subject ) {
+ public function runStoreUpdater( ParserData $parserData ) {
- $updater = new StoreUpdater(
- $this->withContext()->getStore(),
- $subject->getData(),
- $this->withContext()->getSettings()
- );
-
- $updater->setUpdateStatus( $subject->getUpdateStatus()
)->doUpdate();
+ $updater = new StoreUpdater( $parserData->getData(),
$this->withContext() );
+ $updater->setUpdateStatus( $parserData->getUpdateStatus()
)->doUpdate();
return true;
}
diff --git a/includes/dic/SharedDependencyContainer.php
b/includes/dic/SharedDependencyContainer.php
index 55fd7b8..e65317c 100644
--- a/includes/dic/SharedDependencyContainer.php
+++ b/includes/dic/SharedDependencyContainer.php
@@ -231,6 +231,26 @@
*/
'BaseContext' => function ( DependencyBuilder $builder
) {
return new BaseContext( $builder );
+ },
+
+ /**
+ * PropertyChangeNotifier object definition
+ *
+ * @since 1.9
+ *
+ * @return PropertyChangeNotifier
+ */
+ 'PropertyChangeNotifier' => function (
DependencyBuilder $builder ) {
+
+ $instance = new PropertyChangeNotifier(
+ $builder->newObject( 'Store' ),
+ $builder->getArgument( 'SemanticData' ),
+ $builder->newObject( 'Settings' )
+ );
+
+ $instance->setObservableDispatcher(
$builder->newObject( 'ObservableUpdateDispatcher' ) );
+
+ return $instance;
}
);
diff --git a/tests/phpunit/includes/StoreUpdaterTest.php
b/tests/phpunit/includes/StoreUpdaterTest.php
index 8f77ea0..db69fad 100644
--- a/tests/phpunit/includes/StoreUpdaterTest.php
+++ b/tests/phpunit/includes/StoreUpdaterTest.php
@@ -5,25 +5,25 @@
use SMW\StoreFactory;
use SMW\StoreUpdater;
use SMW\SemanticData;
+use SMW\BaseContext;
use SMW\DIWikiPage;
+
use Title;
/**
* @covers \SMW\StoreUpdater
*
- * @ingroup Test
+ * @licence GNU GPL v2+
+ * @since 1.9
*
* @group SMW
* @group SMWExtension
*
* @author mwjames
- * @license GNU GPL v2+
*/
class StoreUpdaterTest extends SemanticMediaWikiTestCase {
/**
- * Returns the name of the class to be tested
- *
* @return string
*/
public function getClass() {
@@ -31,17 +31,11 @@
}
/**
- * Helper method that returns a StoreUpdater object
- *
* @since 1.9
- *
- * @param $store
- * @param $data
- * @param $settings
*
* @return StoreUpdater
*/
- private function newInstance( $store = null, $data = null, $settings =
null ) {
+ private function newInstance( $store = null, $data = null ) {
if ( $store === null ) {
$store = $this->newMockBuilder()->newObject( 'Store' );
@@ -51,19 +45,21 @@
$data = $this->newMockBuilder()->newObject(
'SemanticData' );
}
- if ( $settings === null ) {
- $settings = $this->getSettings( array(
- 'smwgEnableUpdateJobs' => false,
- 'smwgNamespacesWithSemanticLinks' => array(
NS_MAIN => true )
- ) );
- }
+ $settings = $this->newSettings( array(
+ 'smwgEnableUpdateJobs' => false,
+ 'smwgNamespacesWithSemanticLinks' => array( NS_MAIN =>
true )
+ ) );
- return new StoreUpdater( $store, $data, $settings );
+ $context = new BaseContext();
+
+ $container = $context->getDependencyBuilder()->getContainer();
+ $container->registerObject( 'Store', $store );
+ $container->registerObject( 'Settings', $settings );
+
+ return new StoreUpdater( $data, $context );
}
/**
- * @test StoreUpdater::__construct
- *
* @since 1.9
*/
public function testConstructor() {
@@ -71,8 +67,6 @@
}
/**
- * @test StoreUpdater::doUpdate
- *
* @since 1.9
*/
public function testDoUpdate() {
@@ -88,13 +82,9 @@
}
/**
- * @test StoreUpdater::doUpdate
* @dataProvider titleDataProvider
*
* @since 1.9
- *
- * @param $setup
- * @param $expected
*/
public function testDoUpdateOnMock( $setup, $expected ) {
diff --git a/tests/phpunit/includes/UpdateObserverTest.php
b/tests/phpunit/includes/UpdateObserverTest.php
index 781fcfa..4d2488f 100644
--- a/tests/phpunit/includes/UpdateObserverTest.php
+++ b/tests/phpunit/includes/UpdateObserverTest.php
@@ -57,6 +57,13 @@
}
/**
+ * @since 1.9
+ */
+ public function testDefaultContext() {
+ $this->assertInstanceOf( '\SMW\ContextResource',
$this->newInstance()->withContext() );
+ }
+
+ /**
* @dataProvider updateDispatcherDataProvider
*
* @since 1.9
diff --git a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
index 6d177b6..5a40a06 100644
--- a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
+++ b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
@@ -9,31 +9,21 @@
use SMW\DependencyContainer;
/**
- * Tests for the SharedDependencyContainer
- *
- * @file
- *
- * @license GNU GPL v2+
- * @since 1.9
- *
- * @author mwjames
- */
-
-/**
* @covers \SMW\SharedDependencyContainer
* @covers \SMW\SimpleDependencyBuilder
* @covers \SMW\BaseDependencyContainer
*
- * @ingroup Test
+ * @licence GNU GPL v2+
+ * @since 1.9
*
* @group SMW
* @group SMWExtension
+ *
+ * @author mwjames
*/
class SharedDependencyContainerTest extends SemanticMediaWikiTestCase {
/**
- * Returns the name of the class to be tested
- *
* @return string|false
*/
public function getClass() {
@@ -41,11 +31,7 @@
}
/**
- * Helper method that returns a SimpleDependencyBuilder object
- *
* @since 1.9
- *
- * @param $data
*
* @return SimpleDependencyBuilder
*/
@@ -54,8 +40,6 @@
}
/**
- * @test SimpleDependencyBuilder::newObject
- * @test SimpleDependencyBuilder::addArgument
* @dataProvider objectDataProvider
*
* @since 1.9
@@ -173,6 +157,12 @@
)
);
+ $provider[] = array( 'PropertyChangeNotifier', array(
'\SMW\PropertyChangeNotifier' => array(
+ 'SemanticData' =>
$this->newMockBuilder()->newObject( 'SemanticData' )
+ )
+ )
+ );
+
$provider[] = array( 'ParserData', array( '\SMW\ParserData' =>
array(
'Title' =>
$this->newMockBuilder()->newObject( 'Title' ),
'ParserOutput' =>
$this->newMockBuilder()->newObject( 'ParserOutput' )
diff --git a/tests/phpunit/includes/jobs/UpdateJobTest.php
b/tests/phpunit/includes/jobs/UpdateJobTest.php
index a12dd0a..6ac9fe5 100644
--- a/tests/phpunit/includes/jobs/UpdateJobTest.php
+++ b/tests/phpunit/includes/jobs/UpdateJobTest.php
@@ -72,6 +72,13 @@
/**
* @since 1.9
*/
+ public function testDefaultContext() {
+ $this->assertInstanceOf( '\SMW\ContextResource',
$this->newInstance()->withContext() );
+ }
+
+ /**
+ * @since 1.9
+ */
public function testRun() {
$title = $this->newMockBuilder()->newObject( 'Title', array(
--
To view, visit https://gerrit.wikimedia.org/r/86892
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I98b95b00f57e123923441c447f7b55e71f55f0a2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits