Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/334878 )

Change subject: Simplify error reporter mocks in StatementModificationHelperTest
......................................................................

Simplify error reporter mocks in StatementModificationHelperTest

Thanks Jakob for the idea!

Change-Id: I09c1594f6664ed1c7196c24324aa3952847cffa6
---
M repo/tests/phpunit/includes/Api/StatementModificationHelperTest.php
1 file changed, 14 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/78/334878/1

diff --git 
a/repo/tests/phpunit/includes/Api/StatementModificationHelperTest.php 
b/repo/tests/phpunit/includes/Api/StatementModificationHelperTest.php
index 088ace9..0ee109e 100644
--- a/repo/tests/phpunit/includes/Api/StatementModificationHelperTest.php
+++ b/repo/tests/phpunit/includes/Api/StatementModificationHelperTest.php
@@ -1,11 +1,11 @@
 <?php
 
+
 namespace Wikibase\Repo\Tests\Api;
 
 use ApiMain;
 use DataValues\StringValue;
-use ApiUsageException;
-use StatusValue;
+use RuntimeException;
 use ValueValidators\Result;
 use Wikibase\ChangeOp\ChangeOp;
 use Wikibase\ChangeOp\ChangeOpException;
@@ -48,12 +48,8 @@
                $errorReporter = $this->newApiErrorReporter();
                $helper = $this->getNewInstance( $errorReporter );
 
-               try {
-                       $helper->getEntityIdFromString( $invalidEntityIdString 
);
-                       $this->fail( 'Expected exception was not thrown' );
-               } catch ( ApiUsageException $ex ) {
-                       $this->assertMessage( 'invalid-entity-id', $ex );
-               }
+               $this->setExpectedException( RuntimeException::class, 
'invalid-entity-id' );
+               $helper->getEntityIdFromString( $invalidEntityIdString );
        }
 
        public function testCreateSummary() {
@@ -95,12 +91,8 @@
                $errorReporter = $this->newApiErrorReporter();
                $helper = $this->getNewInstance( $errorReporter );
 
-               try {
-                       $helper->getStatementFromEntity( 'foo', $entity );
-                       $this->fail( 'Expected exception was not thrown' );
-               } catch ( ApiUsageException $ex ) {
-                       $this->assertMessage( 'no-such-claim', $ex );
-               }
+               $this->setExpectedException( RuntimeException::class, 
'no-such-claim' );
+               $helper->getStatementFromEntity( 'foo', $entity );
        }
 
        public function 
testGetStatementFromEntity_reportsErrorForUnknownStatementGuid() {
@@ -108,12 +100,8 @@
                $errorReporter = $this->newApiErrorReporter();
                $helper = $this->getNewInstance( $errorReporter );
 
-               try {
-                       $helper->getStatementFromEntity( 'unknown', $entity );
-                       $this->fail( 'Expected exception was not thrown' );
-               } catch ( ApiUsageException $ex ) {
-                       $this->assertMessage( 'no-such-claim', $ex );
-               }
+               $this->setExpectedException( RuntimeException::class, 
'no-such-claim' );
+               $helper->getStatementFromEntity( 'unknown', $entity );
        }
 
        public function testApplyChangeOp_validatesAndAppliesChangeOp() {
@@ -142,12 +130,8 @@
                $changeOp->expects( $this->never() )
                        ->method( 'apply' );
 
-               try {
-                       $helper->applyChangeOp( $changeOp, new Item() );
-                       $this->fail( 'Expected exception was not thrown' );
-               } catch ( ApiUsageException $ex ) {
-                       $this->assertMessage( 'modification-failed', $ex );
-               }
+               $this->setExpectedException( RuntimeException::class, 
'modification-failed' );
+               $helper->applyChangeOp( $changeOp, new Item() );
        }
 
        public function testApplyChangeOp_reportsErrorWhenApplyFails() {
@@ -162,12 +146,8 @@
                $changeOp->method( 'apply' )
                        ->will( $this->throwException( new ChangeOpException() 
) );
 
-               try {
-                       $helper->applyChangeOp( $changeOp, new Item() );
-                       $this->fail( 'Expected exception was not thrown' );
-               } catch ( ApiUsageException $ex ) {
-                       $this->assertMessage( 'modification-failed', $ex );
-               }
+               $this->setExpectedException( RuntimeException::class, 
'modification-failed' );
+               $helper->applyChangeOp( $changeOp, new Item() );
        }
 
        /**
@@ -196,23 +176,15 @@
 
                $errorReporter->method( 'dieException' )
                        ->will( $this->returnCallback( function ( $exception, 
$message ) {
-                               throw new ApiUsageException( null, 
StatusValue::newFatal( $message ) );
+                               throw new RuntimeException( $message );
                        } ) );
 
                $errorReporter->method( 'dieError' )
                        ->will( $this->returnCallback( function ( $description, 
$message ) {
-                               throw new ApiUsageException( null, 
StatusValue::newFatal( $message ) );
+                               throw new RuntimeException( $message );
                        } ) );
 
                return $errorReporter;
-       }
-
-       /**
-        * @param string $expectedMessage
-        * @param ApiUsageException $actualException
-        */
-       private function assertMessage( $expectedMessage, ApiUsageException 
$actualException ) {
-               $this->assertTrue( 
$actualException->getStatusValue()->hasMessage( $expectedMessage ) );
        }
 
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/334878
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I09c1594f6664ed1c7196c24324aa3952847cffa6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to