Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/50635
Change subject: Added TableBuilderTest ...................................................................... Added TableBuilderTest Change-Id: Ie172ebaf146495941f10e6d265433fe2577e5325 --- M repo/Wikibase.hooks.php M repo/tests/phpunit/includes/Database/FieldDefinitionTest.php A repo/tests/phpunit/includes/Database/TableBuilderTest.php M repo/tests/phpunit/includes/Database/TableDefinitionTest.php 4 files changed, 139 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/35/50635/1 diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php index 5f3e700..55587e8 100644 --- a/repo/Wikibase.hooks.php +++ b/repo/Wikibase.hooks.php @@ -186,6 +186,7 @@ 'content/PropertyHandler', 'Database/FieldDefinition', + 'Database/TableBuilder', 'Database/TableDefinition', 'specials/SpecialCreateItem', diff --git a/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php index 29943f8..122cbfb 100644 --- a/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php +++ b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php @@ -5,7 +5,7 @@ use Wikibase\Repo\Database\FieldDefinition; /** - * Unit test Wikibase\Repo\Database\FieldDefinitionTest class. + * Unit test Wikibase\Repo\Database\FieldDefinition class. * * 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 diff --git a/repo/tests/phpunit/includes/Database/TableBuilderTest.php b/repo/tests/phpunit/includes/Database/TableBuilderTest.php new file mode 100644 index 0000000..aa2d33f --- /dev/null +++ b/repo/tests/phpunit/includes/Database/TableBuilderTest.php @@ -0,0 +1,136 @@ +<?php + +namespace Wikibase\Repo\Test\Database; + +use Wikibase\Repo\Database\TableBuilder; +use Wikibase\Repo\Database\FieldDefinition; +use Wikibase\Repo\Database\TableDefinition; + +/** + * Unit test Wikibase\Repo\Database\TableBuilder class. + * + * 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 + * @since 0.4 + * + * @ingroup WikibaseRepoTest + * + * @group Wikibase + * @group WikibaseRepo + * @group WikibaseDatabase + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class TableBuilderTest extends \MediaWikiTestCase { + + public function tableNameProvider() { + return $this->arrayWrap( + array( + 'foo', + 'bar', + 'o', + 'foo_bar_baz', + 'foobarbaz', + ) + ); + } + + /** + * @dataProvider tableNameProvider + */ + public function testCreateTableCallsTableExists( $tableName ) { + $table = new TableDefinition( + $tableName, + array( new FieldDefinition( 'foo', FieldDefinition::TYPE_TEXT ) ) + ); + + $reporter = new NullMessageReporter(); + + $queryInterface = new ObservableQueryInterface(); + + $assertEquals = array( $this, 'assertEquals' ); + $callCount = 0; + + $queryInterface->registerCallback( + 'tableExists', + function( $tableName ) use ( $table, &$callCount, $assertEquals ) { + call_user_func( $assertEquals, $table->getName(), $tableName ); + $callCount += 1; + } + ); + + $builder = new TableBuilder( $queryInterface, $reporter ); + + $builder->createTable( $table ); + $this->assertEquals( 1, $callCount ); + } + +} + +use Wikibase\Repo\Database\QueryInterface; + +class ObservableQueryInterface implements QueryInterface { + + /** + * @var callable[] + */ + private $callbacks = array(); + + /** + * @param string $method + * @param callable $callback + */ + public function registerCallback( $method, $callback ) { + $this->callbacks[$method] = $callback; + } + + private function runCallbacks( $method, $args ) { + if ( array_key_exists( $method, $this->callbacks ) ) { + call_user_func_array( $this->callbacks[$method], $args ); + } + } + + /** + * @see QueryInterface::tableExists + * + * @param string $tableName + * + * @return boolean + */ + public function tableExists( $tableName ) { + $this->runCallbacks( __FUNCTION__, func_get_args() ); + } + +} + +use MessageReporter; + +class NullMessageReporter implements MessageReporter { + + /** + * @see MessageReporter::reportMessage + * + * @since 0.4 + * + * @param string $message + */ + public function reportMessage( $message ) { + // no-op + } + +} \ No newline at end of file diff --git a/repo/tests/phpunit/includes/Database/TableDefinitionTest.php b/repo/tests/phpunit/includes/Database/TableDefinitionTest.php index aa7681e..1a8baa5 100644 --- a/repo/tests/phpunit/includes/Database/TableDefinitionTest.php +++ b/repo/tests/phpunit/includes/Database/TableDefinitionTest.php @@ -6,7 +6,7 @@ use Wikibase\Repo\Database\TableDefinition; /** - * Unit test Wikibase\Repo\Database\TableDefinitionTest class. + * Unit test Wikibase\Repo\Database\TableDefinition class. * * 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 -- To view, visit https://gerrit.wikimedia.org/r/50635 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie172ebaf146495941f10e6d265433fe2577e5325 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits