Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/75279


Change subject: \SMW\QueryData use UnknownIdException instead of MWException
......................................................................

\SMW\QueryData use UnknownIdException instead of MWException

Change-Id: If94ba269cb30378d45b0da5fe14ea02e44b4646d
---
M includes/Setup.php
A includes/exceptions/UnknownIdException.php
M includes/query/QueryData.php
M tests/phpunit/includes/query/QueryDataTest.php
4 files changed, 60 insertions(+), 40 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/79/75279/1

diff --git a/includes/Setup.php b/includes/Setup.php
index 2876b2f..737a044 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -188,6 +188,7 @@
        $wgAutoloadClasses['SMW\InvalidResultException']       = $incDir . 
'/exceptions/InvalidResultException.php';
        $wgAutoloadClasses['SMW\DataItemException']            = $incDir . 
'/exceptions/DataItemException.php'; // 1.9
        $wgAutoloadClasses['SMWDataItemException']             = $incDir . 
'/exceptions/DataItemException.php';
+       $wgAutoloadClasses['SMW\UnknownIdException']           = $incDir . 
'/exceptions/UnknownIdException.php';
        $wgAutoloadClasses['SMW\InvalidSettingsArgumentException']   = $incDir 
. '/exceptions/InvalidSettingsArgumentException.php';
        $wgAutoloadClasses['SMW\InvalidPredefinedPropertyException'] = $incDir 
. '/exceptions/InvalidPredefinedPropertyException.php';
 
diff --git a/includes/exceptions/UnknownIdException.php 
b/includes/exceptions/UnknownIdException.php
new file mode 100644
index 0000000..02ae10f
--- /dev/null
+++ b/includes/exceptions/UnknownIdException.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace SMW;
+
+use MWException;
+
+/**
+ * Exception for an unknown Id
+ *
+ * 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
+ */
+
+/**
+ * Exception for an unknown Id
+ *
+ * @ingroup Exception
+ * @codeCoverageIgnore
+ */
+class UnknownIdException extends MWException {}
\ No newline at end of file
diff --git a/includes/query/QueryData.php b/includes/query/QueryData.php
index 7350069..e60706c 100644
--- a/includes/query/QueryData.php
+++ b/includes/query/QueryData.php
@@ -2,15 +2,14 @@
 
 namespace SMW;
 
-use SMWDIProperty;
 use SMWDINumber;
 use SMWDIBlob;
 use SMWQuery;
+
 use Title;
-use MWException;
 
 /**
- * Handles query meta data collected in #ask / #show
+ * Class that provides access to the query meta data
  *
  * 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
@@ -27,37 +26,28 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.9
- *
  * @file
- * @ingroup SMW
- * @ingroup ParserHooks
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
  *
  * @author mwjames
  */
 
 /**
- * Class that provides access to the meta data about a query
+ * Class that provides access to the query meta data
  *
  * @ingroup SMW
- * @ingroup ParserHooks
  */
 class QueryData {
 
-       /**
-        * Subobject object
-        * @var $semanticData
-        */
+       /** @var Subobject */
        protected $subobject;
 
-       /**
-        * Represents queryId
-        */
+       /** @var string */
        protected $queryId = null;
 
        /**
-        * Constructor
-        *
         * @since 1.9
         *
         * @param Title $Title
@@ -103,7 +93,7 @@
         * @return array
         */
        public function getProperty() {
-               return new SMWDIProperty( '_ASK' );
+               return new DIProperty( '_ASK' );
        }
 
        /**
@@ -125,8 +115,9 @@
         * @return array
         */
        public function add( SMWQuery $query, array $params ) {
+
                if ( $this->queryId === null ) {
-                       throw new MWException( '_QUERY Id is not set' );
+                       throw new UnknownIdException( '_QUERY Id is not set' );
                }
 
                // Prepare subobject semantic container
@@ -135,22 +126,22 @@
                $description = $query->getDescription();
 
                // Add query string
-               $propertyDi = new SMWDIProperty( '_ASKST' );
+               $propertyDi = new DIProperty( '_ASKST' );
                $valueDi = new SMWDIBlob( $description->getQueryString() );
                $this->subobject->getSemanticData()->addPropertyObjectValue( 
$propertyDi, $valueDi );
 
                // Add query size
-               $propertyDi = new SMWDIProperty( '_ASKSI' );
+               $propertyDi = new DIProperty( '_ASKSI' );
                $valueDi = new SMWDINumber( $description->getSize() );
                $this->subobject->getSemanticData()->addPropertyObjectValue( 
$propertyDi, $valueDi );
 
                // Add query depth
-               $propertyDi = new SMWDIProperty( '_ASKDE' );
+               $propertyDi = new DIProperty( '_ASKDE' );
                $valueDi = new SMWDINumber( $description->getDepth() );
                $this->subobject->getSemanticData()->addPropertyObjectValue( 
$propertyDi, $valueDi );
 
                // Add query format
-               $propertyDi = new SMWDIProperty( '_ASKFO' );
+               $propertyDi = new DIProperty( '_ASKFO' );
                $valueDi = new SMWDIBlob( $params['format']->getValue() );
                $this->subobject->getSemanticData()->addPropertyObjectValue( 
$propertyDi, $valueDi );
        }
diff --git a/tests/phpunit/includes/query/QueryDataTest.php 
b/tests/phpunit/includes/query/QueryDataTest.php
index db9fa40..7039bbc 100644
--- a/tests/phpunit/includes/query/QueryDataTest.php
+++ b/tests/phpunit/includes/query/QueryDataTest.php
@@ -26,16 +26,14 @@
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @since 1.9
  *
- * @ingroup Test
+ * @license GNU GPL v2+
+ * @since   1.9
  *
- * @licence GNU GPL v2+
  * @author mwjames
  */
 
 /**
- * Tests for the QueryData class
  * @covers \SMW\QueryData
  *
  * @ingroup Test
@@ -92,17 +90,6 @@
        }
 
        /**
-        * @test QueryData::__construct
-        *
-        * @since 1.9
-        * @throws PHPUnit_Framework_Error
-        */
-       public function testConstructorException() {
-               $this->setExpectedException( 'PHPUnit_Framework_Error' );
-               $instance = $this->getInstance();
-       }
-
-       /**
         * @test QueryData::getProperty
         *
         * @since 1.9
@@ -155,12 +142,14 @@
         * @throws MWException
         */
        public function testQueryIdException( array $params, array $expected ) {
-               $this->setExpectedException( 'MWException' );
+
+               $this->setExpectedException( '\SMW\UnknownIdException' );
                $title = $this->getTitle();
                $instance = $this->getInstance( $title );
 
                list( $query, $formattedParams ) = $this->getQueryProcessor( 
$params );
                $instance->add( $query, $formattedParams );
+
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If94ba269cb30378d45b0da5fe14ea02e44b4646d
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

Reply via email to