From: jeroendedauw Date: Thu, 29 Nov 2012 17:03:03 +0000 (+0100) Subject: Added assertException method to MediaWikiTestCase X-Git-Tag: 1.31.0-rc.0~21462^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=ba9a170df2b785c1e5a3e277caba71ef89216d07;p=lhc%2Fweb%2Fwiklou.git Added assertException method to MediaWikiTestCase Change-Id: I3ce667b4405241c66c5a979863d1cea2cf39956b --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index b6a4a944ee..a594202106 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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 ); + } + }