Added assertException method to MediaWikiTestCase
authorjeroendedauw <jeroendedauw@gmail.com>
Thu, 29 Nov 2012 17:03:03 +0000 (18:03 +0100)
committerjeroendedauw <jeroendedauw@gmail.com>
Fri, 30 Nov 2012 10:35:08 +0000 (11:35 +0100)
Change-Id: I3ce667b4405241c66c5a979863d1cea2cf39956b

tests/phpunit/MediaWikiTestCase.php

index b6a4a94..a594202 100644 (file)
@@ -830,4 +830,32 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        $this->markTestSkipped( "Skip test, since diff3 is not configured" );
                }
        }
+
+       /**
+        * Asserts that an exception of the specified type occurs when running
+        * the provided code.
+        *
+        * @since 1.21
+        *
+        * @param callable $code
+        * @param string $expected
+        * @param string $message
+        */
+       protected function assertException( $code, $expected = 'Exception', $message = '' ) {
+               $pokemons = null;
+
+               try {
+                       call_user_func( $code );
+               }
+               catch ( Exception $pokemons ) {
+                       // Gotta Catch 'Em All!
+               }
+
+               if ( $message === '' ) {
+                       $message = 'An exception of type "' . $expected . '" should have been thrown';
+               }
+
+               $this->assertInstanceOf( $expected, $pokemons, $message );
+       }
+
 }