Jeroen De Dauw has uploaded a new change for review.

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


Change subject: Improvements to DataItemTest
......................................................................

Improvements to DataItemTest

Change-Id: I2d62592ac8183c6417ed4247b38fc33e471105a8
---
M includes/dataitems/DIConcept.php
M tests/phpunit/includes/dataitems/DIConceptTest.php
M tests/phpunit/includes/dataitems/DIPropertyTest.php
M tests/phpunit/includes/dataitems/DIWikiPageTest.php
M tests/phpunit/includes/dataitems/DI_BlobTest.php
M tests/phpunit/includes/dataitems/DI_BoolTest.php
M tests/phpunit/includes/dataitems/DI_GeoCoordTest.php
M tests/phpunit/includes/dataitems/DI_NumberTest.php
M tests/phpunit/includes/dataitems/DataItemTest.php
9 files changed, 113 insertions(+), 69 deletions(-)


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

diff --git a/includes/dataitems/DIConcept.php b/includes/dataitems/DIConcept.php
index 2beea30..3538d14 100644
--- a/includes/dataitems/DIConcept.php
+++ b/includes/dataitems/DIConcept.php
@@ -6,11 +6,6 @@
 use SMWDataItemException;
 
 /**
- * @file
- * @ingroup SMWDataItems
- */
-
-/**
  * This class implements Concept data items.
  *
  * @note These special data items for storing concept declaration data in SMW
@@ -71,12 +66,11 @@
        protected $cacheCount;
 
        /**
-        * Initialise the concept data.
-        * @param $concept the concept query string
-        * @param $docu string with user documentation
-        * @param $queryefeatures integer flags about query features
-        * @param $size integer concept query size
-        * @param $depth integer concept query depth
+        * @param string $concept the concept query string
+        * @param string $docu user documentation
+        * @param integer $queryefeatures flags about query features
+        * @param integer $size concept query size
+        * @param integer $depth concept query depth
         */
        public function __construct( $concept, $docu, $queryfeatures, $size, 
$depth ) {
                $this->m_concept  = $concept;
diff --git a/tests/phpunit/includes/dataitems/DIConceptTest.php 
b/tests/phpunit/includes/dataitems/DIConceptTest.php
index b9d0312..4630df8 100644
--- a/tests/phpunit/includes/dataitems/DIConceptTest.php
+++ b/tests/phpunit/includes/dataitems/DIConceptTest.php
@@ -34,8 +34,20 @@
         */
        public function constructorProvider() {
                return array(
-                       array( true, 'Foo', '', '', '', '' ),
-                       array( false, 'Bar' ),
+                       array( 'Foo', '', '', '', '' ),
+               );
+       }
+
+       /**
+        * @see DataItemTest::invalidConstructorArgsProvider
+        *
+        * @since 1.9
+        *
+        * @return array
+        */
+       public function invalidConstructorArgsProvider() {
+               return array(
+                       array( 'Bar' ),
                );
        }
 
diff --git a/tests/phpunit/includes/dataitems/DIPropertyTest.php 
b/tests/phpunit/includes/dataitems/DIPropertyTest.php
index 65f2213..33c2268 100644
--- a/tests/phpunit/includes/dataitems/DIPropertyTest.php
+++ b/tests/phpunit/includes/dataitems/DIPropertyTest.php
@@ -35,11 +35,23 @@
         */
        public function constructorProvider() {
                return array(
-                       array( true, 0 ),
-                       array( true, 243.35353 ),
-                       array( true, 'ohi there' ),
-                       array( false, array() ),
-                       array( false, true ),
+                       array( 0 ),
+                       array( 243.35353 ),
+                       array( 'ohi there' ),
+               );
+       }
+
+       /**
+        * @see DataItemTest::invalidConstructorArgsProvider
+        *
+        * @since 1.9
+        *
+        * @return array
+        */
+       public function invalidConstructorArgsProvider() {
+               return array(
+                       array( true ),
+                       array( array() ),
                );
        }
 
diff --git a/tests/phpunit/includes/dataitems/DIWikiPageTest.php 
b/tests/phpunit/includes/dataitems/DIWikiPageTest.php
index 43e5509..88eedaa 100644
--- a/tests/phpunit/includes/dataitems/DIWikiPageTest.php
+++ b/tests/phpunit/includes/dataitems/DIWikiPageTest.php
@@ -36,9 +36,9 @@
         */
        public function constructorProvider() {
                return array(
-                       array( true, 'Foo', NS_MAIN, '' ),
-                       array( true, 'Foo_Bar', NS_MAIN, '' ),
-                       array( true, 'Foo_Bar_Baz', NS_MAIN, '', 'spam' ),
+                       array( 'Foo', NS_MAIN, '' ),
+                       array( 'Foo_Bar', NS_MAIN, '' ),
+                       array( 'Foo_Bar_Baz', NS_MAIN, '', 'spam' ),
                );
        }
 
diff --git a/tests/phpunit/includes/dataitems/DI_BlobTest.php 
b/tests/phpunit/includes/dataitems/DI_BlobTest.php
index 1346ee1..628c13b 100644
--- a/tests/phpunit/includes/dataitems/DI_BlobTest.php
+++ b/tests/phpunit/includes/dataitems/DI_BlobTest.php
@@ -41,8 +41,8 @@
         */
        public function constructorProvider() {
                return array(
-                       array( true, 'I love Semantic MediaWiki' ),
-                       array( true, 'It is open source' ),
+                       array( 'I love Semantic MediaWiki' ),
+                       array( 'It is open source' ),
                );
        }
 
diff --git a/tests/phpunit/includes/dataitems/DI_BoolTest.php 
b/tests/phpunit/includes/dataitems/DI_BoolTest.php
index d965cee..6d5d526 100644
--- a/tests/phpunit/includes/dataitems/DI_BoolTest.php
+++ b/tests/phpunit/includes/dataitems/DI_BoolTest.php
@@ -41,11 +41,23 @@
         */
        public function constructorProvider() {
                return array(
-                       array( true, false ),
-                       array( true, true ),
-                       array( false, 42 ),
-                       array( false, array() ),
-                       array( false, 'ohi there' ),
+                       array( false ),
+                       array( true ),
+               );
+       }
+
+       /**
+        * @see DataItemTest::invalidConstructorArgsProvider
+        *
+        * @since 1.9
+        *
+        * @return array
+        */
+       public function invalidConstructorArgsProvider() {
+               return array(
+                       array( 42 ),
+                       array( array() ),
+                       array( 'abc' ),
                );
        }
 
diff --git a/tests/phpunit/includes/dataitems/DI_GeoCoordTest.php 
b/tests/phpunit/includes/dataitems/DI_GeoCoordTest.php
index 6683624..c6d2a42 100644
--- a/tests/phpunit/includes/dataitems/DI_GeoCoordTest.php
+++ b/tests/phpunit/includes/dataitems/DI_GeoCoordTest.php
@@ -41,8 +41,8 @@
         */
        public function constructorProvider() {
                return array(
-                       array( true, array( 'lat'=>83.34, 'lon'=>38.44, 
'alt'=>54 ) ),
-                       array( true, array( 'lat'=>42.43, 'lon'=>33.32 ) ),
+                       array( array( 'lat' => 83.34, 'lon' => 38.44, 'alt' => 
54 ) ),
+                       array( array( 'lat' => 42.43, 'lon' => 33.32 ) ),
                );
        }
 
diff --git a/tests/phpunit/includes/dataitems/DI_NumberTest.php 
b/tests/phpunit/includes/dataitems/DI_NumberTest.php
index f2e0825..8e13c3c 100644
--- a/tests/phpunit/includes/dataitems/DI_NumberTest.php
+++ b/tests/phpunit/includes/dataitems/DI_NumberTest.php
@@ -42,11 +42,23 @@
         */
        public function constructorProvider() {
                return array(
-                       array( true, 0 ),
-                       array( true, 243.35353 ),
-                       array( false, 'ohi there' ),
-                       array( false, array() ),
-                       array( false, true ),
+                       array( 0 ),
+                       array( 243.35353 ),
+               );
+       }
+
+       /**
+        * @see DataItemTest::invalidConstructorArgsProvider
+        *
+        * @since 1.9
+        *
+        * @return array
+        */
+       public function invalidConstructorArgsProvider() {
+               return array(
+                       array( true ),
+                       array( array() ),
+                       array( 'abc' ),
                );
        }
 
diff --git a/tests/phpunit/includes/dataitems/DataItemTest.php 
b/tests/phpunit/includes/dataitems/DataItemTest.php
index 1eea6eb..a47a843 100644
--- a/tests/phpunit/includes/dataitems/DataItemTest.php
+++ b/tests/phpunit/includes/dataitems/DataItemTest.php
@@ -32,9 +32,6 @@
        public abstract function getClass();
 
        /**
-        * First element can be a boolean indication if the successive values 
are valid,
-        * or a string indicating the type of exception that should be thrown 
(ie not valid either).
-        *
         * @since 1.8
         *
         * @return array
@@ -42,11 +39,37 @@
        public abstract function constructorProvider();
 
        /**
+        * @since 1.9
+        *
+        * @return array
+        */
+       public function invalidConstructorArgsProvider() {
+               return array();
+       }
+
+       public function testConstructWithInvalidArgsThrowsException() {
+               $this->assertTrue( true );
+
+               foreach ( $this->invalidConstructorArgsProvider() as $argList ) 
{
+                       $this->assertConstructWithInvalidArgsThrowsException( 
$argList );
+               }
+       }
+
+       protected function assertConstructWithInvalidArgsThrowsException( array 
$argList ) {
+               $this->setExpectedException( 'Exception' );
+
+               call_user_func_array(
+                       array( $this, 'newInstance' ),
+                       $argList
+               );
+       }
+
+       /**
         * Creates and returns a new instance of the data item.
         *
         * @since 1.8
         *
-        * @return \SMWDataItem
+        * @return SMWDataItem
         */
        public function newInstance() {
                $reflector = new \ReflectionClass( $this->getClass() );
@@ -63,19 +86,12 @@
        public function instanceProvider() {
                $phpFails = array( $this, 'newInstance' );
 
-               return array_filter( array_map(
+               return array_map(
                        function( array $args ) use ( $phpFails ) {
-                               $isValid = array_shift( $args ) === true;
-
-                               if ( $isValid ) {
-                                       return array( call_user_func_array( 
$phpFails, $args ) );
-                               }
-                               else {
-                                       return false;
-                               }
+                               return array( call_user_func_array( $phpFails, 
$args ) );
                        },
                        $this->constructorProvider()
-               ), 'is_array' );
+               );
        }
 
        /**
@@ -84,27 +100,13 @@
         * @since 1.8
         */
        public function testConstructor() {
-               $args = func_get_args();
+               $dataItem = call_user_func_array(
+                       array( $this, 'newInstance' ),
+                       func_get_args()
+               );
 
-               $valid = array_shift( $args );
-               $pokemons = null;
-
-               try {
-                       $dataItem = call_user_func_array( array( $this, 
'newInstance' ), $args );
-                       $this->assertInstanceOf( '\SMWDataItem', $dataItem );
-               }
-               catch ( \Exception $pokemons ) {
-                       if ( $valid === true ) {
-                               throw $pokemons;
-                       }
-
-                       if ( is_string( $valid ) ) {
-                               $this->assertEquals( $valid, get_class( 
$pokemons ) );
-                       }
-                       else {
-                               $this->assertTrue( true );
-                       }
-               }
+               $this->assertInstanceOf( '\SMWDataItem', $dataItem );
+               $this->assertInstanceOf( $this->getClass(), $dataItem );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2d62592ac8183c6417ed4247b38fc33e471105a8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to