Mwjames has uploaded a new change for review.

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


Change subject: Improve code coverage
......................................................................

Improve code coverage

Change-Id: I5277756f78c09d15b052a42e3fd172628ba8a016
---
M SemanticMediaWiki.classes.php
M includes/jobs/UpdateJob.php
M includes/queryprinters/AggregatablePrinter.php
R includes/storage/SQLStore/TableDefinition.php
M tests/phpunit/MockObjectRepository.php
M tests/phpunit/includes/FactboxCacheTest.php
M tests/phpunit/includes/GlobalFunctionsTest.php
A tests/phpunit/includes/dataitems/DIPropertyTest.php
M tests/phpunit/includes/dic/SimpleDependencyBuilderTest.php
M tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
M tests/phpunit/includes/specials/SpecialsTest.php
A tests/phpunit/includes/storage/sqlstore/TableDefinitionTest.php
12 files changed, 265 insertions(+), 44 deletions(-)


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

diff --git a/SemanticMediaWiki.classes.php b/SemanticMediaWiki.classes.php
index 02f6ce7..0236925 100644
--- a/SemanticMediaWiki.classes.php
+++ b/SemanticMediaWiki.classes.php
@@ -289,8 +289,8 @@
        'SMW\SQLStore\PropertiesCollector'               => 
'includes/storage/SQLStore/PropertiesCollector.php',
        'SMW\SQLStore\PropertyTableDefinitionBuilder'    => 
'includes/storage/SQLStore/PropertyTableDefinitionBuilder.php',
 
-       'SMWSQLStore3Table'                => 
'includes/storage/SQLStore/SMW_SQLStore3Table.php', // Please fix me ...
-       'SMW\SQLStore\TableDefinition'     => 
'includes/storage/SQLStore/SMW_SQLStore3Table.php',
+       'SMWSQLStore3Table'                => 
'includes/storage/SQLStore/TableDefinition.php',
+       'SMW\SQLStore\TableDefinition'     => 
'includes/storage/SQLStore/TableDefinition.php',
 
        'SMWSQLStore3'                     => 
'includes/storage/SQLStore/SMW_SQLStore3.php',
        'SMWSql3StubSemanticData'          => 
'includes/storage/SQLStore/SMW_Sql3StubSemanticData.php',
diff --git a/includes/jobs/UpdateJob.php b/includes/jobs/UpdateJob.php
index 46bd7cb..3bfadd3 100644
--- a/includes/jobs/UpdateJob.php
+++ b/includes/jobs/UpdateJob.php
@@ -164,9 +164,9 @@
 }
 
 /**
+ * @codeCoverageIgnore
  * SMWUpdateJob
  *
  * @deprecated since 1.9
- * @codeCoverageIgnore
  */
 class_alias( 'SMW\UpdateJob', 'SMWUpdateJob' );
diff --git a/includes/queryprinters/AggregatablePrinter.php 
b/includes/queryprinters/AggregatablePrinter.php
index cc4a442..8e669bf 100644
--- a/includes/queryprinters/AggregatablePrinter.php
+++ b/includes/queryprinters/AggregatablePrinter.php
@@ -232,6 +232,7 @@
        }
 
        /**
+        * @codeCoverageIgnore
         * @see SMWResultPrinter::getParamDefinitions
         *
         * @since 1.8
@@ -279,6 +280,7 @@
 }
 
 /**
+ * @codeCoverageIgnore
  * SMWAggregatablePrinter
  *
  * @deprecated since SMW 1.9
diff --git a/includes/storage/SQLStore/SMW_SQLStore3Table.php 
b/includes/storage/SQLStore/TableDefinition.php
similarity index 90%
rename from includes/storage/SQLStore/SMW_SQLStore3Table.php
rename to includes/storage/SQLStore/TableDefinition.php
index 508cc33..de1902c 100644
--- a/includes/storage/SQLStore/SMW_SQLStore3Table.php
+++ b/includes/storage/SQLStore/TableDefinition.php
@@ -1,5 +1,9 @@
 <?php
 
+namespace SMW\SQLStore;
+
+use OutOfBoundsException;
+
 /**
  * Simple data container for storing information about property tables. A
  * property table is a DB table that is used to store subject-property-value
@@ -16,7 +20,7 @@
  * @author Markus Krötzsch
  * @author Jeroen De Dauw < [email protected] >
  */
-class SMWSQLStore3Table {
+class TableDefinition {
 
        /**
         * Name of the table in the DB.
@@ -86,7 +90,7 @@
        *
        * @return array
        */
-       public function getFields( SMWSQLStore3 $store ) {
+       public function getFields( \SMWSQLStore3 $store ) {
                $diHandler = $store->getDataItemHandlerForDIType( $this->diType 
);
                return $diHandler->getTableFields();
        }
@@ -123,11 +127,12 @@
         * @since 1.8
         *
         * @return string
-        * @throws MWException
+        * @throws OutOfBoundsException
         */
        public function getFixedProperty() {
+
                if ( $this->fixedProperty === false ) {
-                       throw new MWException( 'Attempt to get the fixed 
property from a table that does not hold one' );
+                       throw new OutOfBoundsException( 'Attempt to get the 
fixed property from a table that does not hold one' );
                }
 
                return $this->fixedProperty;
@@ -170,8 +175,9 @@
 }
 
 /**
+ * @codeCoverageIgnore
  * \SMW\SQLStore\TableDefinition
  *
  * @since 1.9
  */
-class_alias( 'SMWSQLStore3Table', 'SMW\SQLStore\TableDefinition' );
+class_alias( 'SMW\SQLStore\TableDefinition', 'SMWSQLStore3Table' );
diff --git a/tests/phpunit/MockObjectRepository.php 
b/tests/phpunit/MockObjectRepository.php
index f79429e..747981c 100644
--- a/tests/phpunit/MockObjectRepository.php
+++ b/tests/phpunit/MockObjectRepository.php
@@ -457,6 +457,11 @@
                        ->will( $this->returnValue( $this->builder->setValue( 
'getCount' ) ) );
 
                $queryResult->expects( $this->any() )
+                       ->method( 'serializeToArray' )
+                       ->will( $this->returnValue( $this->builder->setValue( 
'serializeToArray' ) ) );
+
+
+               $queryResult->expects( $this->any() )
                        ->method( 'getPrintRequests' )
                        ->will( $this->returnValue( $this->builder->setValue( 
'getPrintRequests' ) ) );
 
diff --git a/tests/phpunit/includes/FactboxCacheTest.php 
b/tests/phpunit/includes/FactboxCacheTest.php
index 64846ae..95dca36 100644
--- a/tests/phpunit/includes/FactboxCacheTest.php
+++ b/tests/phpunit/includes/FactboxCacheTest.php
@@ -68,6 +68,15 @@
        }
 
        /**
+        * @test FactboxCache::newCacheId
+        *
+        * @since 1.9
+        */
+       public function testNewCacheId() {
+               $this->assertInstanceOf( '\SMW\CacheIdGenerator', 
FactboxCache::newCacheId( 9001 ) );
+       }
+
+       /**
         * @test FactboxCache::process
         * @test FactboxCache::retrieveContent
         * @dataProvider outputDataProvider
diff --git a/tests/phpunit/includes/GlobalFunctionsTest.php 
b/tests/phpunit/includes/GlobalFunctionsTest.php
index b5cd850..f07ed52 100644
--- a/tests/phpunit/includes/GlobalFunctionsTest.php
+++ b/tests/phpunit/includes/GlobalFunctionsTest.php
@@ -35,6 +35,7 @@
        }
 
        /**
+        * @covers ::smwfGetLinker
         * @test smwfGetLinker
         *
         * @since 1.9
@@ -47,6 +48,7 @@
        }
 
        /**
+        * @covers ::smwfNormalTitleDBKey
         * @test smwfNormalTitleDBKey
         *
         * @since 1.9
@@ -60,6 +62,7 @@
        }
 
        /**
+        * @covers ::smwfHTMLtoUTF8
         * @test smwfHTMLtoUTF8
         *
         * @since 1.9
@@ -82,6 +85,7 @@
        }
 
        /**
+        * @covers ::smwfEncodeMessages
         * @test smwfEncodeMessages
         * @dataProvider getEncodeMessagesDataProvider
         *
diff --git a/tests/phpunit/includes/dataitems/DIPropertyTest.php 
b/tests/phpunit/includes/dataitems/DIPropertyTest.php
new file mode 100644
index 0000000..9dfd5b0
--- /dev/null
+++ b/tests/phpunit/includes/dataitems/DIPropertyTest.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace SMW\Tests;
+
+/**
+ * @covers \SMW\DIProperty
+ * @covers SMWDataItem
+ *
+ * @file
+ * @since 1.8\SMW\DIProperty
+ *
+ * @ingroup SMW
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ * @group SMWDataItems
+ *
+ * @author Nischay Nahata
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class DIPropertyTest extends DataItemTest {
+
+       /**
+        * @see DataItemTest::getClass
+        *
+        * @since 1.8
+        *
+        * @return string
+        */
+       public function getClass() {
+               return '\SMWDIProperty';
+       }
+
+       /**
+        * @see DataItemTest::constructorProvider
+        *
+        * @since 1.8
+        *
+        * @return array
+        */
+       public function constructorProvider() {
+               return array(
+                       array( true, 0 ),
+                       array( true, 243.35353 ),
+                       array( true, 'ohi there' ),
+                       array( false, array() ),
+                       array( false, true ),
+               );
+       }
+
+}
\ No newline at end of file
diff --git a/tests/phpunit/includes/dic/SimpleDependencyBuilderTest.php 
b/tests/phpunit/includes/dic/SimpleDependencyBuilderTest.php
index 8ee4da9..aa4d513 100644
--- a/tests/phpunit/includes/dic/SimpleDependencyBuilderTest.php
+++ b/tests/phpunit/includes/dic/SimpleDependencyBuilderTest.php
@@ -836,6 +836,9 @@
                // #3
                $provider[] = array( $closure, $stdClass );
 
+               // #4
+               $provider[] = array( 'stdClass', $stdClass );
+
                return $provider;
        }
 
diff --git a/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php 
b/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
index a32da5a..712fcde 100644
--- a/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
+++ b/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
@@ -5,8 +5,6 @@
 use SMW\JsonResultPrinter;
 use SMW\ResultPrinter;
 
-use ReflectionClass;
-
 /**
  * Tests for the JsonResultPrinter class
  *
@@ -38,35 +36,11 @@
        }
 
        /**
-        * Helper method that returns a SMWQueryResult object
-        *
-        * @since 1.9
-        *
-        * @return SMWQueryResult
-        */
-       private function getMockQueryResult( $result = array() ) {
-
-               $queryResult = $this->getMockBuilder( 'SMWQueryResult' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $queryResult->expects( $this->any() )
-                       ->method( 'getCount' )
-                       ->will( $this->returnValue( count( $result ) ) );
-
-               $queryResult->expects( $this->any() )
-                       ->method( 'serializeToArray' )
-                       ->will( $this->returnValue( $result ) );
-
-               return $queryResult;
-       }
-
-       /**
         * Helper method that returns a JsonResultPrinter object
         *
         * @return JsonResultPrinter
         */
-       private function getInstance( $parameters = array() ) {
+       private function newInstance( $parameters = array() ) {
                return $this->setParameters( new JsonResultPrinter( 'json' ), 
$parameters );
        }
 
@@ -76,21 +50,54 @@
         * @since 1.9
         */
        public function testConstructor() {
-               $this->assertInstanceOf( $this->getClass(), 
$this->getInstance() );
+               $this->assertInstanceOf( $this->getClass(), 
$this->newInstance() );
+       }
+
+       /**
+        * @test JsonResultPrinter::getMimeType
+        *
+        * @since 1.9
+        */
+       public function testGetMimeType() {
+
+               $this->assertEquals(
+                       'application/json',
+                       $this->newInstance()->getMimeType( 
$this->newMockBuilder()->newObject( 'QueryResult' ) ),
+                       'Asserts that getMimeType() yields an expected result'
+               );
+
        }
 
        /**
         * @test JsonResultPrinter::getFileName
+        * @dataProvider filenameDataProvider
         *
         * @since 1.9
         */
-       public function testGetFileName() {
+       public function testGetFileName( $filename, $expected ) {
 
-               $filename = $this->getRandomString() . ' ' . 
$this->getRandomString();
-               $expected = str_replace( ' ', '_', $filename ) . '.json';
-               $instance = $this->getInstance( array( 'searchlabel' => 
$filename ) );
+               $instance = $this->newInstance( array( 'searchlabel' => 
$filename ) );
 
-               $this->assertEquals( $expected, $instance->getFileName( 
$this->getMockQueryResult() ) );
+               $this->assertEquals(
+                       $expected,
+                       $instance->getFileName( 
$this->newMockBuilder()->newObject( 'QueryResult' ) ),
+                       'Asserts that getFileName() yields an expected result');
+       }
+
+       /**
+        * @return array
+        */
+       public function filenameDataProvider() {
+
+               $provider = array();
+
+               $provider[] = array( 'Lala', 'Lala.json' );
+               $provider[] = array( 'Lala Lilu', 'Lala_Lilu.json' );
+               $provider[] = array( '' , 'result.json');
+
+               return $provider;
+
+
        }
 
        /**
@@ -107,13 +114,18 @@
 
                $expected = array_merge( $result, array( 'rows' => count( 
$result ) ) );
 
-               $instance = $this->getInstance( array( 'prettyprint' => false ) 
);
+               $instance = $this->newInstance( array( 'prettyprint' => false ) 
);
 
-               $reflector = new ReflectionClass( $this->getClass() );
+               $reflector = $this->newReflector();
                $getResultText = $reflector->getMethod( 'getResultText' );
                $getResultText->setAccessible( true );
 
-               $results = $getResultText->invoke( $instance, 
$this->getMockQueryResult( $result ), SMW_OUTPUT_FILE );
+               $queryResult = $this->newMockBuilder()->newObject( 
'QueryResult', array(
+                       'serializeToArray' => $result,
+                       'getCount'         => count( $result )
+               ) );
+
+               $results = $getResultText->invoke( $instance, $queryResult, 
SMW_OUTPUT_FILE );
 
                $this->assertInternalType( 'string', $results );
                $this->assertEquals( json_encode( $expected ), $results );
diff --git a/tests/phpunit/includes/specials/SpecialsTest.php 
b/tests/phpunit/includes/specials/SpecialsTest.php
index 3a1f88b..62d705b 100644
--- a/tests/phpunit/includes/specials/SpecialsTest.php
+++ b/tests/phpunit/includes/specials/SpecialsTest.php
@@ -27,6 +27,10 @@
  * @covers \SMW\SpecialProperties
  * @covers \SMW\SpecialConcepts
  * @covers \SMW\SpecialPage
+ * @covers SMWAskPage
+ * @covers SMWSpecialBrowse
+ * @covers SMWAdmin
+ * @covers SMWSearchByProperty
  *
  * @note Test base was borrowed from the EducationProgram extension
  *
diff --git a/tests/phpunit/includes/storage/sqlstore/TableDefinitionTest.php 
b/tests/phpunit/includes/storage/sqlstore/TableDefinitionTest.php
new file mode 100644
index 0000000..b2977d1
--- /dev/null
+++ b/tests/phpunit/includes/storage/sqlstore/TableDefinitionTest.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace SMW\Test\SQLStore;
+
+use SMW\SQLStore\TableDefinition;
+use SMW\StoreFactory;
+
+use SMWDataItem;
+
+/**
+ * Test for the TableDefinition class
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * @covers \SMW\SQLStore\TableDefinition
+ *
+ * @ingroup SQLStoreTest
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class TableDefinitionTest extends \SMW\Test\SemanticMediaWikiTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMW\SQLStore\TableDefinition';
+       }
+
+       /**
+        * Helper method that returns a TableDefinition object
+        *
+        * @since 1.9
+        *
+        * @return TableDefinition
+        */
+       private function newInstance( $DIType = '' , $tableName = '' ) {
+               return new TableDefinition( $DIType, $tableName );
+       }
+
+       /**
+        * @test TableDefinition::__construct
+        *
+        * @since 1.9
+        */
+       public function testConstructor() {
+               $this->assertInstanceOf( $this->getClass(), 
$this->newInstance() );
+       }
+
+       /**
+        * @test TableDefinition::getFields
+        * @test TableDefinition::getDiType
+        * @test TableDefinition::getName
+        *
+        * @since 1.9
+        */
+       public function testGetters() {
+
+               $diType = SMWDataItem::TYPE_NUMBER;
+               $name   = 'smw_di_number';
+
+               $instance = $this->newInstance( $diType, $name );
+
+               $this->assertInternalType(
+                       'array',
+                       $instance->getFields( StoreFactory::getStore( 
'SMWSQLStore3' ) ),
+                       'Asserts that getFields() returns an array'
+               );
+
+               $this->assertEquals(
+                       $diType,
+                       $instance->getDiType(),
+                       'Asserts that getDiType() returns the corret object'
+               );
+
+               $this->assertEquals(
+                       $name,
+                       $instance->getName(),
+                       'Asserts that getName() returns the corret object'
+               );
+
+       }
+
+       /**
+        * @test TableDefinition::usesIdSubject
+        * @test TableDefinition::setUsesIdSubject
+        *
+        * @since 1.9
+        */
+       public function testIdSubject() {
+
+               $instance = $this->newInstance();
+               $instance->setUsesIdSubject( false );
+
+               $this->assertFalse(
+                       $instance->usesIdSubject(),
+                       'Asserts that usesIdSubject() returns false'
+               );
+
+       }
+
+       /**
+        * @test TableDefinition::getFixedProperty
+        *
+        * @since 1.9
+        */
+       public function testGetFixedProperty() {
+
+               $this->setExpectedException( 'OutOfBoundsException' );
+               $this->newInstance()->getFixedProperty();
+
+       }
+
+}

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

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