Addshore has uploaded a new change for review.

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


Change subject: Add various todos accross the component
......................................................................

Add various todos accross the component

These todos have come from
 - reviewing code (including escaping)
 - testing various methods
 - reviewing test coverage

Change-Id: I3520372b8d958a60120a00d0ce4c7012dbb8f8cb
---
M src/MySQL/MySQLFieldSqlBuilder.php
M src/MySQL/MySQLTableDefinitionReader.php
M src/MySQL/MySQLTableSqlBuilder.php
M src/SQLite/SQLiteFieldSqlBuilder.php
M src/SQLite/SQLiteIndexSqlBuilder.php
M src/SQLite/SQLiteSchemaSqlBuilder.php
M src/SQLite/SQLiteTableSqlBuilder.php
M tests/integration/MediaWiki/Schema/TableCreateReadDeleteTest.php
M tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
M tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
M tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
M tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
M tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
M tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
M tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
M tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
M tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
M tests/phpunit/Schema/ReportingTableBuilderTest.php
18 files changed, 77 insertions(+), 9 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDatabase 
refs/changes/62/89162/1

diff --git a/src/MySQL/MySQLFieldSqlBuilder.php 
b/src/MySQL/MySQLFieldSqlBuilder.php
index bcfcfd5..0e5a64b 100644
--- a/src/MySQL/MySQLFieldSqlBuilder.php
+++ b/src/MySQL/MySQLFieldSqlBuilder.php
@@ -24,6 +24,7 @@
        }
 
        public function getFieldSQL( FieldDefinition $field ){
+               //todo escape name once identifier escaping is implemented
                $sql =  $field->getName() . ' ';
 
                $sql .= $this->getFieldType( $field->getType() );
@@ -33,6 +34,7 @@
                $sql .= $this->getNull( $field->allowsNull() );
 
                // TODO: add all field stuff relevant here
+               //TODO use field->autoIncrement and add to sql if needed
 
                return $sql;
        }
@@ -63,6 +65,7 @@
                                return 'INT';
                        case FieldDefinition::TYPE_FLOAT:
                                return 'FLOAT';
+                       //todo define max length of text fields?
                        case FieldDefinition::TYPE_TEXT:
                                return 'BLOB';
                        case FieldDefinition::TYPE_BOOLEAN:
diff --git a/src/MySQL/MySQLTableDefinitionReader.php 
b/src/MySQL/MySQLTableDefinitionReader.php
index 0ae97e0..43e62c6 100644
--- a/src/MySQL/MySQLTableDefinitionReader.php
+++ b/src/MySQL/MySQLTableDefinitionReader.php
@@ -97,6 +97,7 @@
                } else if ( stristr( $dataType, 'float' ) ){
                        return FieldDefinition::TYPE_FLOAT;
                } else {
+                       //TODO FIXME decide if this is the correct behaviour or 
throw a RuntimeException
                        return $dataType;
                }
        }
diff --git a/src/MySQL/MySQLTableSqlBuilder.php 
b/src/MySQL/MySQLTableSqlBuilder.php
index 20316d5..41d3818 100644
--- a/src/MySQL/MySQLTableSqlBuilder.php
+++ b/src/MySQL/MySQLTableSqlBuilder.php
@@ -34,6 +34,7 @@
                $this->dbName = $dbName;
                $this->escaper = $fieldValueEscaper;
                $this->tableNameFormatter = $tableNameFormatter;
+               //TODO inject sqlbuilder
                $this->fieldSqlBuilder = new MySQLFieldSqlBuilder( 
$this->escaper );
        }
 
@@ -79,10 +80,13 @@
                $sql = $this->getIndexType( $index->getType() );
 
                if( $index->getType() !== IndexDefinition::TYPE_PRIMARY ){
+                       //todo escape name once identifier escaping is 
implemented
                        $sql .= ' `'.$index->getName().'`';
                }
 
                $columnNames = array();
+               //TODO FIXME Error: 1170 BLOB/TEXT column 'textfield' used in 
key specification without a key length (localhost)
+               //todo $intSize here needs to specify the length of the key for 
text fields.
                foreach( $index->getColumns() as $columnName => $intSize ){
                        $columnNames[] = $columnName;
                }
diff --git a/src/SQLite/SQLiteFieldSqlBuilder.php 
b/src/SQLite/SQLiteFieldSqlBuilder.php
index 3a3d048..d67bd8c 100644
--- a/src/SQLite/SQLiteFieldSqlBuilder.php
+++ b/src/SQLite/SQLiteFieldSqlBuilder.php
@@ -24,6 +24,7 @@
        }
 
        public function getFieldSQL( FieldDefinition $field ){
+               //todo escape name once identifier escaping is implemented
                $sql = $field->getName() . ' ';
 
                $sql .= $this->getFieldType( $field->getType() );
@@ -32,6 +33,8 @@
 
                $sql .= $this->getNull( $field->allowsNull() );
 
+               //TODO use field->autoIncrement and add to sql if needed
+
                return $sql;
        }
 
diff --git a/src/SQLite/SQLiteIndexSqlBuilder.php 
b/src/SQLite/SQLiteIndexSqlBuilder.php
index 1716897..676f534 100644
--- a/src/SQLite/SQLiteIndexSqlBuilder.php
+++ b/src/SQLite/SQLiteIndexSqlBuilder.php
@@ -27,6 +27,7 @@
        public function getIndexSQL( IndexDefinition $index, $tableName ){
                $sql = 'CREATE ';
                $sql .= $this->getIndexType( $index->getType() ) . ' ';
+               //todo escape name once identifier escaping is implemented
                $sql .= $index->getName() . ' ';
                $sql .= 'ON ' . $this->tableNameFormatter->formatTableName( 
$tableName );
 
@@ -55,6 +56,7 @@
                        case IndexDefinition::TYPE_UNIQUE:
                                return 'UNIQUE INDEX';
                        default:
+                               //TODO FIXME SQLite doesnt actually support 
primary keys, but we probably want to support them some how
                                throw new RuntimeException( __CLASS__ . ' does 
not support db indexes of type ' . $indexType );
                }
        }
diff --git a/src/SQLite/SQLiteSchemaSqlBuilder.php 
b/src/SQLite/SQLiteSchemaSqlBuilder.php
index a84c743..2c9d14c 100644
--- a/src/SQLite/SQLiteSchemaSqlBuilder.php
+++ b/src/SQLite/SQLiteSchemaSqlBuilder.php
@@ -62,6 +62,7 @@
        private function getFieldsSql( $fields ){
                $fieldNames = array();
                foreach( $fields as $field ){
+                       //todo escape name once identifier escaping is 
implemented
                        $fieldNames[] = $field->getName();
                }
                return implode( ', ', $fieldNames );
diff --git a/src/SQLite/SQLiteTableSqlBuilder.php 
b/src/SQLite/SQLiteTableSqlBuilder.php
index 44079ca..0e55e69 100644
--- a/src/SQLite/SQLiteTableSqlBuilder.php
+++ b/src/SQLite/SQLiteTableSqlBuilder.php
@@ -32,6 +32,7 @@
        public function __construct( Escaper $fieldValueEscaper, 
TableNameFormatter $tableNameFormatter ) {
                $this->escaper = $fieldValueEscaper;
                $this->tableNameFormatter = $tableNameFormatter;
+               //TODO inject sqlbuilders
                $this->fieldSqlBuilder = new SQLiteFieldSqlBuilder( 
$this->escaper );
                $this->indexSqlBuilder = new SQLiteIndexSqlBuilder( 
$tableNameFormatter );
        }
diff --git a/tests/integration/MediaWiki/Schema/TableCreateReadDeleteTest.php 
b/tests/integration/MediaWiki/Schema/TableCreateReadDeleteTest.php
index f2d051d..2aef0c6 100644
--- a/tests/integration/MediaWiki/Schema/TableCreateReadDeleteTest.php
+++ b/tests/integration/MediaWiki/Schema/TableCreateReadDeleteTest.php
@@ -69,25 +69,30 @@
                ) );
 
                $tables[] = new TableDefinition( 'default_field_values', array(
-                       new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, true, 42 ),
+                       new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NULL, 42 ),
                ) );
 
                $tables[] = new TableDefinition( 'not_null_fields', array(
-                       new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, false ),
-                       new FieldDefinition( 'textfield', 
FieldDefinition::TYPE_TEXT, false ),
+                       new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NOT_NULL ),
+                       new FieldDefinition( 'textfield', 
FieldDefinition::TYPE_TEXT, FieldDefinition::NOT_NULL ),
                ) );
 
                $tables[] = new TableDefinition( 'not_null_fields', array(
-                       new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, false ),
-                       new FieldDefinition( 'textfield', 
FieldDefinition::TYPE_TEXT, false ),
+                       new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NOT_NULL ),
+                       new FieldDefinition( 'textfield', 
FieldDefinition::TYPE_TEXT, FieldDefinition::NULL ),
                ) );
 
                $tables[] = new TableDefinition( 'default_field_values', array(
-                               new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, false ),
-                               new FieldDefinition( 'floatfield', 
FieldDefinition::TYPE_FLOAT, false ),
-                               new FieldDefinition( 'boolfield', 
FieldDefinition::TYPE_BOOLEAN, false ),
+                               new FieldDefinition( 'textfield', 
FieldDefinition::TYPE_TEXT, FieldDefinition::NOT_NULL ),
+                               new FieldDefinition( 'intfield', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NULL, 3 ),
+                               new FieldDefinition( 'floatfield', 
FieldDefinition::TYPE_FLOAT, FieldDefinition::NOT_NULL ),
+                               new FieldDefinition( 'boolfield', 
FieldDefinition::TYPE_BOOLEAN, FieldDefinition::NOT_NULL, true ),
                        ),
-                       array( new IndexDefinition( 'somename', array( 
'intfield' => 0, 'floatfield' => 0 ) ) )
+                       array(
+                               //TODO uncomment the below line in test once 
text keys correctly specify a key length
+                               //new IndexDefinition( 'PRIMARY', array( 
'textfield' => 100 ), IndexDefinition::TYPE_PRIMARY ),
+                               new IndexDefinition( 'somename', array( 
'intfield' => 0, 'floatfield' => 0 ) )
+                       )
                );
 
                $argLists = array();
diff --git a/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php 
b/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
index 0c75813..ae9bfe1 100644
--- a/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
+++ b/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
@@ -52,4 +52,8 @@
                $this->assertInstanceOf( 
'Wikibase\Database\Schema\TableBuilder', $tableBuilder );
        }
 
+       public function testUnsupportedDbType(){
+               $this->markTestIncomplete( 'Test RuntimeException on 
unsupported DB type' );
+       }
+
 }
diff --git a/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php 
b/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
index b9a8730..6c076fa 100644
--- a/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
+++ b/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
@@ -50,4 +50,8 @@
                $this->assertInstanceOf( 
'Wikibase\Database\Schema\TableDefinitionReader', $tableDefinitionReader );
        }
 
+       public function testUnsupportedDbType(){
+               $this->markTestIncomplete( 'Test RuntimeException on 
unsupported DB type' );
+       }
+
 }
diff --git a/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php 
b/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
index f5c1f67..97606f7 100644
--- a/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
+++ b/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
@@ -339,6 +339,10 @@
                return $argLists;
        }
 
+       public function testSelectFailure() {
+               $this->markTestIncomplete( 'write test for 
MediaWikiQueryInterface select SelectFailedException' );
+       }
+
 }
 
 class DirectConnectionProvider implements DBConnectionProvider {
diff --git a/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php 
b/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
index 97b57e7..2099fdd 100644
--- a/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
+++ b/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
@@ -39,6 +39,9 @@
        public function fieldAndSqlProvider() {
                $argLists = array();
 
+               //TODO testcase with type INTEGER
+               //TODO testcase with type FLOAT
+
                $argLists[] = array(
                        new FieldDefinition(
                                'fieldName',
@@ -70,4 +73,8 @@
                return $argLists;
        }
 
+       public function testUnsupportedType(){
+               $this->markTestIncomplete( 'Test RuntimeException on 
unsupported field type' );
+       }
+
 }
\ No newline at end of file
diff --git a/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php 
b/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
index 18d3424..00bd151 100644
--- a/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
+++ b/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
@@ -34,6 +34,9 @@
        public function fieldAndSqlProvider() {
                $argLists = array();
 
+               //TODO test with type TYPE_SPATIAL
+               //TODO test with type TYPE_FULLTEXT
+
                $argLists[] = array(
                        new IndexDefinition(
                                'indexName',
@@ -64,4 +67,8 @@
                return $argLists;
        }
 
+       public function testUnsupportedType(){
+               $this->markTestIncomplete( 'Test RuntimeException on 
unsupported index type' );
+       }
+
 }
\ No newline at end of file
diff --git a/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php 
b/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
index 6a09747..dbaac65 100644
--- a/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
+++ b/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
@@ -39,6 +39,10 @@
                return new MySQLTableDefinitionReader( $mockQueryInterface );
        }
 
+       public function testReadNonExistentTable(){
+               $this->markTestIncomplete( 'Test QueryInterfaceException on 
reading non existant table' );
+       }
+
        /**
         * @dataProvider sqlAndDefinitionProvider
         */
@@ -51,6 +55,10 @@
        public function sqlAndDefinitionProvider() {
                $argLists = array();
 
+               //TODO test field type TYPE_BOOLEAN
+               //TODO test field type TYPE_FLOAT
+               //TODO test case containing constraints PRIMARY & UNIQUE
+
                $argLists[] = array(
                        array(
                                array(
diff --git a/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php 
b/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
index bc74505..cf0b677 100644
--- a/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
+++ b/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
@@ -69,4 +69,8 @@
                return $argLists;
        }
 
+       public function testUnsupportedType(){
+               $this->markTestIncomplete( 'Test RuntimeException on 
unsupported field type' );
+       }
+
 }
\ No newline at end of file
diff --git a/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php 
b/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
index 4872f12..002cf4d 100644
--- a/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
+++ b/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
@@ -57,4 +57,8 @@
                return $argLists;
        }
 
+       public function testUnsupportedType(){
+               $this->markTestIncomplete( 'Test RuntimeException on 
unsupported index type' );
+       }
+
 }
\ No newline at end of file
diff --git a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php 
b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
index 9e080cb..c43136a 100644
--- a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
+++ b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
@@ -39,6 +39,10 @@
                return new SQLiteTableDefinitionReader( $mockQueryInterface );
        }
 
+       public function testReadNonExistentTable(){
+               $this->markTestIncomplete( 'Test QueryInterfaceException on 
reading non existant table' );
+       }
+
        /**
         * @dataProvider sqlAndDefinitionProvider
         */
diff --git a/tests/phpunit/Schema/ReportingTableBuilderTest.php 
b/tests/phpunit/Schema/ReportingTableBuilderTest.php
index 12ed8cb..b835afb 100644
--- a/tests/phpunit/Schema/ReportingTableBuilderTest.php
+++ b/tests/phpunit/Schema/ReportingTableBuilderTest.php
@@ -17,6 +17,8 @@
  */
 class ReportingTableBuilderTest extends \PHPUnit_Framework_TestCase {
 
+       //TODO test tableExists method
+
        /**
         * @dataProvider tableProvider
         */

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3520372b8d958a60120a00d0ce4c7012dbb8f8cb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseDatabase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>

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

Reply via email to