jenkins-bot has submitted this change and it was merged.

Change subject: Extend \SMW\Test\MockObjectBuilder
......................................................................


Extend \SMW\Test\MockObjectBuilder

* Extend available mock objects
* Use FakeResultWrapper for DB return results

Change-Id: I87561dfa930bb99af30c6122824ac3d9c516d112
---
M includes/SMW_QueryPage.php
M includes/storage/Collector.php
M includes/storage/SQLStore/StatisticsCollector.php
M includes/storage/SQLStore/UnusedPropertiesCollector.php
M includes/storage/SQLStore/WantedPropertiesCollector.php
M tests/phpunit/ApiTestCase.php
M tests/phpunit/MockObjectBuilder.php
M tests/phpunit/SemanticMediaWikiTestCase.php
M tests/phpunit/includes/QueryPageTest.php
M tests/phpunit/includes/api/ApiAskTest.php
M tests/phpunit/includes/api/ApiQueryTest.php
M tests/phpunit/includes/specials/UnusedPropertiesPageTest.php
M tests/phpunit/includes/specials/WantedPropertiesPageTest.php
M tests/phpunit/includes/storage/CollectorTest.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
17 files changed, 443 insertions(+), 286 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/SMW_QueryPage.php b/includes/SMW_QueryPage.php
index 81ca50c..100683c 100644
--- a/includes/SMW_QueryPage.php
+++ b/includes/SMW_QueryPage.php
@@ -48,10 +48,12 @@
         * @return array
         */
        public function linkParameters() {
-               $parameters = array();
 
-               if ( $this->getRequest()->getCheck( 'property' ) ) {
-                       $parameters['property'] = $this->getRequest()->getVal( 
'property' );
+               $parameters = array();
+               $property   = $this->getRequest()->getVal( 'property' );
+
+               if ( $property !== null && $property !== '' ) {
+                       $parameters['property'] = $property;
                }
 
                return $parameters;
diff --git a/includes/storage/Collector.php b/includes/storage/Collector.php
index 0401c36..5e0ff85 100644
--- a/includes/storage/Collector.php
+++ b/includes/storage/Collector.php
@@ -29,11 +29,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 interface Collectible {}
@@ -41,6 +41,7 @@
 /**
  * Collector base class
  *
+ * @ingroup Collector
  * @ingroup Store
  */
 abstract class Collector implements Collectible {
@@ -143,7 +144,18 @@
        protected abstract function doCollect();
 
        /**
-        * Sub-class is responsible for returning a ArrayAccessor object
+        * Sub-class is returning an ArrayAccessor object necessary for
+        * the ResultCacheMapper instantiation
+        *
+        * @par Example:
+        * @code
+        *  return new ArrayAccessor( array(
+        *   'id'      => 'smwgPropertiesCache' . <...>,
+        *   'type'    => $this->settings->get( 'smwgCacheType' ),
+        *   'enabled' => $this->settings->get( 'smwgPropertiesCache' ),
+        *   'expiry'  => $this->settings->get( 'smwgPropertiesCacheExpiry' )
+        *  ) );
+        * @endcode
         *
         * @since 1.9
         *
diff --git a/includes/storage/SQLStore/StatisticsCollector.php 
b/includes/storage/SQLStore/StatisticsCollector.php
index 3b70ac8..5d79fe7 100644
--- a/includes/storage/SQLStore/StatisticsCollector.php
+++ b/includes/storage/SQLStore/StatisticsCollector.php
@@ -29,11 +29,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
diff --git a/includes/storage/SQLStore/UnusedPropertiesCollector.php 
b/includes/storage/SQLStore/UnusedPropertiesCollector.php
index ee152af..4c89192 100644
--- a/includes/storage/SQLStore/UnusedPropertiesCollector.php
+++ b/includes/storage/SQLStore/UnusedPropertiesCollector.php
@@ -34,11 +34,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  * @author Nischay Nahata
  */
diff --git a/includes/storage/SQLStore/WantedPropertiesCollector.php 
b/includes/storage/SQLStore/WantedPropertiesCollector.php
index 5924fbb..2efa58a 100644
--- a/includes/storage/SQLStore/WantedPropertiesCollector.php
+++ b/includes/storage/SQLStore/WantedPropertiesCollector.php
@@ -30,11 +30,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  * @author Nischay Nahata
  */
diff --git a/tests/phpunit/ApiTestCase.php b/tests/phpunit/ApiTestCase.php
index b70020c..73b5275 100644
--- a/tests/phpunit/ApiTestCase.php
+++ b/tests/phpunit/ApiTestCase.php
@@ -23,11 +23,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -46,7 +46,7 @@
         * @return ApiMain
         */
        protected function getApiMain( array $params ) {
-               return new ApiMain( $this->getContext( $params ), true );
+               return new ApiMain( $this->newContext( $params ), true );
        }
 
        /**
diff --git a/tests/phpunit/MockObjectBuilder.php 
b/tests/phpunit/MockObjectBuilder.php
index c6a9057..738b409 100644
--- a/tests/phpunit/MockObjectBuilder.php
+++ b/tests/phpunit/MockObjectBuilder.php
@@ -3,6 +3,7 @@
 namespace SMW\Test;
 
 use SMW\ArrayAccessor;
+use SMWDataItem;
 
 /**
  * MockObject builder
@@ -22,11 +23,12 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
+ * @author mwjames
  */
 
 /**
@@ -54,14 +56,17 @@
        }
 
        /**
-        * Check and return an invoked object
+        * Sets value
         *
         * @since 1.9
         *
+        * @param $key
+        * @param $default
+        *
         * @return mixed|null
         */
-       protected function get( $key ) {
-               return $this->accessor->has( $key ) ? $this->accessor->get( 
$key ) : null;
+       protected function set( $key, $default = null ) {
+               return $this->accessor->has( $key ) ? $this->accessor->get( 
$key ) : $default;
        }
 
        /**
@@ -79,17 +84,245 @@
 
                $queryResult->expects( $this->any() )
                        ->method( 'toArray' )
-                       ->will( $this->returnValue( $this->get( 'toArray' ) ) );
+                       ->will( $this->returnValue( $this->set( 'toArray' ) ) );
 
                $queryResult->expects( $this->any() )
                        ->method( 'getErrors' )
-                       ->will( $this->returnValue( $this->get( 'getErrors' ) ) 
);
+                       ->will( $this->returnValue( $this->set( 'getErrors' ) ) 
);
 
                $queryResult->expects( $this->any() )
                        ->method( 'hasFurtherResults' )
-                       ->will( $this->returnValue( $this->get( 
'hasFurtherResults' ) ) );
+                       ->will( $this->returnValue( $this->set( 
'hasFurtherResults' ) ) );
 
                return $queryResult;
        }
 
+       /**
+        * Helper method that returns a DIWikiPage object
+        *
+        * @since 1.9
+        *
+        * @return DIWikiPage
+        */
+       public function getMockDIWikiPage() {
+
+               $diWikiPage = $this->getMockBuilder( '\SMW\DIWikiPage' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $diWikiPage->expects( $this->any() )
+                       ->method( 'getTitle' )
+                       ->will( $this->returnValue( $this->set( 'getTitle' ) ) 
);
+
+               $diWikiPage->expects( $this->any() )
+                       ->method( 'getDIType' )
+                       ->will( $this->returnValue( SMWDataItem::TYPE_WIKIPAGE 
) );
+
+               $diWikiPage->expects( $this->any() )
+                       ->method( 'findPropertyTypeID' )
+                       ->will( $this->returnValue( $this->set( 
'findPropertyTypeID', '_wpg' ) ) );
+
+               return $diWikiPage;
+       }
+
+       /**
+        * Returns a DIProperty object
+        *
+        * @par Example:
+        * @code
+        *  $property = array(
+        *   'isUserDefined' => $isUserDefined,
+        *   'getDiWikiPage' => $this->getMockDIWikiPage( true ),
+        *   'getLabel'      => $this->getRandomString(),
+        *  );
+        *
+        *  $mockObject = new MockObjectBuilder( new ArrayAccessor( $property ) 
);
+        *  $mockObject->getMockDIProperty();
+        * @endcode
+        *
+        * @since 1.9
+        *
+        * @return DIProperty
+        */
+       public function getMockDIProperty() {
+
+               $property = $this->getMockBuilder( '\SMW\DIProperty' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $property->expects( $this->any() )
+                       ->method( 'isUserDefined' )
+                       ->will( $this->returnValue( $this->set( 'isUserDefined' 
) ) );
+
+               $property->expects( $this->any() )
+                       ->method( 'getDiWikiPage' )
+                       ->will( $this->returnValue( $this->set( 'getDiWikiPage' 
) ) );
+
+               $property->expects( $this->any() )
+                       ->method( 'findPropertyTypeID' )
+                       ->will( $this->returnValue( $this->set( 
'findPropertyTypeID', '_wpg' ) ) );
+
+               $property->expects( $this->any() )
+                       ->method( 'getKey' )
+                       ->will( $this->returnValue( $this->set( 'getKey', 
'_wpg' ) ) );
+
+               $property->expects( $this->any() )
+                       ->method( 'getDIType' )
+                       ->will( $this->returnValue( SMWDataItem::TYPE_PROPERTY 
) );
+
+               $property->expects( $this->any() )
+                       ->method( 'getLabel' )
+                       ->will( $this->returnValue( $this->set( 'getLabel' ) ) 
);
+
+               return $property;
+       }
+
+       /**
+        * Returns a Store object
+        *
+        * @note MockStore is based on the abstract Store class which avoids
+        * dependency on a specific Store implementation (SQLStore etc.), the 
mock
+        * object will allow to override necessary methods
+        *
+        * @since 1.9
+        *
+        * @return Store
+        */
+       public function getMockStore( ) {
+
+               $idTable = $this->getMock( 'stdClass', array( 'getIdTable') );
+
+               $idTable->expects( $this->any() )
+                       ->method( 'getIdTable' )
+                       ->will( $this->returnValue( 'smw_id_table_test' ) );
+
+               $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'
+                       ) )
+                       ->getMock();
+
+               $store->expects( $this->any() )
+                       ->method( 'getPropertyValues' )
+                       ->will( $this->returnValue( $this->set( 
'getPropertyValues' ) ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getPropertiesSpecial' )
+                       ->will( $this->returnValue( $this->set( 
'getPropertiesSpecial' ) ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getUnusedPropertiesSpecial' )
+                       ->will( $this->returnValue( $this->set( 
'getUnusedPropertiesSpecial' ) ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getWantedPropertiesSpecial' )
+                       ->will( $this->returnValue( $this->set( 
'getWantedPropertiesSpecial' ) ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getSQLConditions' )
+                       ->will( $this->returnValue( $this->set( 
'getSQLConditions' ) ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getPropertyTables' )
+                       ->will( $this->returnValue( $this->set( 
'getPropertyTables' ) ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getObjectIds' )
+                       ->will( $this->returnValue( $idTable ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getStatisticsTable' )
+                       ->will( $this->returnValue( 'smw_statistics_table_test' 
) );
+
+               return $store;
+       }
+
+       /**
+        * Returns a SMWDIError object
+        *
+        * @since 1.9
+        *
+        * @return SMWDIError
+        */
+       public function getMockDIError() {
+
+               $errors = $this->getMockBuilder( 'SMWDIError' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $errors->expects( $this->any() )
+                       ->method( 'getErrors' )
+                       ->will( $this->returnValue( $this->set( 'getErrors' ) ) 
);
+
+               return $errors;
+       }
+
+       /**
+        * Returns a Title mock object
+        *
+        * @note This mock object avoids the involvement of LinksUpdate (which
+        * requires DB access) and returns a randomized LatestRevID/ArticleID
+        *
+        * @since 1.9
+        *
+        * @return Title
+        */
+       public function getMockTitle() {
+
+               $title = $this->getMockBuilder( 'Title' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $title->expects( $this->any() )
+                       ->method( 'getArticleID' )
+                       ->will( $this->returnValue( rand( 10, 10000 ) ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getNamespace' )
+                       ->will( $this->returnValue( $this->set( 'getNamespace' 
) ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'isKnown' )
+                       ->will( $this->returnValue( $this->set( 'exists' ) ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'exists' )
+                       ->will( $this->returnValue( $this->set( 'exists' ) ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getLatestRevID' )
+                       ->will( $this->returnValue( rand( 10, 5000 ) ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getText' )
+                       ->will( $this->returnValue( $this->set( 'getText' ) ) );
+
+               $title->expects( $this->any() )
+                       ->method( 'getPrefixedText' )
+                       ->will( $this->returnValue( $this->set( 
'getPrefixedText' ) ) );
+
+               return $title;
+       }
+
 }
diff --git a/tests/phpunit/SemanticMediaWikiTestCase.php 
b/tests/phpunit/SemanticMediaWikiTestCase.php
index 26db7ef..04a9b03 100644
--- a/tests/phpunit/SemanticMediaWikiTestCase.php
+++ b/tests/phpunit/SemanticMediaWikiTestCase.php
@@ -3,11 +3,13 @@
 namespace SMW\Test;
 
 use SMW\DataValueFactory;
+use SMW\ArrayAccessor;
 use SMW\DIWikiPage;
 use SMW\Settings;
 
 use RequestContext;
 use FauxRequest;
+use WebRequest;
 use Language;
 use Title;
 
@@ -32,11 +34,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -58,6 +60,19 @@
         * @return string
         */
        public abstract function getClass();
+
+       /**
+        * Helper method that returns a MockObjectBuilder object
+        *
+        * @since 1.9
+        *
+        * @param array $accessor
+        *
+        * @return MockObjectBuilder
+        */
+       public function newMockObject( array $accessor = array() ) {
+               return new MockObjectBuilder( new ArrayAccessor( $accessor ) );
+       }
 
        /**
         * Helper method that returns a randomized Title object to avoid results
@@ -102,9 +117,19 @@
         *
         * @return RequestContext
         */
-       protected function getContext( array $params = array() ) {
-               $request = new FauxRequest( $params, true );
-               return RequestContext::getMain()->setRequest( $request );
+       protected function newContext( $request = array() ) {
+
+               $context = new RequestContext();
+
+               if ( $request instanceof WebRequest ) {
+                       $context->setRequest( $request );
+               } else {
+                       $context->setRequest( new FauxRequest( $request, true ) 
);
+               }
+
+               $context->setUser( new MockSuperUser() );
+
+               return $context;
        }
 
        /**
diff --git a/tests/phpunit/includes/QueryPageTest.php 
b/tests/phpunit/includes/QueryPageTest.php
index 55347df..4beea97 100644
--- a/tests/phpunit/includes/QueryPageTest.php
+++ b/tests/phpunit/includes/QueryPageTest.php
@@ -2,9 +2,6 @@
 
 namespace SMW\Test;
 
-use RequestContext;
-use FauxRequest;
-
 /**
  * Tests for the QueryPage class
  *
@@ -23,11 +20,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -65,10 +62,8 @@
                        ->setMethods( array( 'getResults', 'formatResult' ) )
                        ->getMock();
 
-               $request = new FauxRequest( array( 'property' => $search ) );
-               $context = new RequestContext();
+               $context = $this->newContext( array( 'property' => $search ) );
                $context->setTitle( $this->getTitle() );
-               $context->setRequest( $request );
 
                $queryPage->setContext( $context );
 
@@ -87,16 +82,21 @@
 
        /**
         * @test SMWQueryPage::linkParameters
+        * @dataProvider linkParametersDataProvider
         *
         * @since 1.9
+        *
+        * @param $test
+        * @param $expected
         */
-       public function testLinkParameters() {
+       public function testLinkParameters( $test, $expected ) {
 
                $search = $this->getRandomString();
-               $result = $this->getInstance( $search )->linkParameters();
+               $result = $this->getInstance( $test )->linkParameters();
 
                $this->assertInternalType( 'array', $result );
-               $this->assertEquals( array( 'property' => $search ) , $result );
+               $this->assertEquals( $expected , $result );
+
        }
 
        /**
@@ -111,10 +111,30 @@
 
                $matcher = array(
                        'tag' => 'form',
-                       'descendant' => array( 'tag' => 'input', 'attributes' 
=> array( 'name' => 'property', 'value' => $search ) )
+                       'descendant' => array(
+                               'tag' => 'input',
+                               'attributes' => array( 'name' => 'property', 
'value' => $search )
+                       )
                );
 
                $this->assertInternalType( 'string', $result );
                $this->assertTag( $matcher, $result );
        }
+
+       /**
+        * Provides sample data to be tested
+        *
+        * @return array
+        */
+       public function linkParametersDataProvider() {
+               $random = $this->getRandomString();
+
+               return array(
+                       array( ''      , array() ),
+                       array( null    , array() ),
+                       array( $random , array( 'property' => $random ) ),
+                       array( "[{$random}]" , array( 'property' => 
"[{$random}]" ) ),
+                       array( "[&{$random}...]" , array( 'property' => 
"[&{$random}...]" ) )
+               );
+       }
 }
diff --git a/tests/phpunit/includes/api/ApiAskTest.php 
b/tests/phpunit/includes/api/ApiAskTest.php
index d6d54f5..f637f40 100644
--- a/tests/phpunit/includes/api/ApiAskTest.php
+++ b/tests/phpunit/includes/api/ApiAskTest.php
@@ -20,19 +20,15 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
- * @ingroup SMW
- * @ingroup Test
- * @ingroup API
  *
- * @licence GNU GPL v2+
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
 /**
- * Tests for the ApiAsk class
  * @covers \ApiAsk
  *
  * @ingroup Test
diff --git a/tests/phpunit/includes/api/ApiQueryTest.php 
b/tests/phpunit/includes/api/ApiQueryTest.php
index 4fd89d6..722aa26 100644
--- a/tests/phpunit/includes/api/ApiQueryTest.php
+++ b/tests/phpunit/includes/api/ApiQueryTest.php
@@ -2,7 +2,6 @@
 
 namespace SMW\Test;
 
-use SMW\ArrayAccessor;
 use ReflectionClass;
 use ApiResult;
 
@@ -24,11 +23,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -49,20 +48,6 @@
         */
        public function getClass() {
                return '\ApiSMWQuery';
-       }
-
-       /**
-        * Helper method that returns a SMWQueryResult object
-        *
-        * @since 1.9
-        *
-        * @param array $accessor
-        *
-        * @return SMWQueryResult
-        */
-       private function getMockQueryResult( array $accessor = array() ) {
-               $mockObject = new MockObjectBuilder( new ArrayAccessor( 
$accessor ) );
-               return $mockObject->getQueryResult();
        }
 
        /**
@@ -116,11 +101,11 @@
                );
 
                $apiResult   = $this->getApiResult( array() );
-               $queryResult = $this->getMockQueryResult( array(
+               $queryResult = $this->newMockObject( array(
                        'toArray'           => $test,
                        'getErrors'         => array(),
                        'hasFurtherResults' => true
-               ) );
+               ) )->getQueryResult();
 
                // Access protected method
                $reflector = new ReflectionClass( $this->getClass() );
diff --git a/tests/phpunit/includes/specials/UnusedPropertiesPageTest.php 
b/tests/phpunit/includes/specials/UnusedPropertiesPageTest.php
index 446bdb6..854a16b 100644
--- a/tests/phpunit/includes/specials/UnusedPropertiesPageTest.php
+++ b/tests/phpunit/includes/specials/UnusedPropertiesPageTest.php
@@ -6,8 +6,6 @@
 use SMWUnusedPropertiesPage;
 use SMWDataItem;
 
-use RequestContext;
-
 /**
  * Tests for the UnusedPropertiesPage class
  *
@@ -26,11 +24,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -54,109 +52,28 @@
        }
 
        /**
-        * Helper method that returns a SMWDIError object
-        *
-        * @since 1.9
-        *
-        * @return SMWDIError
-        */
-       private function getMockDIError( $error = 'Foo' ) {
-
-               $errors = $this->getMockBuilder( 'SMWDIError' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $errors->expects( $this->any() )
-                       ->method( 'getErrors' )
-                       ->will( $this->returnValue( $error ) );
-
-               return $errors;
-       }
-
-       /**
         * Helper method that returns a DIWikiPage object
         *
         * @since 1.9
         *
         * @return DIWikiPage
         */
-       private function getMockDIWikiPage() {
+       private function getMockDIWikiPage( $exists = true ) {
 
-               $subject = $this->getMockBuilder( '\SMW\DIWikiPage' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $text  = $this->getRandomString();
 
-               $subject->expects( $this->any() )
-                       ->method( 'getTitle' )
-                       ->will( $this->returnValue( $this->getTitle() ) );
+               $title = $this->newMockObject( array(
+                       'exists'  => $exists,
+                       'getText' => $text,
+                       'getNamespace'    => NS_MAIN,
+                       'getPrefixedText' => $text
+               ) )->getMockTitle();
 
-               $subject->expects( $this->any() )
-                       ->method( 'getDIType' )
-                       ->will( $this->returnValue( SMWDataItem::TYPE_WIKIPAGE 
) );
+               $diWikiPage = $this->newMockObject( array(
+                       'getTitle'  => $title,
+               ) )->getMockDIWikiPage();
 
-               return $subject;
-       }
-
-       /**
-        * Helper method that returns a Store object
-        *
-        * @since 1.9
-        *
-        * @param $values
-        *
-        * @return Store
-        */
-       private function getMockStore( array $values ) {
-
-               $store = $this->getMock( '\SMW\Store' );
-
-               $store->expects( $this->any() )
-                       ->method( 'getPropertyValues' )
-                       ->will( $this->returnValue( $values ) );
-
-               return $store;
-       }
-
-       /**
-        * Helper method that returns a DIProperty object
-        *
-        * @since 1.9
-        *
-        * @param $isUserDefined
-        *
-        * @return DIProperty
-        */
-       private function getMockDIProperty( $isUserDefined ) {
-
-               $property = $this->getMockBuilder( '\SMW\DIProperty' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $property->expects( $this->any() )
-                       ->method( 'isUserDefined' )
-                       ->will( $this->returnValue( $isUserDefined ) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getDiWikiPage' )
-                       ->will( $this->returnValue( $this->getMockDIWikiPage() 
) );
-
-               $property->expects( $this->any() )
-                       ->method( 'findPropertyTypeID' )
-                       ->will( $this->returnValue( '_wpg' ) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getKey' )
-                       ->will( $this->returnValue( '_wpg' ) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getDIType' )
-                       ->will( $this->returnValue( SMWDataItem::TYPE_PROPERTY 
) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getLabel' )
-                       ->will( $this->returnValue( $this->getRandomString() ) 
);
-
-               return $property;
+               return $diWikiPage;
        }
 
        /**
@@ -193,15 +110,13 @@
         */
        private function getInstance( $result = null, $values = array() ) {
 
-               // Store stub object
-               $store = $this->getMockStore( $values );
-
-               $store->expects( $this->any() )
-                       ->method( 'getUnusedPropertiesSpecial' )
-                       ->will( $this->returnValue( $this->getMockCollector( 
$result ) ) );
+               $store = $this->newMockObject( array(
+                       'getPropertyValues'          => $values,
+                       'getUnusedPropertiesSpecial' => 
$this->getMockCollector( $result )
+               ) )->getMockStore();
 
                $instance = new SMWUnusedPropertiesPage( $store, 
$this->getSettings() );
-               $instance->setContext( RequestContext::getMain() );
+               $instance->setContext( $this->newContext() );
 
                return $instance;
        }
@@ -229,9 +144,14 @@
 
                // DIProperty
                $instance = $this->getInstance();
-               $property = $this->getMockDIProperty( $isUserDefined );
-               $expected = $property->getDiWikiPage()->getTitle()->getText();
 
+               $property = $this->newMockObject( array(
+                       'isUserDefined' => $isUserDefined,
+                       'getDiWikiPage' => $this->getMockDIWikiPage( true ),
+                       'getLabel'      => $this->getRandomString(),
+               ) )->getMockDIProperty();
+
+               $expected = $property->getDiWikiPage()->getTitle()->getText();
                $result   = $instance->formatResult( $skin, $property );
 
                $this->assertInternalType( 'string', $result );
@@ -240,7 +160,13 @@
                // Multiple entries
                $instance = $this->getInstance();
                $multiple = array( $this->getMockDIWikiPage(), 
$this->getMockDIWikiPage() );
-               $property = $this->getMockDIProperty( $isUserDefined );
+
+               $property = $this->newMockObject( array(
+                       'isUserDefined' => $isUserDefined,
+                       'getDiWikiPage' => $this->getMockDIWikiPage( true ),
+                       'getLabel'      => $this->getRandomString(),
+               ) )->getMockDIProperty();
+
                $expected = $property->getDiWikiPage()->getTitle()->getText();
                $instance = $this->getInstance( null, $multiple );
 
@@ -253,7 +179,10 @@
                $instance = $this->getInstance();
                $error    = $this->getRandomString();
 
-               $result   = $instance->formatResult( $skin, 
$this->getMockDIError( $error ) );
+               $result   = $instance->formatResult(
+                       $skin,
+                       $this->newMockobject( array( 'getErrors' => $error ) 
)->getMockDIError()
+               );
 
                $this->assertInternalType( 'string', $result );
                $this->assertContains( $error, $result );
diff --git a/tests/phpunit/includes/specials/WantedPropertiesPageTest.php 
b/tests/phpunit/includes/specials/WantedPropertiesPageTest.php
index 2190e5a..862f061 100644
--- a/tests/phpunit/includes/specials/WantedPropertiesPageTest.php
+++ b/tests/phpunit/includes/specials/WantedPropertiesPageTest.php
@@ -5,8 +5,6 @@
 use SMWWantedPropertiesPage;
 use SMWDataItem;
 
-use RequestContext;
-
 /**
  * Tests for the WantedPropertiesPage class
  *
@@ -25,11 +23,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -53,89 +51,28 @@
        }
 
        /**
-        * Helper method that returns a Store object
-        *
-        * @since 1.9
-        *
-        * @param $values
-        *
-        * @return Store
-        */
-       private function getMockStore( array $values = array() ) {
-
-               $store = $this->getMock( '\SMW\Store' );
-
-               $store->expects( $this->any() )
-                       ->method( 'getPropertyValues' )
-                       ->will( $this->returnValue( $values ) );
-
-               return $store;
-       }
-
-       /**
         * Helper method that returns a DIWikiPage object
         *
         * @since 1.9
         *
         * @return DIWikiPage
         */
-       private function getMockDIWikiPage() {
+       private function getMockDIWikiPage( $exists = true ) {
 
-               $subject = $this->getMockBuilder( '\SMW\DIWikiPage' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $text  = $this->getRandomString();
 
-               $subject->expects( $this->any() )
-                       ->method( 'getTitle' )
-                       ->will( $this->returnValue( $this->getTitle() ) );
+               $title = $this->newMockObject( array(
+                       'exists'  => $exists,
+                       'getText' => $text,
+                       'getNamespace'    => NS_MAIN,
+                       'getPrefixedText' => $text
+               ) )->getMockTitle();
 
-               $subject->expects( $this->any() )
-                       ->method( 'getDIType' )
-                       ->will( $this->returnValue( SMWDataItem::TYPE_WIKIPAGE 
) );
+               $diWikiPage = $this->newMockObject( array(
+                       'getTitle'  => $title,
+               ) )->getMockDIWikiPage();
 
-               return $subject;
-       }
-
-       /**
-        * Helper method that returns a DIProperty object
-        *
-        * @since 1.9
-        *
-        * @param $isUserDefined
-        *
-        * @return DIProperty
-        */
-       private function getMockDIProperty( $isUserDefined ) {
-
-               $property = $this->getMockBuilder( '\SMW\DIProperty' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $property->expects( $this->any() )
-                       ->method( 'isUserDefined' )
-                       ->will( $this->returnValue( $isUserDefined ) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getDiWikiPage' )
-                       ->will( $this->returnValue( $this->getMockDIWikiPage() 
) );
-
-               $property->expects( $this->any() )
-                       ->method( 'findPropertyTypeID' )
-                       ->will( $this->returnValue( '_wpg' ) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getKey' )
-                       ->will( $this->returnValue( '_wpg' ) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getDIType' )
-                       ->will( $this->returnValue( SMWDataItem::TYPE_PROPERTY 
) );
-
-               $property->expects( $this->any() )
-                       ->method( 'getLabel' )
-                       ->will( $this->returnValue( $this->getRandomString() ) 
);
-
-               return $property;
+               return $diWikiPage;
        }
 
        /**
@@ -171,15 +108,13 @@
         */
        private function getInstance( $result = null ) {
 
-               // Store stub object
-               $store = $this->getMockStore();
-
-               $store->expects( $this->any() )
-                       ->method( 'getWantedPropertiesSpecial' )
-                       ->will( $this->returnValue( $this->getMockCollector( 
$result ) ) );
+               $store = $this->newMockObject( array(
+                       'getPropertyValues'          => array(),
+                       'getWantedPropertiesSpecial' => 
$this->getMockCollector( $result )
+               ) )->getMockStore();
 
                $instance = new SMWWantedPropertiesPage( $store, 
$this->getSettings() );
-               $instance->setContext( RequestContext::getMain() );
+               $instance->setContext( $this->newContext() );
 
                return $instance;
        }
@@ -206,8 +141,13 @@
                $skin     = $this->getMock( 'Skin' );
 
                $count    = rand();
+               $property = $this->newMockObject( array(
+                       'isUserDefined' => $isUserDefined,
+                       'getDiWikiPage' => $this->getMockDIWikiPage( true ),
+                       'getLabel'      => $this->getRandomString(),
+               ) )->getMockDIProperty();
+
                $expected = $isUserDefined ? (string)$count : '';
-               $property = $this->getMockDIProperty( $isUserDefined );
                $result   = $instance->formatResult( $skin, array( $property, 
$count ) );
 
                $this->assertInternalType( 'string', $result );
diff --git a/tests/phpunit/includes/storage/CollectorTest.php 
b/tests/phpunit/includes/storage/CollectorTest.php
index 9700d96..17b122a 100644
--- a/tests/phpunit/includes/storage/CollectorTest.php
+++ b/tests/phpunit/includes/storage/CollectorTest.php
@@ -22,11 +22,10 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
- *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -92,6 +91,7 @@
         */
        public function testGetResults() {
 
+               // Non-cached scenario
                $accessor = array(
                        'id'      => rand(),
                        'type'    => false,
@@ -106,7 +106,11 @@
 
                $this->assertInternalType( 'array', $result );
                $this->assertEquals( $expected, $result );
+               $this->assertNull( $instance->getCacheDate() );
+               $this->assertFalse( $instance->isCached() );
+               $this->assertEquals( count( $expected ), $instance->getCount() 
);
 
+               // Cached scenario
                $accessor = array(
                        'id'      => rand(),
                        'type'    => 'hash',
@@ -126,7 +130,10 @@
                // has not changed results are expected to be cached and be 
equal to
                // the results of the previous initialization
                $instance = $this->getInstance( array( 'Lula' ), $accessor );
+
                $this->assertEquals( $result, $instance->getResults() );
+               $this->assertNotNull( $instance->getCacheDate() );
+               $this->assertTrue( $instance->isCached() );
 
        }
 }
diff --git 
a/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php 
b/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
index 3162638..3d3e31b 100644
--- a/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
@@ -7,6 +7,8 @@
 use SMW\Settings;
 use SMW\Store;
 
+use FakeResultWrapper;
+
 /**
  *Test for the StatisticsCollector class
  *
@@ -25,11 +27,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -64,12 +66,16 @@
         */
        private function getInstance( $count = 1, $cacheEnabled = false ) {
 
+               // $store = $this->newMockObject( array( 'getPropertyTables' => 
array( 'smw_test' ) ) )->getMockStore();
                $store = StoreFactory::getStore();
 
-               // fetchObject return object
-               $returnFetchObject = new \StdClass;
-               $returnFetchObject->count = $count;
-               $returnFetchObject->o_hash ='foo';
+               $result = array(
+                       'count'  => $count,
+                       'o_hash' => 'foo'
+               );
+
+               $resultWrapper = new FakeResultWrapper( array( (object)$result 
) );
+               $resultWrapper->count = $count;
 
                // Database stub object which makes the test
                // independent from the real DB
@@ -78,18 +84,14 @@
                // Override methods with expected return objects
                $connection->expects( $this->any() )
                        ->method( 'select' )
-                       ->will( $this->returnValue( array( $returnFetchObject ) 
) );
+                       ->will( $this->returnValue( $resultWrapper ) );
 
                $connection->expects( $this->any() )
                        ->method( 'fetchObject' )
-                       ->will( $this->returnValue( $returnFetchObject ) );
+                       ->will( $this->returnValue( $resultWrapper ) );
 
                $connection->expects( $this->any() )
                        ->method( 'estimateRowCount' )
-                       ->will( $this->returnValue( $count ) );
-
-               $connection->expects( $this->any() )
-                       ->method( 'numRows' )
                        ->will( $this->returnValue( $count ) );
 
                // Settings to be used
diff --git 
a/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php 
b/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
index 5602f23..fa0e548 100644
--- a/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/UnusedPropertiesCollectorTest.php
@@ -3,12 +3,15 @@
 namespace SMW\Test\SQLStore;
 
 use SMW\SQLStore\UnusedPropertiesCollector;
+
 use SMW\MessageFormatter;
 use SMW\StoreFactory;
 use SMW\DIProperty;
 use SMW\Settings;
 
 use SMWRequestOptions;
+
+use FakeResultWrapper;
 
 /**
  * Test for the UnusedPropertiesCollector class
@@ -28,11 +31,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -66,9 +69,9 @@
         */
        private function getMockDBConnection( $smwTitle = 'Foo' ) {
 
-               // Injection object expected as the DB fetchObject
-               $returnFetchObject = new \StdClass;
-               $returnFetchObject->smw_title = $smwTitle;
+               $result = array(
+                       'smw_title' => $smwTitle,
+               );
 
                // Database stub object to make the test independent from any 
real DB
                $connection = $this->getMock( 'DatabaseMysql' );
@@ -76,7 +79,7 @@
                // Override method with expected return objects
                $connection->expects( $this->any() )
                        ->method( 'select' )
-                       ->will( $this->returnValue( array( $returnFetchObject ) 
) );
+                       ->will( $this->returnValue( new FakeResultWrapper( 
array( (object)$result ) ) ) );
 
                return $connection;
        }
diff --git 
a/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php 
b/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
index 0eff584..2f40f07 100644
--- a/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/WantedPropertiesCollectorTest.php
@@ -9,6 +9,8 @@
 
 use SMWRequestOptions;
 
+use FakeResultWrapper;
+
 /**
  * Test for the WantedPropertiesCollector class
  *
@@ -27,11 +29,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
  *
  * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
@@ -67,9 +69,10 @@
        private function getMockDBConnection( $smwTitle = 'Foo', $count = 1 ) {
 
                // Injection object expected as the DB fetchObject
-               $returnFetchObject = new \StdClass;
-               $returnFetchObject->count = $count;
-               $returnFetchObject->smw_title = $smwTitle;
+               $result = array(
+                       'count'     => $count,
+                       'smw_title' => $smwTitle
+               );
 
                // Database stub object to make the test independent from any 
real DB
                $connection = $this->getMock( 'DatabaseMysql' );
@@ -77,7 +80,7 @@
                // Override method with expected return objects
                $connection->expects( $this->any() )
                        ->method( 'select' )
-                       ->will( $this->returnValue( array( $returnFetchObject ) 
) );
+                       ->will( $this->returnValue( new FakeResultWrapper( 
array( (object)$result ) ) ) );
 
                return $connection;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/72132
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I87561dfa930bb99af30c6122824ac3d9c516d112
Gerrit-PatchSet: 1
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

Reply via email to