jenkins-bot has submitted this change and it was merged.
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: 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/hooks/README.md
M includes/jobs/JobBase.php
M includes/jobs/UpdateDispatcherJob.php
M includes/jobs/UpdateJob.php
M tests/phpunit/includes/UpdateObserverTest.php
D tests/phpunit/includes/jobs/JobBaseTest.php
M tests/phpunit/includes/jobs/UpdateDispatcherJobTest.php
M tests/phpunit/includes/jobs/UpdateJobTest.php
9 files changed, 289 insertions(+), 315 deletions(-)
Approvals:
Mwjames: Looks good to me, approved
jenkins-bot: Verified
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/hooks/README.md b/includes/hooks/README.md
index 08b8914..570f97a 100644
--- a/includes/hooks/README.md
+++ b/includes/hooks/README.md
@@ -1,18 +1,18 @@
-[Hooks][hooks] are so-called event handlers that allow costum code to be
executed. Semantic MediaWiki (SMW) uses several of those hooks to enable
specific process logic to be integrated with MediaWiki. SMW currently
integrates the following hooks:
+[Hooks][hooks] are so-called event handlers that allow custom code to be
executed. Semantic MediaWiki (SMW) uses several of those hooks to enable
specific process logic to be integrated with MediaWiki. SMW currently uses the
following hooks:
#### ArticlePurge
-ArticlePurge executes during a pruge action of an article and depending on
available settings is being used to track a manual refresh of a page.
+ArticlePurge is executed during a manual purge action of an article and
depending on available settings is being used to track a page refresh.
#### BeforePageDisplay
BeforePageDisplay allows last minute changes to the output page and is being
used to render a ExportRDF link into each individual article.
#### InternalParseBeforeLinks
-InternalParseBeforeLinks is used to process and expand text content, and in
case of SMW is used to indentify and resolve [[link::syntax]] property
annotation syntax, returning a modified content component and storing property
annotations within the ParserOutput object.
+InternalParseBeforeLinks is used to process and expand text content, and in
case of SMW it is used to identify and resolve the property annotation syntax
([[link::syntax]]), returning a modified content component and storing
annotations within the ParserOutput object.
#### LinksUpdateConstructed
-LinksUpdateConstructed is called at the end of LinksUpdate and is being used
to iniate a store update for data that where stored in the ParserOutput object.
+LinksUpdateConstructed is called at the end of LinksUpdate and is being used
to initiate a store update for data that were held by the ParserOutput object.
#### ParserAfterTidy
-ParserAfterTidy is used to re-introduce content, update base annotations (e.g.
special properties, categories etc.) and in case of a manual article purge
initiates a store update (LinksUpdateConstructed wouldn't work because on link
has been changed and therefore would not trigger a LinksUpdateConstructed
event).
+ParserAfterTidy is used to re-introduce content, update base annotations (e.g.
special properties, categories etc.) and in case of a manual article purge
initiates a store update (LinksUpdateConstructed wouldn't work because it acts
only on link changes and therefore would not trigger a LinksUpdateConstructed
event).
[hooks]: https://www.mediawiki.org/wiki/Hooks "Manual:Hooks"
\ No newline at end of file
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..269b6a5 100644
--- a/includes/jobs/UpdateDispatcherJob.php
+++ b/includes/jobs/UpdateDispatcherJob.php
@@ -6,9 +6,7 @@
use Job;
/**
- * Dispatcher class to either run in deferred or immediate mode to generate
- * necessary UpdateJob's to restore the data parity between a property
- * and its attached subjects
+ * Dispatcher class to enable to run in deferred or immediate update mode
*
* @file
*
@@ -19,9 +17,8 @@
*/
/**
- * Dispatcher class to either run in deferred or immediate mode to generate
- * necessary UpdateJob's to restore the data parity between a property
- * and its attached subjects
+ * Dispatcher class to enable to run UpdateJob in deferred or immediate mode
+ * that restores the data parity between a property and its attached subjects
*
* @ingroup Job
* @ingroup Dispatcher
@@ -69,8 +66,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 +96,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 +114,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 +171,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..ed7efc7 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
*
@@ -53,60 +46,97 @@
}
/**
- * Run job
- * @return boolean success
+ * @see Job::run
+ *
+ * @return boolean
*/
public function run() {
Profiler::In( __METHOD__ . '-run' );
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
- Profiler::Out( __METHOD__ . '-run' );
+ $result = $this->runUpdate();
+
+ Profiler::Out( __METHOD__ . '-run' );
+ return $result;
+ }
+
+ /**
+ * @since 1.9
+ *
+ * @param Title $title
+ *
+ * @return boolean
+ */
+ private function runUpdate() {
+
+ // For non existing titles make sure to clear the data
+ if ( !$this->getTitle()->exists() ) {
+
+ /**
+ * @var Store $store
+ */
+ $store = $this->getDependencyBuilder()->newObject(
'Store' );
+
+ $store->deleteSubject( $this->getTitle() );
return true;
}
- if ( !$this->getContentParser()->getOutput() instanceof
ParserOutput ) {
- $this->setLastError(
$this->getContentParser()->getErrors() );
+ return $this->runContentParser();
+ }
+
+ /**
+ * @since 1.9
+ *
+ * @return boolean
+ */
+ private function runContentParser() {
+
+ /**
+ * @var ContentParser $contentParser
+ */
+ $contentParser = $this->getDependencyBuilder()->newObject(
'ContentParser', array(
+ 'Title' => $this->getTitle()
+ ) );
+
+ $contentParser->parse();
+
+ if ( !( $contentParser->getOutput() instanceof ParserOutput ) )
{
+ $this->setLastError( $contentParser->getErrors() );
return false;
}
+ return $this->runStoreUpdater( $contentParser->getOutput() );
+
+ }
+
+ /**
+ * @since 1.9
+ *
+ * @param ParserOutput $parserOutput
+ *
+ * @return true
+ */
+ private function runStoreUpdater( ParserOutput $parserOutput ) {
Profiler::In( __METHOD__ . '-update' );
- $parserData = new ParserData( $this->getTitle(),
$this->getContentParser()->getOutput() );
- $parserData->setObservableDispatcher( new
ObservableSubjectDispatcher( new UpdateObserver() ) )
- ->disableUpdateJobs()
- ->updateStore();
+ /**
+ * @var ParserData $parserData
+ */
+ $parserData = $this->getDependencyBuilder()->newObject(
'ParserData', array(
+ 'Title' => $this->getTitle(),
+ 'ParserOutput' => $parserOutput
+ ) );
+
+ $parserData->disableUpdateJobs()->updateStore();
Profiler::Out( __METHOD__ . '-update' );
- Profiler::Out( __METHOD__ . '-run' );
-
return true;
}
/**
- * Returns a ContentParser object
+ * @see Job::insert
*
- * @since 1.9
- *
- * @return ContentParser
- */
- protected function getContentParser() {
-
- if ( $this->contentParser === null ) {
- $this->contentParser = new ContentParser( $this->title
);
- $this->contentParser->parse();
- }
-
- return $this->contentParser;
- }
-
- /**
* 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 +145,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..4c11b2c 100644
--- a/tests/phpunit/includes/UpdateObserverTest.php
+++ b/tests/phpunit/includes/UpdateObserverTest.php
@@ -47,14 +47,17 @@
$observer = new UpdateObserver();
- // For now use the default builder set internally by the
observer
- // $observer->setDependencyBuilder( new
\SMW\SimpleDependencyBuilder );
+ // Use the provided default builder
$observer->setDependencyBuilder(
$observer->getDependencyBuilder() );
- // Dependency object registration
+ $mockStore = $this->newMockObject( array(
+ 'getAllPropertySubjects' => array(),
+ 'getPropertySubjects' => array()
+ ) )->getMockStore();
+
$observer->getDependencyBuilder()
->getContainer()
- ->registerObject( 'Store',
$this->newMockObject()->getMockStore() );
+ ->registerObject( 'Store', $mockStore );
return $observer;
}
@@ -78,12 +81,14 @@
$instance = $this->newInstance();
- // Dependency object registration
$instance->getDependencyBuilder()
->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'
+ );
}
/**
@@ -96,12 +101,14 @@
$instance = $this->newInstance();
- // Dependency object registration
$instance->getDependencyBuilder()
->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/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..055acb3 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,30 @@
*
* @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(),
+ 'assert that run() always returns true'
+ );
}
/**
* @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 +138,24 @@
$result = $jobs->getValue( $instance );
- $this->assertInternalType( 'array', $result );
- $this->assertCount( $count, $result );
+ $this->assertInternalType(
+ 'array',
+ $result,
+ 'asserts that the job result property is of type array'
+ );
+
+ $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 that the job instance is of type
\SMW\UpdateJob'
+ );
}
}
@@ -149,4 +172,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..a685222 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,29 @@
*
* @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() );
+
return $instance;
+
}
/**
@@ -61,10 +79,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 +90,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 the run() returns false due to a missing
ParserOutput object'
+ );
}
@@ -85,17 +107,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 run() in terms of the available ContentParser
object'
+ );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/81449
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3e9ee616b2d3667032c6bd3be6c3f88eca4017be
Gerrit-PatchSet: 5
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