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

Change subject: Add test for some class aliases
......................................................................


Add test for some class aliases

* SemanticDataTest
* UpdateJobTest
* Improve StoreFactoryTest

Change-Id: Icb2e423c08b5f6e64b1d6bf9e9339a7f69dd1e8e
---
M docs/doxygen.group.definitions.php
M includes/SMW_SemanticData.php
M includes/Setup.php
R includes/exceptions/InvalidStoreException.php
M includes/jobs/SMW_UpdateJob.php
M includes/storage/StoreFactory.php
M tests/phpunit/MockObjectBuilder.php
M tests/phpunit/SemanticMediaWikiTestCase.php
A tests/phpunit/includes/SemanticDataTest.php
A tests/phpunit/includes/jobs/UpdateJobTest.php
M tests/phpunit/includes/storage/StoreFactoryTest.php
11 files changed, 250 insertions(+), 35 deletions(-)

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



diff --git a/docs/doxygen.group.definitions.php 
b/docs/doxygen.group.definitions.php
index e4503a7..b670b13 100644
--- a/docs/doxygen.group.definitions.php
+++ b/docs/doxygen.group.definitions.php
@@ -18,6 +18,13 @@
  */
 
 /**
+ * This group contains members that are related to jobs
+ *
+ * @defgroup Job Job
+ * @ingroup SMW
+ */
+
+/**
  * This group contains members that are related to accessors
  *
  * @defgroup Accessor Accessor
diff --git a/includes/SMW_SemanticData.php b/includes/SMW_SemanticData.php
index 132c51f..4d1706a 100644
--- a/includes/SMW_SemanticData.php
+++ b/includes/SMW_SemanticData.php
@@ -528,4 +528,11 @@
                }
        }
 
-}
\ No newline at end of file
+}
+
+/**
+ * SMWSemanticData class alias
+ *
+ * @since 1.9
+ */
+class_alias( 'SMWSemanticData', 'SMW\SemanticData' );
diff --git a/includes/Setup.php b/includes/Setup.php
index 9c36ef9..fe93e10 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -132,6 +132,7 @@
        $wgAutoloadClasses['SMWOutputs']                = $incDir . 
'SMW_Outputs.php';
        $wgAutoloadClasses['SMW\ParserTextProcessor']   = $incDir . 
'ParserTextProcessor.php';
        $wgAutoloadClasses['SMWSemanticData']           = $incDir . 
'SMW_SemanticData.php';
+       $wgAutoloadClasses['SMW\SemanticData']          = $incDir . 
'SMW_SemanticData.php'; // 1.9
        $wgAutoloadClasses['SMWPageLister']             = $incDir . 
'SMW_PageLister.php';
 
        $wgAutoloadClasses['SMWDataValueFactory']       = $incDir . 
'DataValueFactory.php';
@@ -172,7 +173,7 @@
        $wgAutoloadClasses['SMW\ApiRequestParameterFormatter'] = $incDir . 
'formatters/ApiRequestParameterFormatter.php';
 
        // Exceptions
-       $wgAutoloadClasses['SMW\StoreInstanceException']       = $incDir . 
'/exceptions/StoreInstanceException.php';
+       $wgAutoloadClasses['SMW\InvalidStoreException']       = $incDir . 
'/exceptions/InvalidStoreException.php';
        $wgAutoloadClasses['SMW\InvalidSemanticDataException'] = $incDir . 
'/exceptions/InvalidSemanticDataException.php';
        $wgAutoloadClasses['SMW\InvalidNamespaceException']    = $incDir . 
'/exceptions/InvalidNamespaceException.php';
        $wgAutoloadClasses['SMW\InvalidPropertyException']     = $incDir . 
'/exceptions/InvalidPropertyException.php';
@@ -410,6 +411,7 @@
        // Jobs
        $wgJobClasses['SMWUpdateJob']       = 'SMWUpdateJob';
        $wgAutoloadClasses['SMWUpdateJob']  = $smwgIP . 
'includes/jobs/SMW_UpdateJob.php';
+       $wgAutoloadClasses['SMW\UpdateJob'] = $smwgIP . 
'includes/jobs/SMW_UpdateJob.php';
        $wgJobClasses['SMWRefreshJob']      = 'SMWRefreshJob';
        $wgAutoloadClasses['SMWRefreshJob'] = $smwgIP . 
'includes/jobs/SMW_RefreshJob.php';
 
diff --git a/includes/exceptions/StoreInstanceException.php 
b/includes/exceptions/InvalidStoreException.php
similarity index 95%
rename from includes/exceptions/StoreInstanceException.php
rename to includes/exceptions/InvalidStoreException.php
index d06473e..f12c676 100644
--- a/includes/exceptions/StoreInstanceException.php
+++ b/includes/exceptions/InvalidStoreException.php
@@ -36,4 +36,4 @@
  * @ingroup Exception
  * @codeCoverageIgnore
  */
-class StoreInstanceException extends MWException {}
\ No newline at end of file
+class InvalidStoreException extends MWException {}
\ No newline at end of file
diff --git a/includes/jobs/SMW_UpdateJob.php b/includes/jobs/SMW_UpdateJob.php
index 42693b4..7d0e471 100644
--- a/includes/jobs/SMW_UpdateJob.php
+++ b/includes/jobs/SMW_UpdateJob.php
@@ -98,3 +98,10 @@
        }
 
 }
+
+/**
+ * SMWUpdateJob class alias
+ *
+ * @since 1.9
+ */
+class_alias( 'SMWUpdateJob', 'SMW\UpdateJob' );
diff --git a/includes/storage/StoreFactory.php 
b/includes/storage/StoreFactory.php
index 0186d4d..455ca30 100644
--- a/includes/storage/StoreFactory.php
+++ b/includes/storage/StoreFactory.php
@@ -20,10 +20,10 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
- * @ingroup Store
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
  *
  * @author mwjames
  */
@@ -31,21 +31,12 @@
 /**
  * Factory method that handles store instantiation
  *
- * @todo instead of having a single store declaration such 
as'smwgDefaultStore' => 'MyStore'
- * allow for a more fain-grained definition such as
- *
- * @code
- * 'smwgStores' => array(
- *   'SqlStore' => 'MySqlStore'
- *   'SparqlStore' => 'MySparqlStore'
- *   'HashStore' => 'MyHashStore' // For unit testing to omit direct database 
access
- *   ...
- * )
- * @endcode
- *
  * @ingroup Store
  */
 class StoreFactory {
+
+       /** @var Store[] */
+       private static $instance = array();
 
        /**
         * Returns a new store instance
@@ -55,14 +46,14 @@
         * @param string $store
         *
         * @return Store
-        * @throws StoreInstanceException
+        * @throws InvalidStoreException
         */
        public static function newInstance( $store ) {
 
                $instance = new $store;
 
                if ( !( $instance instanceof Store ) ) {
-                       throw new StoreInstanceException( "{$store} can not be 
used as a store instance" );
+                       throw new InvalidStoreException( "{$store} can not be 
used as a store instance" );
                }
 
                return $instance;
@@ -73,19 +64,27 @@
         *
         * @since 1.9
         *
-        * @param boolean|string $store
+        * @param string|null $store
         *
         * @return Store
         */
-       public static function getStore( $store = false ) {
-               static $instance = array();
+       public static function getStore( $store = null ) {
 
-               $store = $store === false ? Settings::newFromGlobals()->get( 
'smwgDefaultStore' ) : $store;
+               $store = $store === null ? Settings::newFromGlobals()->get( 
'smwgDefaultStore' ) : $store;
 
-               if ( !isset( $instance[$store] ) ) {
-                       $instance[$store] = self::newInstance( $store );
+               if ( !isset( self::$instance[$store] ) ) {
+                       self::$instance[$store] = self::newInstance( $store );
                }
 
-               return $instance[$store];
+               return self::$instance[$store];
+       }
+
+       /**
+        * Reset instance
+        *
+        * @since 1.9
+        */
+       public static function clear() {
+               self::$instance = array();
        }
 }
diff --git a/tests/phpunit/MockObjectBuilder.php 
b/tests/phpunit/MockObjectBuilder.php
index 64772fc..7ca7355 100644
--- a/tests/phpunit/MockObjectBuilder.php
+++ b/tests/phpunit/MockObjectBuilder.php
@@ -78,7 +78,7 @@
         */
        public function getMockSemanticData() {
 
-               $semanticData = $this->getMockBuilder( 'SMWSemanticData' )
+               $semanticData = $this->getMockBuilder( 'SMW\SemanticData' )
                        ->disableOriginalConstructor()
                        ->getMock();
 
@@ -268,9 +268,16 @@
                        ) )
                        ->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->returnValue( $this->set( 
'getPropertyValues' ) ) );
+                       ->will( is_callable( $this->set( 'getPropertyValues' ) 
) ? $this->returnCallback( $this->set( 'getPropertyValues' ) ) : 
$this->returnValue( $this->set( 'getPropertyValues' ) ) );
 
                $store->expects( $this->any() )
                        ->method( 'getPropertiesSpecial' )
@@ -301,6 +308,14 @@
                        ->will( is_callable( $this->set( 'getQueryResult' ) ) ? 
$this->returnCallback( $this->set( 'getQueryResult' ) ) : $this->returnValue( 
$this->set( 'getQueryResult' ) ) );
 
                $store->expects( $this->any() )
+                       ->method( 'getAllPropertySubjects' )
+                       ->will( is_callable( $this->set( 
'getAllPropertySubjects' ) ) ? $this->returnCallback( $this->set( 
'getAllPropertySubjects' ) ) : $this->returnValue( $this->set( 
'getAllPropertySubjects' ) ) );
+
+               $store->expects( $this->any() )
+                       ->method( 'getPropertySubjects' )
+                       ->will( is_callable( $this->set( 'getPropertySubjects' 
) ) ? $this->returnCallback( $this->set( 'getPropertySubjects' ) ) : 
$this->returnValue( $this->set( 'getPropertySubjects' ) ) );
+
+               $store->expects( $this->any() )
                        ->method( 'getObjectIds' )
                        ->will( $this->returnValue( $idTable ) );
 
diff --git a/tests/phpunit/SemanticMediaWikiTestCase.php 
b/tests/phpunit/SemanticMediaWikiTestCase.php
index 04a9b03..82e9ae6 100644
--- a/tests/phpunit/SemanticMediaWikiTestCase.php
+++ b/tests/phpunit/SemanticMediaWikiTestCase.php
@@ -13,6 +13,8 @@
 use Language;
 use Title;
 
+use ReflectionClass;
+
 use SMWSemanticData;
 use SMWDataItem;
 
@@ -72,6 +74,19 @@
         */
        public function newMockObject( array $accessor = array() ) {
                return new MockObjectBuilder( new ArrayAccessor( $accessor ) );
+       }
+
+       /**
+        * Helper method that returns a ReflectionClass object
+        *
+        * @since 1.9
+        *
+        * @param string|null $class
+        *
+        * @return ReflectionClass
+        */
+       public function newReflector( $class = null ) {
+               return new ReflectionClass( $class === null ? $this->getClass() 
: $class );
        }
 
        /**
@@ -146,6 +161,19 @@
        }
 
        /**
+        * Helper method that returns a DIWikiPage object
+        *
+        * @since 1.9
+        *
+        * @param Title|null $title
+        *
+        * @return DIWikiPage
+        */
+       protected function newSubject( Title $title = null ) {
+               return DIWikiPage::newFromTitle( $title === null ? 
$this->getTitle() : $title );
+       }
+
+       /**
         * Helper method that returns a Settings object
         *
         * @since 1.9
diff --git a/tests/phpunit/includes/SemanticDataTest.php 
b/tests/phpunit/includes/SemanticDataTest.php
new file mode 100644
index 0000000..b71deee
--- /dev/null
+++ b/tests/phpunit/includes/SemanticDataTest.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\SemanticData;
+
+/**
+ * Tests for the SemanticData class
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * @covers \SMW\SemanticData
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class SemanticDataTest extends SemanticMediaWikiTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMW\SemanticData';
+       }
+
+       /**
+        * Helper method that returns a SemanticData object
+        *
+        * @since 1.9
+        *
+        * @return SemanticData
+        */
+       private function getInstance() {
+               return new SemanticData( $this->getSubject() );
+       }
+
+       /**
+        * @test SemanticData::__construct
+        *
+        * @since 1.9
+        */
+       public function testConstructor() {
+               $this->assertInstanceOf( $this->getClass(), 
$this->getInstance() );
+               $this->assertInstanceOf( 'SMWSemanticData', 
$this->getInstance() );
+       }
+
+}
diff --git a/tests/phpunit/includes/jobs/UpdateJobTest.php 
b/tests/phpunit/includes/jobs/UpdateJobTest.php
new file mode 100644
index 0000000..b3f312b
--- /dev/null
+++ b/tests/phpunit/includes/jobs/UpdateJobTest.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\UpdateJob;
+
+/**
+ * Tests for the UpdateJob class
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * @covers \SMW\UpdateJob
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class UpdateJobTest extends SemanticMediaWikiTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMW\UpdateJob';
+       }
+
+       /**
+        * Helper method that returns a UpdateJob object
+        *
+        * @since 1.9
+        *
+        * @return UpdateJob
+        */
+       private function getInstance() {
+               return new UpdateJob( $this->getTitle() );
+       }
+
+       /**
+        * @test UpdateJob::__construct
+        *
+        * @since 1.9
+        */
+       public function testConstructor() {
+               $this->assertInstanceOf( $this->getClass(), 
$this->getInstance() );
+               $this->assertInstanceOf( 'SMWUpdateJob', $this->getInstance() );
+       }
+
+}
diff --git a/tests/phpunit/includes/storage/StoreFactoryTest.php 
b/tests/phpunit/includes/storage/StoreFactoryTest.php
index c172c65..bd118ed 100644
--- a/tests/phpunit/includes/storage/StoreFactoryTest.php
+++ b/tests/phpunit/includes/storage/StoreFactoryTest.php
@@ -23,17 +23,15 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
- * @ingroup Test
  *
- * @licence GNU GPL v2+
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
  * @author mwjames
  */
 
 /**
- * Tests for the StoreFactory class
  * @covers \SMW\StoreFactory
  *
  * @ingroup Test
@@ -58,6 +56,7 @@
         * @since 1.9
         */
        public function testGetStore() {
+
                $settings = Settings::newFromGlobals();
 
                // Default is handled by the method itself
@@ -66,6 +65,10 @@
 
                // Static instance
                $this->assertTrue( StoreFactory::getStore() === $instance );
+
+               // Reset static instance
+               StoreFactory::clear();
+               $this->assertTrue( StoreFactory::getStore() !== $instance );
 
                // Inject default store
                $defaulStore = $settings->get( 'smwgDefaultStore' );
@@ -80,6 +83,7 @@
         * @since 1.9
         */
        public function testNewInstance() {
+
                $settings = Settings::newFromGlobals();
 
                // Circumvent the static instance
@@ -98,7 +102,7 @@
         * @since 1.9
         */
        public function testStoreInstanceException() {
-               $this->setExpectedException( '\SMW\StoreInstanceException' );
+               $this->setExpectedException( '\SMW\InvalidStoreException' );
                $instance = StoreFactory::newInstance( $this->getClass() );
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icb2e423c08b5f6e64b1d6bf9e9339a7f69dd1e8e
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