[MediaWiki-commits] [Gerrit] Add logic and tests for getRemoveIndexSql - change (mediawiki...WikibaseDatabase)
Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/88053 Change subject: Add logic and tests for getRemoveIndexSql .. Add logic and tests for getRemoveIndexSql Change-Id: Ifbca2d9f98f73e66740e1126c76283511fdf2745 --- M src/MySQL/MySQLSchemaSqlBuilder.php M src/SQLite/SQLiteSchemaSqlBuilder.php M tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php M tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php 4 files changed, 22 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDatabase refs/changes/53/88053/1 diff --git a/src/MySQL/MySQLSchemaSqlBuilder.php b/src/MySQL/MySQLSchemaSqlBuilder.php index a4f0c94..30c0ab1 100644 --- a/src/MySQL/MySQLSchemaSqlBuilder.php +++ b/src/MySQL/MySQLSchemaSqlBuilder.php @@ -56,7 +56,8 @@ * @return string */ public function getRemoveIndexSql( $tableName, $indexName ){ - //TODO + $tableName = $this->tableNameFormatter->formatTableName( $tableName ); + return "DROP INDEX {$indexName} ON {$tableName}"; } /** diff --git a/src/SQLite/SQLiteSchemaSqlBuilder.php b/src/SQLite/SQLiteSchemaSqlBuilder.php index 003091a..564b8fa 100644 --- a/src/SQLite/SQLiteSchemaSqlBuilder.php +++ b/src/SQLite/SQLiteSchemaSqlBuilder.php @@ -86,7 +86,8 @@ * @return string */ public function getRemoveIndexSql( $tableName, $indexName ){ - //TODO + $tableName = $this->tableNameFormatter->formatTableName( $tableName ); + return "DROP INDEX IF EXISTS {$tableName}.{$indexName}"; } /** diff --git a/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php b/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php index 1094833..7580d98 100644 --- a/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php +++ b/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php @@ -44,4 +44,10 @@ $this->assertEquals( 'ALTER TABLE tableName ADD intField INT DEFAULT 42 NOT NULL', $sql ); } + public function testGetRemoveIndexSql(){ + $instance = $this->newInstance(); + $sql = $instance->getRemoveIndexSql( 'tableName', 'indexName' ); + $this->assertEquals( "DROP INDEX indexName ON tableName", $sql ); + } + } \ No newline at end of file diff --git a/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php b/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php index 48cab7a..57d7f58 100644 --- a/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php +++ b/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php @@ -19,7 +19,7 @@ */ class SQLiteSchemaSqlBuilderTest extends \PHPUnit_Framework_TestCase { - private function newInstance( $existingDefinition ) { + private function newInstance( $existingDefinition = null ) { $mockEscaper = $this->getMock( 'Wikibase\Database\Escaper' ); $mockEscaper->expects( $this->any() ) ->method( 'getEscapedValue' ) @@ -34,7 +34,7 @@ ->getMockBuilder( 'Wikibase\Database\SQLite\SQLiteTableDefinitionReader' ) ->disableOriginalConstructor() ->getMock(); - $mockQueryInterface->expects( $this->atLeastOnce() ) + $mockQueryInterface->expects( $this->any() ) ->method( 'readDefinition' ) ->will( $this->returnValue( $existingDefinition ) ); @@ -70,4 +70,14 @@ $this->assertEquals( 'ALTER TABLE tableName RENAME TO tableName_tmp;CREATE TABLE tableName (primaryField INT NOT NULL, intField INT DEFAULT 42 NOT NULL);CREATE INDEX INDEX ON tableName (intField,primaryField);INSERT INTO tableName(primaryField, intField) SELECT primaryField, intField FROM tableName_tmp;DROP TABLE tableName_tmp;', $sql ); } + public function testGetRemoveFieldSql(){ + $this->markTestIncomplete( 'testme!' ); //TODO complete the test! + } + + public function testGetRemoveIndexSql(){ + $instance = $this->newInstance( ); + $sql = $instance->getRemoveIndexSql( 'tableName', 'textField' ); + $this->assertEquals( "DROP INDEX IF EXISTS tableName.textField", $sql ); + } + } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/88053 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifbca2d9f98f73e66740e1126c76283511fdf2745 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseDatabase Gerrit-Branch: master Gerrit-Owner: Addshore ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] Add logic and tests for getRemoveIndexSql - change (mediawiki...WikibaseDatabase)
Jeroen De Dauw has submitted this change and it was merged. Change subject: Add logic and tests for getRemoveIndexSql .. Add logic and tests for getRemoveIndexSql Change-Id: Ifbca2d9f98f73e66740e1126c76283511fdf2745 --- M src/MySQL/MySQLSchemaSqlBuilder.php M src/SQLite/SQLiteSchemaSqlBuilder.php M tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php M tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php 4 files changed, 22 insertions(+), 4 deletions(-) Approvals: Jeroen De Dauw: Looks good to me, approved jenkins-bot: Verified diff --git a/src/MySQL/MySQLSchemaSqlBuilder.php b/src/MySQL/MySQLSchemaSqlBuilder.php index 5db7acc..6a52259 100644 --- a/src/MySQL/MySQLSchemaSqlBuilder.php +++ b/src/MySQL/MySQLSchemaSqlBuilder.php @@ -56,7 +56,8 @@ * @return string */ public function getRemoveIndexSql( $tableName, $indexName ){ - //TODO + $tableName = $this->tableNameFormatter->formatTableName( $tableName ); + return "DROP INDEX {$indexName} ON {$tableName}"; } /** diff --git a/src/SQLite/SQLiteSchemaSqlBuilder.php b/src/SQLite/SQLiteSchemaSqlBuilder.php index 4246d41..8f90a6e 100644 --- a/src/SQLite/SQLiteSchemaSqlBuilder.php +++ b/src/SQLite/SQLiteSchemaSqlBuilder.php @@ -86,7 +86,8 @@ * @return string */ public function getRemoveIndexSql( $tableName, $indexName ){ - //TODO + $tableName = $this->tableNameFormatter->formatTableName( $tableName ); + return "DROP INDEX IF EXISTS {$tableName}.{$indexName}"; } /** diff --git a/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php b/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php index 1094833..7580d98 100644 --- a/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php +++ b/tests/phpunit/MySQL/MySQLSchemaSqlBuilderTest.php @@ -44,4 +44,10 @@ $this->assertEquals( 'ALTER TABLE tableName ADD intField INT DEFAULT 42 NOT NULL', $sql ); } + public function testGetRemoveIndexSql(){ + $instance = $this->newInstance(); + $sql = $instance->getRemoveIndexSql( 'tableName', 'indexName' ); + $this->assertEquals( "DROP INDEX indexName ON tableName", $sql ); + } + } \ No newline at end of file diff --git a/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php b/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php index 48cab7a..57d7f58 100644 --- a/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php +++ b/tests/phpunit/SQLite/SQLiteSchemaSqlBuilderTest.php @@ -19,7 +19,7 @@ */ class SQLiteSchemaSqlBuilderTest extends \PHPUnit_Framework_TestCase { - private function newInstance( $existingDefinition ) { + private function newInstance( $existingDefinition = null ) { $mockEscaper = $this->getMock( 'Wikibase\Database\Escaper' ); $mockEscaper->expects( $this->any() ) ->method( 'getEscapedValue' ) @@ -34,7 +34,7 @@ ->getMockBuilder( 'Wikibase\Database\SQLite\SQLiteTableDefinitionReader' ) ->disableOriginalConstructor() ->getMock(); - $mockQueryInterface->expects( $this->atLeastOnce() ) + $mockQueryInterface->expects( $this->any() ) ->method( 'readDefinition' ) ->will( $this->returnValue( $existingDefinition ) ); @@ -70,4 +70,14 @@ $this->assertEquals( 'ALTER TABLE tableName RENAME TO tableName_tmp;CREATE TABLE tableName (primaryField INT NOT NULL, intField INT DEFAULT 42 NOT NULL);CREATE INDEX INDEX ON tableName (intField,primaryField);INSERT INTO tableName(primaryField, intField) SELECT primaryField, intField FROM tableName_tmp;DROP TABLE tableName_tmp;', $sql ); } + public function testGetRemoveFieldSql(){ + $this->markTestIncomplete( 'testme!' ); //TODO complete the test! + } + + public function testGetRemoveIndexSql(){ + $instance = $this->newInstance( ); + $sql = $instance->getRemoveIndexSql( 'tableName', 'textField' ); + $this->assertEquals( "DROP INDEX IF EXISTS tableName.textField", $sql ); + } + } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/88053 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifbca2d9f98f73e66740e1126c76283511fdf2745 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/WikibaseDatabase Gerrit-Branch: master Gerrit-Owner: Addshore Gerrit-Reviewer: Jeroen De Dauw Gerrit-Reviewer: jenkins-bot ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits