ApiTestCase: Avoid notices about undefined indices
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 13 Aug 2014 17:47:57 +0000 (19:47 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 13 Aug 2014 17:47:57 +0000 (19:47 +0200)
We're going to throw an exception right away here, but this is still
problematic because of PHPUnit:

"By default, PHPUnit converts PHP errors, warnings, and notices that
are triggered during the execution of a test to an exception."
http://phpunit.de/manual/4.2/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.errors

Also change the exception message to something saner.

Change-Id: I766c36076d34428035be78bbb3cf36cc572b565b

tests/phpunit/includes/api/ApiTestCase.php

index b556ef8..f633315 100644 (file)
@@ -133,7 +133,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                        $session = $wgRequest->getSessionArray();
                }
 
-               if ( $session['wsToken'] ) {
+               if ( isset( $session['wsToken'] ) && $session['wsToken'] ) {
                        // add edit token to fake session
                        $session['wsEditToken'] = $session['wsToken'];
                        // add token to request parameters
@@ -141,7 +141,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
                        return $this->doApiRequest( $params, $session, false, $user );
                } else {
-                       throw new Exception( "request data not in right format" );
+                       throw new Exception( "Session token not available" );
                }
        }