Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92479
Change subject: Improve coverage on WantedPropertiesCollectorTest
......................................................................
Improve coverage on WantedPropertiesCollectorTest
Change-Id: I5386d344e5e4a41568e18e7370459459a1b76af3
---
M tests/phpunit/MockObjectRepository.php
M tests/phpunit/SemanticMediaWikiTestCase.php
M tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
3 files changed, 121 insertions(+), 143 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/79/92479/1
diff --git a/tests/phpunit/MockObjectRepository.php
b/tests/phpunit/MockObjectRepository.php
index 8e78839..79bb0cc 100644
--- a/tests/phpunit/MockObjectRepository.php
+++ b/tests/phpunit/MockObjectRepository.php
@@ -47,34 +47,13 @@
->disableOriginalConstructor()
->getMock();
- $semanticData->expects( $this->any() )
- ->method( 'getSubject' )
- ->will( $this->returnValue( $this->builder->setValue(
'getSubject' ) ) );
+ foreach ( $this->builder->getInvokedMethods() as $method ) {
- // array of SMWDataItem
- $semanticData->expects( $this->any() )
- ->method( 'getPropertyValues' )
- ->will( $this->returnValue( $this->builder->setValue(
'getPropertyValues' ) ) );
+ $semanticData->expects( $this->any() )
+ ->method( $method )
+ ->will( $this->builder->setCallback( $method )
);
- $semanticData->expects( $this->any() )
- ->method( 'hasVisibleSpecialProperties' )
- ->will( $this->returnValue( $this->builder->setValue(
'hasVisibleSpecialProperties' ) ) );
-
- $semanticData->expects( $this->any() )
- ->method( 'hasVisibleProperties' )
- ->will( $this->returnValue( $this->builder->setValue(
'hasVisibleProperties' ) ) );
-
- $semanticData->expects( $this->any() )
- ->method( 'getProperties' )
- ->will( $this->returnValue( $this->builder->setValue(
'getProperties' ) ) );
-
- $semanticData->expects( $this->any() )
- ->method( 'isEmpty' )
- ->will( $this->returnValue( $this->builder->setValue(
'isEmpty' ) ) );
-
- $semanticData->expects( $this->any() )
- ->method( 'addPropertyObjectValue' )
- ->will( $this->builder->setCallback(
'addPropertyObjectValue' ) );
+ }
return $semanticData;
}
@@ -549,6 +528,36 @@
// SMW\Store is an abstract class, use setMethods to implement
// required abstract methods
+ $requiredAbstractMethods = array(
+ 'setup',
+ 'drop',
+ 'getStatisticsTable',
+ 'getObjectIds',
+ 'refreshData',
+ 'getStatistics',
+ 'getQueryResult',
+ 'getPropertiesSpecial',
+ 'getUnusedPropertiesSpecial',
+ 'getWantedPropertiesSpecial',
+ 'getPropertyTables',
+ 'deleteSubject',
+ 'doDataUpdate',
+ 'changeTitle',
+ 'getProperties',
+ 'getInProperties',
+ 'getAllPropertySubjects',
+ 'getSQLConditions',
+ 'getSemanticData',
+ 'getPropertyValues',
+ 'getPropertySubjects',
+ 'refreshConceptCache',
+ 'deleteConceptCache',
+ 'getConceptCacheStatus',
+ 'clearData',
+ 'updateData'
+ );
+
+ $methods = array_unique( array_merge( $requiredAbstractMethods,
$this->builder->getInvokedMethods() ) );
$idTable = $this->getMock( 'stdClass', array( 'getIdTable') );
@@ -558,114 +567,8 @@
$store = $this->getMockBuilder( '\SMW\Store' )
->disableOriginalConstructor()
- ->setMethods( array(
- 'setup',
- 'drop',
- 'getStatisticsTable',
- 'getObjectIds',
- 'refreshData',
- 'getStatistics',
- 'getQueryResult',
- 'getPropertiesSpecial',
- 'getUnusedPropertiesSpecial',
- 'getWantedPropertiesSpecial',
- 'getPropertyTables',
- 'deleteSubject',
- 'doDataUpdate',
- 'changeTitle',
- 'getProperties',
- 'getInProperties',
- 'getAllPropertySubjects',
- 'getSQLConditions',
- 'getSemanticData',
- 'getPropertyValues',
- 'getPropertySubjects',
- 'refreshConceptCache',
- 'deleteConceptCache',
- 'getConceptCacheStatus',
- 'clearData',
- 'updateData'
- ) )
+ ->setMethods( $methods )
->getMock();
-
- /**
- * @param $subject mixed SMWDIWikiPage or null
- * @param $property SMWDIProperty
- * @param $requestoptions SMWRequestOptions
- *
- * @return array of SMWDataItem
- */
- $store->expects( $this->any() )
- ->method( 'getPropertyValues' )
- ->will( $this->builder->setCallback(
'getPropertyValues' ) );
-
- $store->expects( $this->any() )
- ->method( 'getPropertiesSpecial' )
- ->will( $this->returnValue( $this->builder->setValue(
'getPropertiesSpecial' ) ) );
-
- $store->expects( $this->any() )
- ->method( 'deleteSubject' )
- ->will( $this->returnValue( $this->builder->setValue(
'deleteSubject' ) ) );
-
- $store->expects( $this->any() )
- ->method( 'getSemanticData' )
- ->will( $this->builder->setCallback( 'getSemanticData'
) );
-
- $store->expects( $this->any() )
- ->method( 'refreshData' )
- ->will( $this->builder->setCallback( 'refreshData' ) );
-
- $store->expects( $this->any() )
- ->method( 'getUnusedPropertiesSpecial' )
- ->will( $this->returnValue( $this->builder->setValue(
'getUnusedPropertiesSpecial' ) ) );
-
- $store->expects( $this->any() )
- ->method( 'getWantedPropertiesSpecial' )
- ->will( $this->returnValue( $this->builder->setValue(
'getWantedPropertiesSpecial' ) ) );
-
- $store->expects( $this->any() )
- ->method( 'getSQLConditions' )
- ->will( $this->returnValue( $this->builder->setValue(
'getSQLConditions' ) ) );
-
- $store->expects( $this->any() )
- ->method( 'getStatistics' )
- ->will( $this->returnValue( $this->builder->setValue(
'getStatistics' ) ) );
-
- $store->expects( $this->any() )
- ->method( 'getPropertyTables' )
- ->will( $this->returnValue( $this->builder->setValue(
'getPropertyTables' ) ) );
-
- $store->expects( $this->any() )
- ->method( 'getQueryResult' )
- ->will( $this->builder->setCallback( 'getQueryResult' )
);
-
- $store->expects( $this->any() )
- ->method( 'updateData' )
- ->will( $this->builder->setCallback( 'updateData' ) );
-
- $store->expects( $this->any() )
- ->method( 'clearData' )
- ->will( $this->builder->setCallback( 'clearData' ) );
-
- $store->expects( $this->any() )
- ->method( 'getAllPropertySubjects' )
- ->will( $this->builder->setCallback(
'getAllPropertySubjects' ) );
-
- $store->expects( $this->any() )
- ->method( 'getPropertySubjects' )
- ->will( $this->builder->setCallback(
'getPropertySubjects' ) );
-
- $store->expects( $this->any() )
- ->method( 'refreshConceptCache' )
- ->will( $this->builder->setCallback(
'refreshConceptCache' ) );
-
- $store->expects( $this->any() )
- ->method( 'deleteConceptCache' )
- ->will( $this->builder->setCallback(
'deleteConceptCache' ) );
-
- $store->expects( $this->any() )
- ->method( 'getConceptCacheStatus' )
- ->will( $this->builder->setCallback(
'getConceptCacheStatus' ) );
$store->expects( $this->any() )
->method( 'getObjectIds' )
@@ -675,10 +578,42 @@
->method( 'getStatisticsTable' )
->will( $this->returnValue( 'smw_statistics_table_test'
) );
+ foreach ( $this->builder->getInvokedMethods() as $method ) {
+
+ $store->expects( $this->any() )
+ ->method( $method )
+ ->will( $this->builder->setCallback( $method )
);
+
+ }
+
return $store;
}
/**
+ * Returns a TableDefinition object
+ *
+ * @since 1.9
+ *
+ * @return TableDefinition
+ */
+ public function SQLStoreTableDefinition() {
+
+ $tableDefinition = $this->getMockBuilder(
'SMW\SQLStore\TableDefinition' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ foreach ( $this->builder->getInvokedMethods() as $method ) {
+
+ $tableDefinition->expects( $this->any() )
+ ->method( $method )
+ ->will( $this->builder->setCallback( $method )
);
+
+ }
+
+ return $tableDefinition;
+ }
+
+ /**
* Returns a SMWDIError object
*
* @since 1.9
diff --git a/tests/phpunit/SemanticMediaWikiTestCase.php
b/tests/phpunit/SemanticMediaWikiTestCase.php
index 9e62134..ef2c3ea 100644
--- a/tests/phpunit/SemanticMediaWikiTestCase.php
+++ b/tests/phpunit/SemanticMediaWikiTestCase.php
@@ -5,6 +5,7 @@
use SMW\SimpleDependencyBuilder;
use SMW\DependencyContainer;
use SMW\DataValueFactory;
+use SMW\StoreFactory;
use SMW\SemanticData;
use SMW\DIWikiPage;
use SMW\DIProperty;
@@ -255,9 +256,13 @@
*
* @since 1.9
*/
- protected function runOnlyOnSQLStore() {
+ protected function runOnlyOnSQLStore( $store = null ) {
- if ( !( \SMW\StoreFactory::getStore() instanceof \SMWSQLStore3
) ) {
+ if ( $store === null ) {
+ $store = StoreFactory::getStore();
+ }
+
+ if ( !( $store instanceof \SMWSQLStore3 ) ) {
$this->markTestSkipped( 'Test only applicable to
SMWSQLStore3' );
}
diff --git
a/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
b/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
index 7a26c5e..88f1b14 100644
--- a/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
@@ -62,9 +62,12 @@
*
* @return WantedPropertiesCollector
*/
- private function newInstance( $property = 'Foo', $count = 1,
$cacheEnabled = false ) {
+ private function newInstance( $store = null, $property = 'Foo', $count
= 1, $cacheEnabled = false ) {
- $store = StoreFactory::getStore( 'SMWSQLStore3' );
+ if ( $store === null ) {
+ $store = $this->newMockBuilder()->newObject( 'Store' );
+ }
+
$connection = $this->getMockDBConnection( $property, $count );
$settings = $this->newSettings( array(
@@ -87,13 +90,15 @@
/**
* @since 1.9
*/
- public function testGetResults() {
+ public function testGetResultsOnSQLStore() {
+
+ $store = StoreFactory::getStore( 'SMWSQLStore3' );
$count = rand();
- $property = $this->getRandomString();
+ $property = $this->newRandomString();
$expected = array( array( new DIProperty( $property ), $count )
);
- $instance = $this->newInstance( $property, $count );
+ $instance = $this->newInstance( $store, $property, $count );
$instance->setRequestOptions(
new SMWRequestOptions( $property,
SMWRequestOptions::STRCOND_PRE )
);
@@ -104,14 +109,46 @@
}
/**
+ * @since 1.9
+ */
+ public function testIsFixedPropertyTableOnSQLMockStore() {
+
+ $tableDefinition = $this->newMockBuilder()->newObject(
'SQLStoreTableDefinition', array(
+ 'isFixedPropertyTable' => true
+ ) );
+
+ $store = $this->newMockBuilder()->newObject( 'Store', array(
+ 'getPropertyTables' => array( 'Foo' => $tableDefinition
),
+ 'findTypeTableId' => 'Foo'
+ ) );
+
+ $result = $this->newInstance( $store )->runCollector();
+
+ $this->assertInternalType(
+ 'array',
+ $result,
+ 'Asserts that runCollector() returns an array'
+ );
+
+ $this->assertEmpty(
+ $result,
+ 'Asserts that runCollector() returns an empty array'
+ );
+
+ }
+
+ /**
* @dataProvider getCacheNonCacheDataProvider
*
* @since 1.9
*/
- public function testCacheNoCache( array $test, array $expected, array
$info ) {
+ public function testCacheNoCacheOnSQLStore( array $test, array
$expected, array $info ) {
+
+ $store = StoreFactory::getStore( 'SMWSQLStore3' );
// Sample A
$instance = $this->newInstance(
+ $store,
$test['A']['property'],
$test['A']['count'],
$test['cacheEnabled']
@@ -121,6 +158,7 @@
// Sample B
$instance = $this->newInstance(
+ $store,
$test['B']['property'],
$test['B']['count'],
$test['cacheEnabled']
@@ -134,8 +172,8 @@
* @return array
*/
public function getCacheNonCacheDataProvider() {
- $propertyA = $this->getRandomString();
- $propertyB = $this->getRandomString();
+ $propertyA = $this->newRandomString();
+ $propertyB = $this->newRandomString();
$countA = rand();
$countB = rand();
--
To view, visit https://gerrit.wikimedia.org/r/92479
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5386d344e5e4a41568e18e7370459459a1b76af3
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