From: Edward Speyer Date: Thu, 8 Mar 2012 22:54:49 +0000 (-0800) Subject: [ArcanistPhutilTestCase] add ->assertException() to the base test case X-Git-Tag: conduit-4~113 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=bdfc021d391beb13d7e6c58be2302b360dc255b8;p=arcanist.git [ArcanistPhutilTestCase] add ->assertException() to the base test case Summary: Simpler assert function for asserting a type of exception was raised. Test Plan: Wrote this for (and tested it with) D1836. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1837 --- diff --git a/src/unit/engine/phutil/testcase/ArcanistPhutilTestCase.php b/src/unit/engine/phutil/testcase/ArcanistPhutilTestCase.php index a5b4f5dd..2895d5c6 100644 --- a/src/unit/engine/phutil/testcase/ArcanistPhutilTestCase.php +++ b/src/unit/engine/phutil/testcase/ArcanistPhutilTestCase.php @@ -113,6 +113,25 @@ abstract class ArcanistPhutilTestCase { /* -( Exception Handling )------------------------------------------------- */ + /** + * This simplest way to assert exceptions are thrown. + * + * @param exception The expected exception. + * @param callable The thing which throws the exception. + * + * @return void + * @task exceptions + */ + final protected function assertException($expected_exception_class, + $callable) { + $this->tryTestCases( + array('assertException' => array()), + array(false), + $callable, + $expected_exception_class + ); + } + /** * Straightforward method for writing unit tests which check if some block of * code throws an exception. For example, this allows you to test the