jenkins-bot has submitted this change and it was merged. ( 
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(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



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: merged
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>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to