Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/81449
Change subject: [DIC]: \SMW\JobBase implements \SMW\DependencyRequestor
......................................................................
[DIC]: \SMW\JobBase implements \SMW\DependencyRequestor
\SMW\UpdateDispatcherJob
Code coverage: 100%
CRAP: 15
\SMW\UpdateJob
Code coverage: 100%
CRAP: 7 (before 9)
\SMW\UpdateObserver
Code coverage: 100%
CRAP: 5 (before 15)
+ Cleaner interface
+ Eliminate setter/getter clutter
Change-Id: I3e9ee616b2d3667032c6bd3be6c3f88eca4017be
---
M includes/UpdateObserver.php
M includes/dic/SharedDependencyContainer.php
M includes/jobs/JobBase.php
M includes/jobs/UpdateDispatcherJob.php
M includes/jobs/UpdateJob.php
M tests/phpunit/includes/UpdateObserverTest.php
M tests/phpunit/includes/dic/SharedDependencyContainerTest.php
D tests/phpunit/includes/jobs/JobBaseTest.php
M tests/phpunit/includes/jobs/UpdateDispatcherJobTest.php
M tests/phpunit/includes/jobs/UpdateJobTest.php
10 files changed, 268 insertions(+), 297 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/49/81449/1
diff --git a/includes/UpdateObserver.php b/includes/UpdateObserver.php
index 889b11a..1828c2b 100644
--- a/includes/UpdateObserver.php
+++ b/includes/UpdateObserver.php
@@ -80,12 +80,17 @@
*/
public function runStoreUpdater( ParserData $subject ) {
- $updater = new StoreUpdater(
- $this->getDependencyBuilder()->newObject( 'Store' ),
- $subject->getData(),
- $this->getDependencyBuilder()->newObject( 'Settings' )
- );
+ /**
+ * @var Settings $settings
+ */
+ $settings = $this->getDependencyBuilder()->newObject(
'Settings' );
+ /**
+ * @var Store $store
+ */
+ $store = $this->getDependencyBuilder()->newObject( 'Store' );
+
+ $updater = new StoreUpdater( $store, $subject->getData(),
$settings );
$updater->setUpdateStatus( $subject->getUpdateStatus()
)->doUpdate();
return true;
@@ -113,19 +118,9 @@
*/
public function runUpdateDispatcher( TitleAccess $subject ) {
- $settings = $this->getDependencyBuilder()->newObject(
'Settings' );
-
$dispatcher = new UpdateDispatcherJob( $subject->getTitle() );
- $dispatcher->setSettings( $settings );
-
- if ( $settings->get( 'smwgDeferredPropertyUpdate' ) &&
class_exists( '\SMW\PropertyPageIdMapper' ) ) {
- // Enable coverage after PropertyPageIdMapper is
available
- // @codeCoverageIgnoreStart
- $dispatcher->insert(); // JobQueue is handling
dispatching
- // @codeCoverageIgnoreEnd
- } else {
- $dispatcher->run();
- }
+ $dispatcher->setDependencyBuilder(
$this->getDependencyBuilder() );
+ $dispatcher->run();
return true;
}
diff --git a/includes/dic/SharedDependencyContainer.php
b/includes/dic/SharedDependencyContainer.php
index c1e0e70..20cca18 100644
--- a/includes/dic/SharedDependencyContainer.php
+++ b/includes/dic/SharedDependencyContainer.php
@@ -88,40 +88,51 @@
} );
/**
- * UpdateObserver object definitions
+ * UpdateObserver object definition
*
* @since 1.9
*
* @return UpdateObserver
*/
- $this->registerObject( 'UpdateObserver', function (
DependencyBuilder $builder ){
+ $this->registerObject( 'UpdateObserver', function (
DependencyBuilder $builder ) {
$updateObserver = new UpdateObserver();
$updateObserver->setDependencyBuilder( $builder );
return $updateObserver;
} );
/**
- * ObservableSubjectDispatcher object definitions
+ * ObservableSubjectDispatcher object definition
*
* @since 1.9
*
* @return ObservableSubjectDispatcher
*/
- $this->registerObject( 'ObservableUpdateDispatcher', function (
DependencyBuilder $builder ){
+ $this->registerObject( 'ObservableUpdateDispatcher', function (
DependencyBuilder $builder ) {
return new ObservableSubjectDispatcher(
$builder->newObject( 'UpdateObserver' ) );
} );
/**
- * NamespaceExaminer object definitions
+ * NamespaceExaminer object definition
*
* @since 1.9
*
* @return NamespaceExaminer
*/
- $this->registerObject( 'NamespaceExaminer', function (
DependencyBuilder $builder ){
+ $this->registerObject( 'NamespaceExaminer', function (
DependencyBuilder $builder ) {
return NamespaceExaminer::newFromArray(
$builder->newObject( 'Settings' )->get( 'smwgNamespacesWithSemanticLinks' ) );
} );
+ /**
+ * ContentParser object definition
+ *
+ * @since 1.9
+ *
+ * @return ContentParser
+ */
+ $this->registerObject( 'ContentParser', function (
DependencyBuilder $builder ) {
+ return new ContentParser( $builder->getArgument(
'Title' ) );
+ } );
+
// $this->set( 'FactboxPresenter', function ( DependencyBuilder
$builder ) {
// $outputPage = $builder->getArgument( 'OutputPage' );
// return new FactboxPresenter( $outputPage,
$builder->newObject( 'Settings' ) );
diff --git a/includes/jobs/JobBase.php b/includes/jobs/JobBase.php
index 0ee7a6e..e4dffe4 100644
--- a/includes/jobs/JobBase.php
+++ b/includes/jobs/JobBase.php
@@ -20,21 +20,46 @@
*
* @ingroup Job
*/
-abstract class JobBase extends Job implements Cacheable, Configurable,
StoreAccess {
+abstract class JobBase extends Job implements DependencyRequestor {
- /** $var Store */
- protected $store = null;
+ /** @var DependencyBuilder */
+ protected $dependencyBuilder = null;
- /** $var Settings */
- protected $settings = null;
+ /**
+ * @see DependencyRequestor::setDependencyBuilder
+ *
+ * @since 1.9
+ *
+ * @param DependencyBuilder $builder
+ */
+ public function setDependencyBuilder( DependencyBuilder $builder ) {
+ $this->dependencyBuilder = $builder;
+ }
- /** $var CacheHandler */
- protected $cache = null;
+ /**
+ * @see DependencyRequestor::getDependencyBuilder
+ *
+ * @since 1.9
+ *
+ * @return DependencyBuilder
+ */
+ public function getDependencyBuilder() {
+
+ // JobBase is a top-level class and to avoid a non-instantiated
object
+ // a default builder is set as for when Jobs are triggered using
+ // command line etc.
+
+ if ( $this->dependencyBuilder === null ) {
+ $this->dependencyBuilder = new SimpleDependencyBuilder(
new SharedDependencyContainer() );
+ }
+
+ return $this->dependencyBuilder;
+ }
/**
* Returns invoked Title object
*
- * Apparently Job::getTitle() in MW 1.19 does not exists
+ * Apparently Job::getTitle() in MW 1.19 does not exist
*
* @since 1.9
*
@@ -44,75 +69,4 @@
return $this->title;
}
- /**
- * Sets Store object
- *
- * @since 1.9
- *
- * @param Store $store
- */
- public function setStore( Store $store ) {
- $this->store = $store;
- return $this;
- }
-
- /**
- * Returns Store object
- *
- * @since 1.9
- *
- * @return Store
- */
- public function getStore() {
-
- if ( $this->store === null ) {
- $this->store = StoreFactory::getStore();
- }
-
- return $this->store;
- }
-
- /**
- * Sets Settings object
- *
- * @since 1.9
- *
- * @param Store $store
- */
- public function setSettings( Settings $settings ) {
- $this->settings = $settings;
- return $this;
- }
-
- /**
- * Returns Settings object
- *
- * @since 1.9
- *
- * @return Settings
- */
- public function getSettings() {
-
- if ( $this->settings === null ) {
- $this->settings = Settings::newFromGlobals();
- }
-
- return $this->settings;
- }
-
- /**
- * Returns CacheHandler object
- *
- * @since 1.9
- *
- * @return CacheHandler
- */
- public function getCache() {
-
- if ( $this->cache === null ) {
- $this->cache = CacheHandler::newFromId(
$this->getSettings()->get( 'smwgCacheType' ) );
- }
-
- return $this->cache;
- }
}
diff --git a/includes/jobs/UpdateDispatcherJob.php
b/includes/jobs/UpdateDispatcherJob.php
index 9d9397e..de72b54 100644
--- a/includes/jobs/UpdateDispatcherJob.php
+++ b/includes/jobs/UpdateDispatcherJob.php
@@ -69,8 +69,8 @@
public function run() {
Profiler::In( __METHOD__, true );
- if ( $this->title->getNamespace() === SMW_NS_PROPERTY ) {
- $this->distribute( DIProperty::newFromUserLabel(
$this->title->getText() ) )->push();
+ if ( $this->getTitle()->getNamespace() === SMW_NS_PROPERTY ) {
+ $this->distribute( DIProperty::newFromUserLabel(
$this->getTitle()->getText() ) )->push();
}
Profiler::Out( __METHOD__, true );
@@ -99,8 +99,13 @@
protected function distribute( DIProperty $property ) {
Profiler::In( __METHOD__, true );
+ /**
+ * @var Store $store
+ */
+ $store = $this->getDependencyBuilder()->newObject( 'Store' );
+
// Array of all subjects that have some value for the given
property
- $subjects = $this->getStore()->getAllPropertySubjects(
$property );
+ $subjects = $store->getAllPropertySubjects( $property );
$this->addJobs( $subjects );
@@ -112,7 +117,7 @@
// Fetch all those that have an error property attached and
// re-run it through the job-queue
- $subjects = $this->getStore()->getPropertySubjects(
+ $subjects = $store->getPropertySubjects(
new DIProperty( DIProperty::TYPE_ERROR ),
DIWikiPage::newFromTitle( $this->title )
);
@@ -169,7 +174,13 @@
* @codeCoverageIgnore
*/
public function insert() {
- if ( $this->getSettings()->get( 'smwgEnableUpdateJobs' ) ) {
+
+ /**
+ * @var Settings $settings
+ */
+ $settings = $this->getDependencyBuilder()->newObject(
'Settings' );
+
+ if ( $settings->get( 'smwgEnableUpdateJobs' ) ) {
parent::insert();
}
}
diff --git a/includes/jobs/UpdateJob.php b/includes/jobs/UpdateJob.php
index ca60bed..61d629a 100644
--- a/includes/jobs/UpdateJob.php
+++ b/includes/jobs/UpdateJob.php
@@ -4,11 +4,7 @@
use ParserOutput;
use LinkCache;
-use WikiPage;
-use Revision;
use Title;
-use User;
-use Job;
/**
* UpdateJob is responsible for the asynchronous update of semantic data
@@ -40,9 +36,6 @@
*/
class UpdateJob extends JobBase {
- /** @var ContentParser */
- protected $contentParser = null;
-
/**
* @since 1.9
*
@@ -61,52 +54,64 @@
LinkCache::singleton()->clear();
- if ( $this->getTitle() === null ) {
- $this->setLastError( __METHOD__ . ': Invalid title' );
- Profiler::Out( __METHOD__ . '-run' );
- return false;
- } elseif ( !$this->getTitle()->exists() ) {
- $this->getStore()->deleteSubject( $this->getTitle() );
// be sure to clear the data
+ /**
+ * @var Store $store
+ */
+ $store = $this->getDependencyBuilder()->newObject( 'Store' );
+
+ // For non existing titles make sure to clear the data
+ if ( !$this->getTitle()->exists() ) {
+ $store->deleteSubject( $this->getTitle() );
Profiler::Out( __METHOD__ . '-run' );
return true;
}
- if ( !$this->getContentParser()->getOutput() instanceof
ParserOutput ) {
- $this->setLastError(
$this->getContentParser()->getErrors() );
+ /**
+ * @var ContentParser $contentParser
+ */
+ $contentParser = $this->getDependencyBuilder()->newObject(
'ContentParser', array(
+ 'Title' => $this->getTitle()
+ ) );
+
+ $contentParser->parse();
+
+ if ( !( $contentParser->getOutput() instanceof ParserOutput ) )
{
+ Profiler::Out( __METHOD__ . '-run' );
+ $this->setLastError( $contentParser->getErrors() );
return false;
}
- Profiler::In( __METHOD__ . '-update' );
+ $this->runStoreUpdate( $contentParser->getOutput() );
- $parserData = new ParserData( $this->getTitle(),
$this->getContentParser()->getOutput() );
- $parserData->setObservableDispatcher( new
ObservableSubjectDispatcher( new UpdateObserver() ) )
- ->disableUpdateJobs()
- ->updateStore();
-
- Profiler::Out( __METHOD__ . '-update' );
Profiler::Out( __METHOD__ . '-run' );
return true;
}
/**
- * Returns a ContentParser object
+ * @since 1.9
*
- * @since 1.9
- *
- * @return ContentParser
+ * @param ParserOutput $parserOutput
*/
- protected function getContentParser() {
+ private function runStoreUpdate( ParserOutput $parserOutput ) {
+ Profiler::In( __METHOD__ . '-update' );
- if ( $this->contentParser === null ) {
- $this->contentParser = new ContentParser( $this->title
);
- $this->contentParser->parse();
- }
+ /**
+ * @var ParserData $parserData
+ */
+ $parserData = $this->getDependencyBuilder()->newObject(
'ParserData', array(
+ 'Title' => $this->getTitle(),
+ 'ParserOutput' => $parserOutput
+ ) );
- return $this->contentParser;
+ $parserData->disableUpdateJobs()->updateStore();
+
+ Profiler::Out( __METHOD__ . '-update' );
}
/**
+ * @see Job::insert
+ *
* This actually files the job. This is prevented if the configuration
of SMW
* disables jobs.
* @note Any method that inserts jobs with Job::batchInsert or
otherwise must
@@ -115,7 +120,13 @@
* @codeCoverageIgnore
*/
function insert() {
- if ( $this->getSettings()->get( 'smwgEnableUpdateJobs' ) ) {
+
+ /**
+ * @var Settings $settings
+ */
+ $settings = $this->getDependencyBuilder()->newObject(
'Settings' );
+
+ if ( $settings->get( 'smwgEnableUpdateJobs' ) ) {
parent::insert();
}
}
diff --git a/tests/phpunit/includes/UpdateObserverTest.php
b/tests/phpunit/includes/UpdateObserverTest.php
index 8a90f7e..34c0536 100644
--- a/tests/phpunit/includes/UpdateObserverTest.php
+++ b/tests/phpunit/includes/UpdateObserverTest.php
@@ -51,10 +51,15 @@
// $observer->setDependencyBuilder( new
\SMW\SimpleDependencyBuilder );
$observer->setDependencyBuilder(
$observer->getDependencyBuilder() );
+ $mockStore = $this->newMockObject( array(
+ 'getAllPropertySubjects' => array(),
+ 'getPropertySubjects' => array()
+ ) )->getMockStore();
+
// Dependency object registration
$observer->getDependencyBuilder()
->getContainer()
- ->registerObject( 'Store',
$this->newMockObject()->getMockStore() );
+ ->registerObject( 'Store', $mockStore );
return $observer;
}
@@ -83,7 +88,10 @@
->getContainer()
->registerObject( 'Settings', $this->newSettings(
$setup['settings'] ) );
- $this->assertTrue( $instance->runUpdateDispatcher(
$setup['title'] ) );
+ $this->assertTrue(
+ $instance->runUpdateDispatcher( $setup['title'] ),
+ 'asserts that runUpdateDispatcher always returns true'
+ );
}
/**
@@ -101,7 +109,10 @@
->getContainer()
->registerObject( 'Settings', $this->newSettings(
$setup['settings'] ) );
- $this->assertTrue( $instance->runStoreUpdater(
$setup['parserData'] ) );
+ $this->assertTrue(
+ $instance->runStoreUpdater( $setup['parserData'] ),
+ 'asserts that runStoreUpdater always returns true'
+ );
}
/**
diff --git a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
index ef204ad..665d8a0 100644
--- a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
+++ b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
@@ -113,6 +113,12 @@
$provider[] = array( 'UpdateObserver', array(
'\SMW\UpdateObserver' => array() ) );
$provider[] = array( 'ObservableUpdateDispatcher', array(
'\SMW\ObservableSubjectDispatcher' => array() ) );
+ $provider[] = array( 'ContentParser' , array(
'\SMW\ContentParser' => array(
+ 'Title' =>
$this->newMockObject()->getMockTitle()
+ )
+ )
+ );
+
$provider[] = array( 'ParserData' , array( '\SMW\ParserData'
=> array(
'Title' =>
$this->newMockObject()->getMockTitle(),
'ParserOutput' =>
$this->newMockObject()->getMockParserOutput()
diff --git a/tests/phpunit/includes/jobs/JobBaseTest.php
b/tests/phpunit/includes/jobs/JobBaseTest.php
deleted file mode 100644
index e880ccb..0000000
--- a/tests/phpunit/includes/jobs/JobBaseTest.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-
-namespace SMW\Test;
-
-use SMW\JobBase;
-
-/**
- * Tests for the JobBase class
- *
- * @file
- *
- * @license GNU GPL v2+
- * @since 1.9
- *
- * @author mwjames
- */
-
-/**
- * @covers \SMW\JobBase
- *
- * @ingroup Test
- *
- * @group SMW
- * @group SMWExtension
- */
-class JobBaseTest extends SemanticMediaWikiTestCase {
-
- /**
- * Returns the name of the class to be tested
- *
- * @return string|false
- */
- public function getClass() {
- return '\SMW\JobBase';
- }
-
- /**
- * Helper method that returns a JobBase object
- *
- * @since 1.9
- *
- * @param $result
- *
- * @return JobBase
- */
- private function getInstance() {
- return $this->getMockForAbstractClass( $this->getClass(),
array( $this->newTitle(), array() ) );
- }
-
- /**
- * @test JobBase::__construct
- *
- * @since 1.9
- */
- public function testConstructor() {
- $this->assertInstanceOf( $this->getClass(),
$this->getInstance() );
- }
-
- /**
- * @test JobBase::getStore
- * @test JobBase::setStore
- *
- * @since 1.9
- */
- public function testGetSetStore() {
-
- $instance = $this->getInstance();
- $mockStore = $this->newMockObject()->getMockStore();
-
- $this->assertInstanceOf( '\SMW\Store', $instance->getStore() );
- $this->assertInstanceOf( $this->getClass(),
$instance->setStore( $mockStore ) );
- $this->assertInstanceOf( '\SMW\Store', $instance->getStore() );
- $this->assertEquals( $mockStore, $instance->getStore() );
- }
-
- /**
- * @test JobBase::setSettings
- * @test JobBase::getSettings
- *
- * @since 1.9
- */
- public function testGetSetSettings() {
-
- $instance = $this->getInstance();
- $settings = $this->newSettings( array( 'test' => 'lula' ) );
-
- $this->assertInstanceOf( '\SMW\Settings',
$instance->getSettings() );
- $this->assertInstanceOf( $this->getClass(),
$instance->setSettings( $settings ) );
- $this->assertInstanceOf( '\SMW\Settings',
$instance->getSettings() );
- $this->assertEquals( $settings, $instance->getSettings() );
-
- }
-
- /**
- * @test JobBase::getCache
- *
- * @since 1.9
- */
- public function testGetCache() {
-
- $instance = $this->getInstance();
- $this->assertInstanceOf( '\SMW\CacheHandler',
$instance->getCache() );
- }
-
-}
diff --git a/tests/phpunit/includes/jobs/UpdateDispatcherJobTest.php
b/tests/phpunit/includes/jobs/UpdateDispatcherJobTest.php
index 22f850e..e4880cf 100644
--- a/tests/phpunit/includes/jobs/UpdateDispatcherJobTest.php
+++ b/tests/phpunit/includes/jobs/UpdateDispatcherJobTest.php
@@ -2,6 +2,7 @@
namespace SMW\Test;
+use SMW\SharedDependencyContainer;
use SMW\UpdateDispatcherJob;
use SMW\DIProperty;
@@ -52,8 +53,30 @@
*
* @return UpdateDispatcherJob
*/
- private function getInstance( Title $title = null ) {
- return new UpdateDispatcherJob( $title === null ?
$this->getTitle() : $title );
+ private function newInstance( Title $title = null ) {
+
+ if ( $title === null ) {
+ $title = $this->newTitle();
+ }
+
+ $mockStore = $this->newMockObject( array(
+ 'getAllPropertySubjects' => array( $this,
'mockStoreAllPropertySubjectsCallback' ),
+ 'getPropertySubjects' => array()
+ ) )->getMockStore();
+
+ $settings = $this->newSettings( array(
+ 'smwgCacheType' => 'hash',
+ 'smwgEnableUpdateJobs' => false
+ ) );
+
+ $container = new SharedDependencyContainer();
+ $container->registerObject( 'Store', $mockStore );
+ $container->registerObject( 'Settings', $settings );
+
+ $instance = new UpdateDispatcherJob( $title );
+ $instance->setDependencyBuilder( $this->newDependencyBuilder(
$container ) );
+
+ return $instance;
}
/**
@@ -62,7 +85,7 @@
* @since 1.9
*/
public function testConstructor() {
- $this->assertInstanceOf( $this->getClass(),
$this->getInstance() );
+ $this->assertInstanceOf( $this->getClass(),
$this->newInstance() );
}
/**
@@ -74,7 +97,7 @@
* @since 1.9
*/
public function testPush() {
- $this->assertNull( $this->getInstance()->push() );
+ $this->assertNull( $this->newInstance()->push() );
}
/**
@@ -82,43 +105,27 @@
*
* @since 1.9
*/
- public function testDBRun() {
- $this->assertTrue( $this->getInstance( $this->newTitle(
SMW_NS_PROPERTY ) )->disable()->run() );
+ public function testRunOnDB() {
+ $this->assertTrue( $this->newInstance( $this->newTitle(
SMW_NS_PROPERTY ) )->disable()->run() );
}
/**
* @test UpdateDispatcherJob::run
+ * @dataProvider subjectDataProvider
*
* @since 1.9
*/
- public function testMockRun() {
+ public function testRunOnMockObjects( $setup, $expected ) {
- $title = $this->newTitle( SMW_NS_PROPERTY );
-
- // Set-up expected property, accessible in the mock callback
- $this->property = DIProperty::newFromUserLabel(
$title->getText() );
+ // Set-up expected property to be accessible in the mock
callback
+ $this->property = DIProperty::newFromUserLabel(
$setup['title']->getText() );
// Set-up expected "raw" subjects to be returned (plus
duplicate)
- $duplicate = $this->newSubject();
- $this->subjects = array(
- $duplicate,
- $this->newSubject(),
- $this->newSubject(),
- $duplicate,
- $this->newSubject()
- );
- $count = count( $this->subjects ) - 1; // eliminate duplicate
count
+ $this->subjects = $setup['subjects'];
- $mockStore = $this->newMockObject( array(
- 'getAllPropertySubjects' => array( $this,
'mockStoreAllPropertySubjectsCallback' ),
- 'getPropertySubjects' => array()
- ) )->getMockStore();
+ $instance = $this->newInstance( $setup['title'] );
- $instance = $this->getInstance( $title );
- $instance->setStore( $mockStore );
-
- // Disable distribution of generated jobs
- // being inserted into the"real" JobQueue
+ // For tests disable distribution of jobs into the "real"
JobQueue
$instance->disable()->run();
// Get access to protected jobs property
@@ -128,11 +135,24 @@
$result = $jobs->getValue( $instance );
- $this->assertInternalType( 'array', $result );
- $this->assertCount( $count, $result );
+ $this->assertInternalType(
+ 'array',
+ $result,
+ 'asserts the result type'
+ );
+
+ $this->assertCount(
+ $expected['count'],
+ $result,
+ 'asserts the amount of available job entries'
+ );
foreach ( $result as $job ) {
- $this->assertInstanceOf( 'SMW\UpdateJob', $job );
+ $this->assertInstanceOf(
+ 'SMW\UpdateJob',
+ $job,
+ 'asserts the instance type of an invoked job'
+ );
}
}
@@ -149,4 +169,36 @@
return $this->property == $property ? $this->subjects : array();
}
+ /**
+ * @return array
+ */
+ public function subjectDataProvider() {
+
+ $provider = array();
+
+ $title = $this->newTitle( SMW_NS_PROPERTY );
+
+ $duplicate = $this->newSubject();
+ $subjects = array(
+ $duplicate,
+ $this->newSubject(),
+ $this->newSubject(),
+ $duplicate,
+ $this->newSubject()
+ );
+
+ $count = count( $subjects ) - 1; // eliminate duplicate count
+
+ $provider[] = array(
+ array(
+ 'title' => $title,
+ 'subjects' => $subjects
+ ),
+ array(
+ 'count' => $count
+ )
+ );
+
+ return $provider;
+ }
}
diff --git a/tests/phpunit/includes/jobs/UpdateJobTest.php
b/tests/phpunit/includes/jobs/UpdateJobTest.php
index 689d2d9..ccc21f5 100644
--- a/tests/phpunit/includes/jobs/UpdateJobTest.php
+++ b/tests/phpunit/includes/jobs/UpdateJobTest.php
@@ -2,6 +2,7 @@
namespace SMW\Test;
+use SMW\SharedDependencyContainer;
use SMW\UpdateJob;
use Title;
@@ -19,6 +20,7 @@
/**
* @covers \SMW\UpdateJob
+ * @covers \SMW\JobBase
*
* @ingroup Test
*
@@ -43,13 +45,30 @@
*
* @return UpdateJob
*/
- private function getInstance( Title $title = null ) {
- $instance = new UpdateJob( $title === null ? $this->newTitle()
: $title );
+ private function newInstance( Title $title = null, $settings = null ) {
+
+ if ( $title === null ) {
+ $title = $this->newTitle();
+ }
// Set smwgEnableUpdateJobs to false in order to avoid having
jobs being
// inserted as real jobs to the queue
- $instance->setSettings( $this->getSettings( array(
'smwgEnableUpdateJobs' => false ) ) );
+ if ( $settings === null ) {
+ $settings = $this->newSettings( array(
+ 'smwgCacheType' => 'hash',
+ 'smwgEnableUpdateJobs' => false
+ ) );
+ }
+
+ $instance = new UpdateJob( $title );
+
+ $container = $instance->getDependencyBuilder()->getContainer();
+ $container->registerObject( 'Settings', $settings );
+ $container->registerObject( 'Store',
$this->newMockObject()->getMockStore() );
+ $instance->getDependencyBuilder()->registerContainer(
$container );
+
return $instance;
+
}
/**
@@ -61,10 +80,9 @@
* @since 1.9
*/
public function testConstructor() {
- $this->assertInstanceOf( $this->getClass(),
$this->getInstance() );
- $this->assertInstanceOf( 'SMWUpdateJob', $this->getInstance() );
+ $this->assertInstanceOf( $this->getClass(),
$this->newInstance() );
+ $this->assertInstanceOf( $this->getClass(), new \SMWUpdateJob(
$this->newTitle() ) );
}
-
/**
* @test UpdateJob::__construct
@@ -73,9 +91,14 @@
*/
public function testRun() {
- $title = $this->newMockObject( array( 'exists' => true )
)->getMockTitle();
- $instance = $this->getInstance( $title );
- $this->assertFalse( $instance->run() );
+ $title = $this->newMockObject( array(
+ 'exists' => true
+ ) )->getMockTitle();
+
+ $this->assertFalse(
+ $this->newInstance( $title )->run(),
+ 'asserts that ...'
+ );
}
@@ -85,17 +108,19 @@
*
* @since 1.9
*/
- public function testMockRun( $test, $expected ) {
+ public function testRunOnMockObjects( $setup, $expected ) {
- $reflector = $this->newReflector();
- $instance = $this->getInstance( $test['title'] );
- $instance->setStore( $this->newMockObject()->getMockStore() );
+ $instance = $this->newInstance( $setup['title'] );
- $contentParser = $reflector->getProperty( 'contentParser' );
- $contentParser->setAccessible( true );
- $contentParser->setValue( $instance, $test['contentParser'] );
+ $instance->getDependencyBuilder()
+ ->getContainer()
+ ->registerObject( 'ContentParser',
$setup['contentParser'] );
- $this->assertEquals( $expected['result'], $instance->run() );
+ $this->assertEquals(
+ $expected['result'],
+ $instance->run(),
+ 'asserts that ...'
+ );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/81449
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e9ee616b2d3667032c6bd3be6c3f88eca4017be
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits