Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86893
Change subject: CacheableObjectCollector to implement ContextAware / Delete
SMWSQLStore3SpecialPageHandlers
......................................................................
CacheableObjectCollector to implement ContextAware / Delete
SMWSQLStore3SpecialPageHandlers
Eliminate assumptions that were implemented by SMWSQLStore3SpecialPageHandlers
and successively by each CacheableObjectCollector when using
...::newFromStore( $this->store ).
Change-Id: I5a1238ee7534655e68608bdd75ca1f6742a6cddc
---
M SemanticMediaWiki.classes.php
M includes/storage/CacheableObjectCollector.php
M includes/storage/SQLStore/PropertiesCollector.php
M includes/storage/SQLStore/SMW_SQLStore3.php
D includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
M includes/storage/SQLStore/StatisticsCollector.php
M includes/storage/SQLStore/UnusedPropertiesCollector.php
M includes/storage/SQLStore/WantedPropertiesCollector.php
M tests/phpunit/MockObjectRepository.php
M tests/phpunit/includes/storage/CacheableObjectCollectorTest.php
M tests/phpunit/includes/storage/sqlstore/PropertiesCollectorTest.php
D tests/phpunit/includes/storage/sqlstore/SpecialPageHandlersTest.php
M tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
M tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
M tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
15 files changed, 156 insertions(+), 481 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/93/86893/1
diff --git a/SemanticMediaWiki.classes.php b/SemanticMediaWiki.classes.php
index e4f07cd..ab5012a 100644
--- a/SemanticMediaWiki.classes.php
+++ b/SemanticMediaWiki.classes.php
@@ -300,7 +300,6 @@
'SMWSQLStore3QueryEngine' =>
'includes/storage/SQLStore/SMW_SQLStore3_Queries.php',
'SMWSQLStore3Query' =>
'includes/storage/SQLStore/SMW_SQLStore3_Queries.php',
'SMWSQLStore3Writers' =>
'includes/storage/SQLStore/SMW_SQLStore3_Writers.php',
- 'SMWSQLStore3SpecialPageHandlers' =>
'includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php',
'SMWSQLStore3SetupHandlers' =>
'includes/storage/SQLStore/SMW_SQLStore3_SetupHandlers.php',
'SMWDataItemHandler' =>
'includes/storage/SQLStore/SMW_DataItemHandler.php',
'SMWDIHandlerBoolean' =>
'includes/storage/SQLStore/SMW_DIHandler_Bool.php',
diff --git a/includes/storage/CacheableObjectCollector.php
b/includes/storage/CacheableObjectCollector.php
index 4fe9a61..d7800de 100644
--- a/includes/storage/CacheableObjectCollector.php
+++ b/includes/storage/CacheableObjectCollector.php
@@ -3,9 +3,10 @@
namespace SMW\Store;
use SMW\CacheableResultMapper;
+use SMW\ContextResource;
use SMW\DIProperty;
-use SMW\Settings;
+use DatabaseBase;
use SMWRequestOptions;
use InvalidArgumentException;
use MWTimestamp;
@@ -48,6 +49,12 @@
*/
abstract class CacheableObjectCollector implements ObjectCollector {
+ /** @var ContextResource */
+ protected $context;
+
+ /** @var DatabaseBase */
+ protected $dbConnection;
+
/** @var array */
protected $results = array();
@@ -59,6 +66,28 @@
/** @var string */
protected $cacheDate = null;
+
+ /**
+ * @since 1.9
+ *
+ * @param DatabaseBase $dbw
+ * @param ContextResource $context
+ */
+ public function __construct( DatabaseBase $dbw, ContextResource
$context ) {
+ $this->dbConnection = $dbw;
+ $this->context = $context;
+ }
+
+ /**
+ * @see ContextAware::withContext
+ *
+ * @since 1.9
+ *
+ * @return ContextResource
+ */
+ public function withContext() {
+ return $this->context;
+ }
/**
* Collects and returns information in an associative array
@@ -173,16 +202,17 @@
* @param string $type
*
* @return array
- * @@codeCoverageIgnore
+ * @codeCoverageIgnore
*/
protected function getPropertyTables( $type, $dataItemId = true ) {
- $propertyTables = $this->store->getPropertyTables();
+ $store = $this->withContext()->getStore();
+ $propertyTables = $store->getPropertyTables();
if ( $dataItemId ) {
- $id = $this->store->findTypeTableId( $type );
+ $id = $store->findTypeTableId( $type );
} else {
- $id = $this->store->findPropertyTableID( new
DIProperty( $type ) );
+ $id = $store->findPropertyTableID( new DIProperty(
$type ) );
}
return $propertyTables[$id];
diff --git a/includes/storage/SQLStore/PropertiesCollector.php
b/includes/storage/SQLStore/PropertiesCollector.php
index 600dbc1..d4cd2bb 100644
--- a/includes/storage/SQLStore/PropertiesCollector.php
+++ b/includes/storage/SQLStore/PropertiesCollector.php
@@ -7,14 +7,11 @@
use SMW\InvalidPropertyException;
use SMW\SimpleDictionary;
use SMW\DIProperty;
-use SMW\Settings;
use SMW\Profiler;
-use SMW\Store;
use SMWDIError;
use Message;
-use DatabaseBase;
/**
* Collects properties from a store entity
@@ -36,53 +33,6 @@
*/
class PropertiesCollector extends CacheableObjectCollector {
- /** @var Store */
- protected $store;
-
- /** @var Settings */
- protected $settings;
-
- /** @var DatabaseBase */
- protected $dbConnection;
-
- /**
- * @since 1.9
- *
- * @param Store $store
- * @param DatabaseBase $dbw
- * @param Settings $settings
- */
- public function __construct( Store $store, DatabaseBase $dbw, Settings
$settings ) {
- $this->store = $store;
- $this->dbConnection = $dbw;
- $this->settings = $settings;
- }
-
- /**
- * Factory method for an immediate instantiation of a
PropertiesCollector object
- *
- * @par Example:
- * @code
- * $properties = \SMW\SQLStore\PropertiesCollector::newFromStore(
$store )
- * $properties->getResults();
- * @endcode
- *
- * @since 1.9
- *
- * @param Store $store
- * @param $dbw Boolean or DatabaseBase:
- * - Boolean: whether to use a dedicated DB or Slave
- * - DatabaseBase: database connection to use
- *
- * @return ObjectCollector
- */
- public static function newFromStore( Store $store, $dbw = false ) {
-
- $dbw = $dbw instanceof DatabaseBase ? $dbw : wfGetDB( DB_SLAVE
);
- $settings = Settings::newFromGlobals();
- return new self( $store, $dbw, $settings );
- }
-
/**
* @see CacheableObjectCollector::cacheSetup
*
@@ -91,11 +41,17 @@
* @return ObjectDictionary
*/
protected function cacheSetup() {
+
+ /**
+ * @var Settings $settings
+ */
+ $settings = $this->withContext()->getSettings();
+
return new SimpleDictionary( array(
'id' => array( 'smwgPropertiesCache',
(array)$this->requestOptions ),
- 'type' => $this->settings->get( 'smwgCacheType' ),
- 'enabled' => $this->settings->get(
'smwgPropertiesCache' ),
- 'expiry' => $this->settings->get(
'smwgPropertiesCacheExpiry' )
+ 'type' => $settings->get( 'smwgCacheType' ),
+ 'enabled' => $settings->get( 'smwgPropertiesCache' ),
+ 'expiry' => $settings->get(
'smwgPropertiesCacheExpiry' )
) );
}
@@ -111,6 +67,11 @@
*/
protected function doCollect() {
Profiler::In( __METHOD__ );
+
+ /**
+ * @var Store $store
+ */
+ $store = $this->withContext()->getStore();
$result = array();
$propertyIds = array();
@@ -131,13 +92,13 @@
}
if ( $this->requestOptions->getStringConditions() ) {
- $conditions[] = $this->store->getSQLConditions(
$this->requestOptions, '', 'smw_title', false );
+ $conditions[] = $store->getSQLConditions(
$this->requestOptions, '', 'smw_title', false );
}
}
$res = $this->dbConnection->select(
- $this->store->getObjectIds()->getIdTable(),
+ $store->getObjectIds()->getIdTable(),
array(
'smw_id',
'smw_title'
@@ -151,7 +112,7 @@
$propertyIds[] = (int)$row->smw_id;
}
- $statsTable = new PropertyStatisticsTable(
$this->store->getStatisticsTable(), $this->dbConnection );
+ $statsTable = new PropertyStatisticsTable(
$store->getStatisticsTable(), $this->dbConnection );
$usageCounts = $statsTable->getUsageCounts( $propertyIds );
foreach ( $res as $row ) {
diff --git a/includes/storage/SQLStore/SMW_SQLStore3.php
b/includes/storage/SQLStore/SMW_SQLStore3.php
index 4320afa..a9e7d54 100644
--- a/includes/storage/SQLStore/SMW_SQLStore3.php
+++ b/includes/storage/SQLStore/SMW_SQLStore3.php
@@ -79,14 +79,10 @@
protected $writer = false;
/**
- * The SpecialPageHandler object used by this store. Initialized by
- * getSpecialPageHandler(), which is the only way in which it should
- * be accessed.
- *
- * @since 1.8
- * @var SMWSQLStore3SpecialPageHandlers
+ * @var ContextResource
+ * @since 1.9
*/
- protected $specialPageHandler = false;
+ protected $context = null;
/**
* The SetupHandler object used by this store. Initialized by
getSetupHandler(),
@@ -337,27 +333,41 @@
///// Special page functions /////
- public function getSpecialPageHandler() {
- if( $this->specialPageHandler == false )
- $this->specialPageHandler = new
SMWSQLStore3SpecialPageHandlers( $this );//Initialize if not done already
+ /**
+ * @see ContextAware::withContext
+ *
+ * @since 1.9
+ *
+ * @return ContextResource
+ */
+ protected function withContext() {
- return $this->specialPageHandler;
+ if ( $this->context === null ) {
+ $this->context = new \SMW\BaseContext();
+
$this->context->getDependencyBuilder()->getContainer()->registerObject(
'Store', $this );
+ }
+
+ return $this->context;
}
public function getPropertiesSpecial( $requestoptions = null ) {
- return $this->getSpecialPageHandler()->getPropertiesSpecial(
$requestoptions );
+ $collector = new \SMW\SQLStore\PropertiesCollector( wfGetDB(
DB_SLAVE ), $this->withContext() );
+ return $collector->setRequestOptions( $requestoptions );
}
public function getUnusedPropertiesSpecial( $requestoptions = null ) {
- return
$this->getSpecialPageHandler()->getUnusedPropertiesSpecial( $requestoptions );
+ $collector = new \SMW\SQLStore\UnusedPropertiesCollector(
wfGetDB( DB_SLAVE ), $this->withContext() );
+ return $collector->setRequestOptions( $requestoptions );
}
public function getWantedPropertiesSpecial( $requestoptions = null ) {
- return
$this->getSpecialPageHandler()->getWantedPropertiesSpecial( $requestoptions );
+ $collector = new \SMW\SQLStore\WantedPropertiesCollector(
wfGetDB( DB_SLAVE ), $this->withContext() );
+ return $collector->setRequestOptions( $requestoptions );
}
public function getStatistics() {
- return $this->getSpecialPageHandler()->getStatistics();
+ $collector = new \SMW\SQLStore\StatisticsCollector( wfGetDB(
DB_SLAVE ), $this->withContext() );
+ return $collector->getResults();
}
@@ -784,6 +794,8 @@
return self::$prop_tables;
}
+ // FIXME get the Settings from withContext() or better inject
the context
+ // to avoid having unilateral object invocations
$propertyTDBuilder = new
\SMW\SQLStore\PropertyTableDefinitionBuilder(
self::$di_type_tables,
self::$special_tables,
diff --git a/includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
b/includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
deleted file mode 100644
index 7d15609..0000000
--- a/includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
+++ /dev/null
@@ -1,96 +0,0 @@
-<?php
-/**
- * @file
- * @ingroup SMWStore
- * @since 1.8
- */
-
-/**
- * Class Handling all the Special Page methods for SMWSQLStore3
- *
- * @author Markus Krötzsch
- * @author Jeroen De Dauw
- * @author Nischay Nahata
- *
- * @since 1.8
- * @ingroup SMWStore
- */
-class SMWSQLStore3SpecialPageHandlers {
-
- /**
- * The store used by this specialPageHandler
- *
- * @since 1.8
- * @var SMWSQLStore3
- */
- protected $store;
-
-
- public function __construct( SMWSQLStore3 $parentstore ) {
- $this->store = $parentstore;
- }
-
- /**
- * Implementation of SMWStore::getPropertiesSpecial(). It works by
- * querying for all properties in the SMW IDs table (based on their
- * namespace) and getting their usage from the property statistics
- * table. When asking for unused properties, the result does not
- * include the usage count (which is always 0 then).
- *
- * @bug Properties that are used as super properties of others are
reported as unused now.
- *
- * FIXME: this method is doing to uch things. Getting unused properties
and getting usage counts
- * for all properties are two different tasks.
- *
- * @see SMWStore::getPropertiesSpecial()
- * @see SMWStore::getUnusedPropertiesSpecial()
- * @since 1.8
- * @param SMWRequestOptions $requestoptions
- * @param boolean $unusedProperties
- * @return array
- */
- public function getPropertiesSpecial( SMWRequestOptions $requestoptions
= null ) {
- return \SMW\SQLStore\PropertiesCollector::newFromStore(
$this->store )->setRequestOptions( $requestoptions );
- }
-
- /**
- * Implementation of SMWStore::getUnusedPropertiesSpecial(). It works by
- * calling getPropertiesSpecial() with additional parameters.
- *
- * @see SMWStore::getUnusedPropertiesSpecial()
- *
- * @since 1.8
- *
- * @param SMWRequestOptions $requestoptions
- *
- * @return Collector
- */
- public function getUnusedPropertiesSpecial( SMWRequestOptions
$requestoptions = null ) {
- return \SMW\SQLStore\UnusedPropertiesCollector::newFromStore(
$this->store )->setRequestOptions( $requestoptions );
- }
-
- /**
- * Implementation of SMWStore::getWantedPropertiesSpecial(). Like all
- * WantedFoo specials, this function is very resource intensive and
needs
- * to be cached on medium/large wikis.
- *
- * @param SMWRequestOptions $requestoptions
- *
- * @return Collector
- */
- public function getWantedPropertiesSpecial( $requestoptions = null ) {
- return \SMW\SQLStore\WantedPropertiesCollector::newFromStore(
$this->store )->setRequestOptions( $requestoptions );
- }
-
- /**
- * @see SMWStore::getStatistics
- * @see StatisticsCollector:getResults
- *
- * @return array
- */
- public function getStatistics() {
- // Until the settings object is invoke during Store setup, use
the factory method here
- return \SMW\SQLStore\StatisticsCollector::newFromStore(
$this->store )->getResults();
- }
-
-}
diff --git a/includes/storage/SQLStore/StatisticsCollector.php
b/includes/storage/SQLStore/StatisticsCollector.php
index 3d6930c..7366640 100644
--- a/includes/storage/SQLStore/StatisticsCollector.php
+++ b/includes/storage/SQLStore/StatisticsCollector.php
@@ -6,8 +6,6 @@
use SMW\SimpleDictionary;
use SMW\DIProperty;
-use SMW\Settings;
-use SMW\Store;
use DatabaseBase;
@@ -30,57 +28,6 @@
*/
class StatisticsCollector extends CacheableObjectCollector {
- /** @var Store */
- protected $store;
-
- /** @var Settings */
- protected $settings;
-
- /** @var DatabaseBase */
- protected $dbConnection;
-
- /**
- * // FIXME The store itself should know which database connection is
being
- * used therefore this info should come from the store object rather
than
- * doing an extra injection here
- *
- * @since 1.9
- *
- * @param Store $store
- * @param DatabaseBase $dbw
- * @param Settings $settings
- */
- public function __construct( Store $store, DatabaseBase $dbw, Settings
$settings ) {
- $this->store = $store;
- $this->dbConnection = $dbw;
- $this->settings = $settings;
- }
-
- /**
- * Factory method for an immediate instantiation of a
StatisticsCollector object
- *
- * @par Example:
- * @code
- * $statistics = \SMW\SQLStore\StatisticsCollector::newFromStore(
$store )
- * $statistics->getResults();
- * @endcode
- *
- * @since 1.9
- *
- * @param Store $store
- * @param $dbw Boolean or DatabaseBase:
- * - Boolean: whether to use a dedicated DB or Slave
- * - DatabaseBase: database connection to use
- *
- * @return StatisticsCollector
- */
- public static function newFromStore( Store $store, $dbw = false ) {
-
- $dbw = $dbw instanceof DatabaseBase ? $dbw : wfGetDB( DB_SLAVE
);
- $settings = Settings::newFromGlobals();
- return new self( $store, $dbw, $settings );
- }
-
/**
* @see CacheableObjectCollector::cacheSetup
*
@@ -89,11 +36,17 @@
* @return ObjectDictionary
*/
protected function cacheSetup() {
+
+ /**
+ * @var Settings $settings
+ */
+ $settings = $this->withContext()->getSettings();
+
return new SimpleDictionary( array(
'id' => array( 'smwgStatisticsCache',
$this->requestOptions ),
- 'type' => $this->settings->get( 'smwgCacheType' ),
- 'enabled' => $this->settings->get(
'smwgStatisticsCache' ),
- 'expiry' => $this->settings->get(
'smwgStatisticsCacheExpiry' )
+ 'type' => $settings->get( 'smwgCacheType' ),
+ 'enabled' => $settings->get( 'smwgStatisticsCache' ),
+ 'expiry' => $settings->get(
'smwgStatisticsCacheExpiry' )
) );
}
@@ -238,7 +191,7 @@
$count = 0;
$row = $this->dbConnection->selectRow(
- array( $this->store->getStatisticsTable() ),
+ array(
$this->withContext()->getStore()->getStatisticsTable() ),
'SUM( usage_count ) AS count',
array(),
__METHOD__
@@ -260,7 +213,7 @@
$count = 0;
$row = $this->dbConnection->selectRow(
- array( $this->store->getStatisticsTable() ),
+ array(
$this->withContext()->getStore()->getStatisticsTable() ),
'Count( * ) AS count',
array( 'usage_count > 0' ),
__METHOD__
diff --git a/includes/storage/SQLStore/UnusedPropertiesCollector.php
b/includes/storage/SQLStore/UnusedPropertiesCollector.php
index 0b50243..b67a807 100644
--- a/includes/storage/SQLStore/UnusedPropertiesCollector.php
+++ b/includes/storage/SQLStore/UnusedPropertiesCollector.php
@@ -7,14 +7,11 @@
use SMW\InvalidPropertyException;
use SMW\SimpleDictionary;
use SMW\DIProperty;
-use SMW\Settings;
use SMW\Profiler;
-use SMW\Store;
use SMWDIError;
use Message;
-use DatabaseBase;
/**
* Collects unused properties from a store entity
@@ -36,53 +33,6 @@
*/
class UnusedPropertiesCollector extends CacheableObjectCollector {
- /** @var Store */
- protected $store;
-
- /** @var Settings */
- protected $settings;
-
- /** @var DatabaseBase */
- protected $dbConnection;
-
- /**
- * @since 1.9
- *
- * @param Store $store
- * @param DatabaseBase $dbw
- * @param Settings $settings
- */
- public function __construct( Store $store, DatabaseBase $dbw, Settings
$settings ) {
- $this->store = $store;
- $this->dbConnection = $dbw;
- $this->settings = $settings;
- }
-
- /**
- * Factory method for an immediate instantiation of a
UnusedPropertiesCollector object
- *
- * @par Example:
- * @code
- * $properties =
\SMW\SQLStore\UnusedPropertiesCollector::newFromStore( $store )
- * $properties->getResults();
- * @endcode
- *
- * @since 1.9
- *
- * @param Store $store
- * @param $dbw Boolean or DatabaseBase:
- * - Boolean: whether to use a dedicated DB or Slave
- * - DatabaseBase: database connection to use
- *
- * @return ObjectCollector
- */
- public static function newFromStore( Store $store, $dbw = false ) {
-
- $dbw = $dbw instanceof DatabaseBase ? $dbw : wfGetDB( DB_SLAVE
);
- $settings = Settings::newFromGlobals();
- return new self( $store, $dbw, $settings );
- }
-
/**
* @see CacheableObjectCollector::cacheSetup
*
@@ -91,11 +41,17 @@
* @return ObjectDictionary
*/
protected function cacheSetup() {
+
+ /**
+ * @var Settings $settings
+ */
+ $settings = $this->withContext()->getSettings();
+
return new SimpleDictionary( array(
'id' => array( 'smwgUnusedPropertiesCache',
$this->requestOptions ),
- 'type' => $this->settings->get( 'smwgCacheType' ),
- 'enabled' => $this->settings->get(
'smwgUnusedPropertiesCache' ),
- 'expiry' => $this->settings->get(
'smwgUnusedPropertiesCacheExpiry' )
+ 'type' => $settings->get( 'smwgCacheType' ),
+ 'enabled' => $settings->get(
'smwgUnusedPropertiesCache' ),
+ 'expiry' => $settings->get(
'smwgUnusedPropertiesCacheExpiry' )
) );
}
@@ -108,6 +64,11 @@
*/
protected function doCollect() {
Profiler::In( __METHOD__ );
+
+ /**
+ * @var Store $store
+ */
+ $store = $this->withContext()->getStore();
$result = array();
@@ -129,12 +90,12 @@
$conditions['usage_count'] = 0;
$res = $this->dbConnection->select(
- array( $this->store->getObjectIds()->getIdTable(),
$this->store->getStatisticsTable() ),
+ array( $store->getObjectIds()->getIdTable(),
$store->getStatisticsTable() ),
array( 'smw_title', 'usage_count' ),
$conditions,
__METHOD__,
$options,
- array( $this->store->getObjectIds()->getIdTable() =>
array( 'INNER JOIN', array( 'smw_id=p_id' ) ) )
+ array( $store->getObjectIds()->getIdTable() => array(
'INNER JOIN', array( 'smw_id=p_id' ) ) )
);
foreach ( $res as $row ) {
diff --git a/includes/storage/SQLStore/WantedPropertiesCollector.php
b/includes/storage/SQLStore/WantedPropertiesCollector.php
index 3e56b8a..454784d 100644
--- a/includes/storage/SQLStore/WantedPropertiesCollector.php
+++ b/includes/storage/SQLStore/WantedPropertiesCollector.php
@@ -32,53 +32,6 @@
*/
class WantedPropertiesCollector extends CacheableObjectCollector {
- /** @var Store */
- protected $store;
-
- /** @var Settings */
- protected $settings;
-
- /** @var DatabaseBase */
- protected $dbConnection;
-
- /**
- * @since 1.9
- *
- * @param Store $store
- * @param DatabaseBase $dbw
- * @param Settings $settings
- */
- public function __construct( Store $store, DatabaseBase $dbw, Settings
$settings ) {
- $this->store = $store;
- $this->dbConnection = $dbw;
- $this->settings = $settings;
- }
-
- /**
- * Factory method for an immediate instantiation of a
WantedPropertiesCollector object
- *
- * @par Example:
- * @code
- * $properties =
\SMW\SQLStore\WantedPropertiesCollector::newFromStore( $store )
- * $properties->getResults();
- * @endcode
- *
- * @since 1.9
- *
- * @param Store $store
- * @param $dbw Boolean or DatabaseBase:
- * - Boolean: whether to use a dedicated DB or Slave
- * - DatabaseBase: database connection to use
- *
- * @return ObjectCollector
- */
- public static function newFromStore( Store $store, $dbw = false ) {
-
- $dbw = $dbw instanceof DatabaseBase ? $dbw : wfGetDB( DB_SLAVE
);
- $settings = Settings::newFromGlobals();
- return new self( $store, $dbw, $settings );
- }
-
/**
* @see CacheableObjectCollector::cacheSetup
*
@@ -87,11 +40,17 @@
* @return ObjectDictionary
*/
protected function cacheSetup() {
+
+ /**
+ * @var Settings $settings
+ */
+ $settings = $this->withContext()->getSettings();
+
return new SimpleDictionary( array(
- 'id' => array( 'smwgWantedPropertiesCache',
$this->settings->get( 'smwgPDefaultType' ), $this->requestOptions ),
- 'type' => $this->settings->get( 'smwgCacheType' ),
- 'enabled' => $this->settings->get(
'smwgWantedPropertiesCache' ),
- 'expiry' => $this->settings->get(
'smwgWantedPropertiesCacheExpiry' )
+ 'id' => array( 'smwgWantedPropertiesCache',
$settings->get( 'smwgPDefaultType' ), $this->requestOptions ),
+ 'type' => $settings->get( 'smwgCacheType' ),
+ 'enabled' => $settings->get(
'smwgWantedPropertiesCache' ),
+ 'expiry' => $settings->get(
'smwgWantedPropertiesCacheExpiry' )
) );
}
@@ -107,7 +66,7 @@
$result = array();
// Wanted Properties must have the default type
- $this->propertyTables = $this->getPropertyTables(
$this->settings->get( 'smwgPDefaultType' ) );
+ $this->propertyTables = $this->getPropertyTables(
$this->withContext()->getSettings()->get( 'smwgPDefaultType' ) );
// anything else would be crazy, but let's fail gracefully even
if the whole world is crazy
if ( !$this->propertyTables->isFixedPropertyTable() ) {
@@ -130,15 +89,20 @@
protected function doQuery() {
Profiler::In( __METHOD__ );
+ /**
+ * @var Store $store
+ */
+ $store = $this->withContext()->getStore();
+
$result = array();
- $options = $this->store->getSQLOptions( $this->requestOptions,
'title' );
+ $options = $store->getSQLOptions( $this->requestOptions,
'title' );
$options['ORDER BY'] = 'count DESC';
// TODO: this is not how JOINS should be specified in the
select function
$res = $this->dbConnection->select(
$this->dbConnection->tableName(
$this->propertyTables->getName() ) . ' INNER JOIN ' .
- $this->dbConnection->tableName(
$this->store->getObjectIds()->getIdTable() ) . ' ON p_id=smw_id LEFT JOIN ' .
+ $this->dbConnection->tableName(
$store->getObjectIds()->getIdTable() ) . ' ON p_id=smw_id LEFT JOIN ' .
$this->dbConnection->tableName( 'page' ) . ' ON
(page_namespace=' .
$this->dbConnection->addQuotes( SMW_NS_PROPERTY
) . ' AND page_title=smw_title)',
'smw_title, COUNT(*) as count',
diff --git a/tests/phpunit/MockObjectRepository.php
b/tests/phpunit/MockObjectRepository.php
index bf7abd7..372869e 100644
--- a/tests/phpunit/MockObjectRepository.php
+++ b/tests/phpunit/MockObjectRepository.php
@@ -100,6 +100,7 @@
}
$collector = $this->getMockBuilder(
'\SMW\Store\CacheableObjectCollector' )
+ ->disableOriginalConstructor()
->setMethods( $methods )
->getMock();
diff --git a/tests/phpunit/includes/storage/CacheableObjectCollectorTest.php
b/tests/phpunit/includes/storage/CacheableObjectCollectorTest.php
index 8a0c5fa..19cae76 100644
--- a/tests/phpunit/includes/storage/CacheableObjectCollectorTest.php
+++ b/tests/phpunit/includes/storage/CacheableObjectCollectorTest.php
@@ -45,7 +45,7 @@
*
* @return CacheableObjectCollector
*/
- private function getInstance( $doCollect = array(), $cacheSetup =
array() ) {
+ private function newInstance( $doCollect = array(), $cacheSetup =
array() ) {
$collector = $this->newMockBuilder()->newObject(
'CacheableObjectCollector', array(
'doCollect' => $doCollect,
@@ -61,7 +61,7 @@
* @since 1.9
*/
public function testConstructor() {
- $this->assertInstanceOf( $this->getClass(),
$this->getInstance() );
+ $this->assertInstanceOf( $this->getClass(),
$this->newInstance() );
}
/**
@@ -72,7 +72,7 @@
*/
public function testGetResults( $setup, $expected ) {
- $instance = $this->getInstance( $setup['test'],
$setup['cacheSetup'] );
+ $instance = $this->newInstance( $setup['test'],
$setup['cacheSetup'] );
$instance->setRequestOptions( new SMWRequestOptions() );
$result = $instance->getResults();
diff --git
a/tests/phpunit/includes/storage/sqlstore/PropertiesCollectorTest.php
b/tests/phpunit/includes/storage/sqlstore/PropertiesCollectorTest.php
index 616291b..1887c73 100644
--- a/tests/phpunit/includes/storage/sqlstore/PropertiesCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/PropertiesCollectorTest.php
@@ -4,8 +4,7 @@
use SMW\SQLStore\PropertiesCollector;
-use SMW\Test\SemanticMediaWikiTestCase;
-
+use SMw\BaseContext;
use SMW\MessageFormatter;
use SMW\StoreFactory;
use SMW\DIProperty;
@@ -35,7 +34,7 @@
* @group SMW
* @group SMWExtension
*/
-class PropertiesCollectorTest extends SemanticMediaWikiTestCase {
+class PropertiesCollectorTest extends \SMW\Test\SemanticMediaWikiTestCase {
/**
* Returns the name of the class to be tested
@@ -102,7 +101,11 @@
'smwgPropertiesCacheExpiry' => 360,
) );
- return new PropertiesCollector( $mockStore, $connection,
$settings );
+ $context = new BaseContext();
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings',
$settings );
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Store',
$mockStore );
+
+ return new PropertiesCollector( $connection, $context );
}
/**
@@ -112,16 +115,6 @@
*/
public function testConstructor() {
$this->assertInstanceOf( $this->getClass(),
$this->newInstance() );
- }
-
- /**
- * @test PropertiesCollector::newFromStore
- *
- * @since 1.9
- */
- public function testNewFromStore() {
- $instance = PropertiesCollector::newFromStore(
StoreFactory::getStore() );
- $this->assertInstanceOf( $this->getClass(), $instance );
}
/**
diff --git
a/tests/phpunit/includes/storage/sqlstore/SpecialPageHandlersTest.php
b/tests/phpunit/includes/storage/sqlstore/SpecialPageHandlersTest.php
deleted file mode 100644
index 6f24ae7..0000000
--- a/tests/phpunit/includes/storage/sqlstore/SpecialPageHandlersTest.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-
-namespace SMW\Test\SQLStore;
-
-use SMW\Store;
-use SMW\Test\SemanticMediaWikiTestCase;
-use SMWSQLStore3SpecialPageHandlers;
-
-/**
- * Tests for the SMWSQLStore3SpecialPageHandlers class
- *
- * @since 1.9
- *
- * @file
- * @ingroup Store
- * @ingroup Test
- *
- * @licence GNU GPL v2+
- * @author mwjames
- */
-
-/**
- * Tests for the SMWSQLStore3SpecialPageHandlers class
- *
- * @ingroup Test
- *
- * @group SMW
- * @group SMWExtension
- */
-class SpecialPageHandlersTest extends SemanticMediaWikiTestCase {
-
- /**
- * Returns the name of the class to be tested
- *
- * @return string|false
- */
- public function getClass() {
- return '\SMWSQLStore3SpecialPageHandlers';
- }
-
- /**
- * Helper method that returns a Store object
- *
- * @since 1.9
- *
- * @return Store
- */
- private function getStore() {
-
- // FIXME Use StoreFactory::getStore()
- return smwfGetStore();
- }
-
- /**
- * Helper method that returns a SMWSQLStore3SpecialPageHandlers object
- *
- * @param Store $store
- *
- * @return SMWSQLStore3SpecialPageHandlers
- */
- private function getInstance( $store ) {
- return new SMWSQLStore3SpecialPageHandlers( $store );
- }
-
- /**
- * @test SMWSQLStore3SpecialPageHandlers::__construct
- *
- * @since 1.9
- */
- public function testConstructor() {
- $instance = $this->getInstance( $this->getStore() );
- $this->assertInstanceOf( $this->getClass(), $instance );
- }
-
- /**
- * @test SMWSQLStore3SpecialPageHandlers::getStatistics
- *
- * @since 1.9
- */
- public function testGetStatistics() {
- $instance = $this->getInstance( $this->getStore() );
- $this->assertInternalType( 'array', $instance->getStatistics()
);
- }
-}
diff --git
a/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
b/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
index 8f09aad..c198a9b 100644
--- a/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
@@ -3,6 +3,7 @@
namespace SMW\Test\SQLStore;
use SMW\SQLStore\StatisticsCollector;
+use SMW\BaseContext;
use SMW\StoreFactory;
use SMW\Settings;
use SMW\Store;
@@ -90,7 +91,11 @@
'smwgStatisticsCacheExpiry' => 3600
) );
- return new StatisticsCollector( $store, $connection, $settings
);
+ $context = new BaseContext();
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings',
$settings );
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Store',
$store );
+
+ return new StatisticsCollector( $connection, $context );
}
/**
@@ -99,18 +104,7 @@
* @since 1.9
*/
public function testConstructor() {
- $instance = $this->newInstance();
- $this->assertInstanceOf( $this->getClass(), $instance );
- }
-
- /**
- * @test StatisticsCollector::newFromStore
- *
- * @since 1.9
- */
- public function testNewFromStore() {
- $instance = StatisticsCollector::newFromStore(
StoreFactory::getStore() );
- $this->assertInstanceOf( $this->getClass(), $instance );
+ $this->assertInstanceOf( $this->getClass(),
$this->newInstance() );
}
/**
diff --git
a/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
b/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
index e166b2f..d53940d 100644
--- a/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
@@ -4,6 +4,7 @@
use SMW\SQLStore\UnusedPropertiesCollector;
+use SMW\BaseContext;
use SMW\MessageFormatter;
use SMW\StoreFactory;
use SMW\DIProperty;
@@ -90,7 +91,11 @@
'smwgUnusedPropertiesCacheExpiry' => 360,
) );
- return new UnusedPropertiesCollector( $mockStore, $connection,
$settings );
+ $context = new BaseContext();
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings',
$settings );
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Store',
$mockStore );
+
+ return new UnusedPropertiesCollector( $connection, $context );
}
/**
@@ -99,18 +104,7 @@
* @since 1.9
*/
public function testConstructor() {
- $instance = $this->newInstance();
- $this->assertInstanceOf( $this->getClass(), $instance );
- }
-
- /**
- * @test UnusedPropertiesCollector::newFromStore
- *
- * @since 1.9
- */
- public function testNewFromStore() {
- $instance = UnusedPropertiesCollector::newFromStore(
StoreFactory::getStore() );
- $this->assertInstanceOf( $this->getClass(), $instance );
+ $this->assertInstanceOf( $this->getClass(),
$this->newInstance() );
}
/**
diff --git
a/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
b/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
index 805e72c..e0fb9cb 100644
--- a/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
@@ -5,7 +5,7 @@
use SMW\SQLStore\WantedPropertiesCollector;
use SMW\StoreFactory;
use SMW\DIProperty;
-use SMW\Settings;
+use SMW\BaseContext;
use SMWRequestOptions;
@@ -93,7 +93,11 @@
'smwgWantedPropertiesCacheExpiry' => 360,
) );
- return new WantedPropertiesCollector( $store, $connection,
$settings );
+ $context = new BaseContext();
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings',
$settings );
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Store',
$store );
+
+ return new WantedPropertiesCollector( $connection, $context );
}
/**
@@ -102,18 +106,7 @@
* @since 1.9
*/
public function testConstructor() {
- $instance = $this->newInstance();
- $this->assertInstanceOf( $this->getClass(), $instance );
- }
-
- /**
- * @test WantedPropertiesCollector::newFromStore
- *
- * @since 1.9
- */
- public function testNewFromStore() {
- $instance = WantedPropertiesCollector::newFromStore(
smwfGetStore() );
- $this->assertInstanceOf( $this->getClass(), $instance );
+ $this->assertInstanceOf( $this->getClass(),
$this->newInstance() );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/86893
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5a1238ee7534655e68608bdd75ca1f6742a6cddc
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