]> khamidou — GitHub mirrors - arcanist.git/commitdiff
[ArcanistPhutilTestCase] add ->assertException() to the base test case
authorEdward Speyer <edward@fb.com>
Thu, 8 Mar 2012 22:54:49 +0000 (14:54 -0800)
committerEdward Speyer <edward@fb.com>
Thu, 8 Mar 2012 23:14:30 +0000 (15:14 -0800)
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

src/unit/engine/phutil/testcase/ArcanistPhutilTestCase.php

index a5b4f5ddf8a9fd0939821a30d9d7e6fb7c9cb0e5..2895d5c654baf488cbccbf2d22d05decea86d12c 100644 (file)
@@ -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