WMDE-leszek has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/351831 )
Change subject: Add tests for CognateStore's Read Only mode. ...................................................................... Add tests for CognateStore's Read Only mode. Also fixes the call of exception's constructor. Change-Id: I298171d6c166f03260d20de1428668b7462ea368 --- M src/CognateStore.php A tests/phpunit/CognateStoreUnitTest.php 2 files changed, 65 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cognate refs/changes/31/351831/1 diff --git a/src/CognateStore.php b/src/CognateStore.php index 94362bf..25a1775 100644 --- a/src/CognateStore.php +++ b/src/CognateStore.php @@ -335,7 +335,7 @@ * @throws DBReadOnlyError */ private function throwReadOnlyException() { - throw new DBReadOnlyError( 'Cognate is in Read Only mode' ); + throw new DBReadOnlyError( null, 'Cognate is in Read Only mode' ); } } diff --git a/tests/phpunit/CognateStoreUnitTest.php b/tests/phpunit/CognateStoreUnitTest.php new file mode 100644 index 0000000..e0edddf --- /dev/null +++ b/tests/phpunit/CognateStoreUnitTest.php @@ -0,0 +1,64 @@ +<?php + +namespace Cognate\Tests; + +use Cognate\CognateStore; +use Cognate\StringHasher; +use Cognate\StringNormalizer; +use TitleValue; +use Wikimedia\Rdbms\ConnectionManager; +use Wikimedia\Rdbms\DBReadOnlyError; + +/** + * @cover Cognate\CognateStore + * + * @license GNU GPL v2+ + */ +class CognateStoreUnitTest extends \PHPUnit_Framework_TestCase { + + private function newReadOnlyCognateStore() { + $connectionManager = $this->getMockBuilder( ConnectionManager::class ) + ->disableOriginalConstructor() + ->getMock(); + + return new CognateStore( + $connectionManager, + new StringNormalizer(), + new StringHasher(), + true + ); + } + + public function testWhenInReadOnlyMode_insertPageThrowsException() { + $store = $this->newReadOnlyCognateStore(); + + $this->setExpectedException( DBReadOnlyError::class ); + + $store->insertPage( 'foo', new TitleValue( 0, 'Some_Page' ) ); + } + + public function testWhenInReadOnlyMode_deletePageThrowsException() { + $store = $this->newReadOnlyCognateStore(); + + $this->setExpectedException( DBReadOnlyError::class ); + + $store->deletePage( 'foo', new TitleValue( 0, 'Some_Page' ) ); + } + + public function testWhenInReadOnlyMode_insertPagesThrowsException() { + $store = $this->newReadOnlyCognateStore(); + + $this->setExpectedException( DBReadOnlyError::class ); + + $store->insertPages( [ [ 'site' => 'foo', 'namespace' => 0, 'title' => 'Some_Page' ] ] ); + } + + public function testWhenInReadOnlyMode_insertSitesThrowsException() { + $store = $this->newReadOnlyCognateStore(); + + $this->setExpectedException( DBReadOnlyError::class ); + + $store->insertSites( [ 'foo' => 'f' ] ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/351831 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I298171d6c166f03260d20de1428668b7462ea368 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Cognate Gerrit-Branch: master Gerrit-Owner: WMDE-leszek <leszek.mani...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits