Thiemo Mättig (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/331454 )
Change subject: Add missing negative test cases to ValueParserFactoryTest ...................................................................... Add missing negative test cases to ValueParserFactoryTest There are four exceptions in this class, and none was tested before. Change-Id: I96d1f2e3b46da85e37313f7614296d349f0b300f --- M repo/tests/phpunit/includes/ValueParserFactoryTest.php 1 file changed, 40 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/54/331454/1 diff --git a/repo/tests/phpunit/includes/ValueParserFactoryTest.php b/repo/tests/phpunit/includes/ValueParserFactoryTest.php index a9e096e..e0f4730 100644 --- a/repo/tests/phpunit/includes/ValueParserFactoryTest.php +++ b/repo/tests/phpunit/includes/ValueParserFactoryTest.php @@ -2,6 +2,9 @@ namespace Wikibase\Repo\Tests; +use InvalidArgumentException; +use LogicException; +use OutOfBoundsException; use ValueParsers\NullParser; use ValueParsers\ParserOptions; use ValueParsers\ValueParser; @@ -14,10 +17,47 @@ * * @license GPL-2.0+ * @author Adrian Heine <adrian.he...@wikimedia.de> + * @author Thiemo Mättig */ class ValueParserFactoryTest extends \PHPUnit_Framework_TestCase { /** + * @dataProvider provideInvalidConstructorArgument + */ + public function testInvalidConstructorArgument( array $valueParsers ) { + $this->setExpectedException( InvalidArgumentException::class ); + new ValueParserFactory( $valueParsers ); + } + + public function provideInvalidConstructorArgument() { + return [ + 'value is not a callable' => [ [ + 'id' => 'not a callable', + ] ], + 'id is not a string' => [ [ + function () { + }, + ] ], + ]; + } + + public function testNewParser_withUnknownParserId() { + $factory = new ValueParserFactory( [] ); + + $this->setExpectedException( OutOfBoundsException::class ); + $factory->newParser( 'unknown', new ParserOptions() ); + } + + public function testNewParser_withInvalidReturnValue() { + $factory = new ValueParserFactory( [ 'id' => function () { + return 'invalid'; + } ] ); + + $this->setExpectedException( LogicException::class ); + $factory->newParser( 'id', new ParserOptions() ); + } + + /** * @dataProvider provideFactoryFunctions */ public function testGetParserIds( $factoryFunctions ) { -- To view, visit https://gerrit.wikimedia.org/r/331454 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I96d1f2e3b46da85e37313f7614296d349f0b300f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits