]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add willRunTestCases / didRunTestCases hooks
authorepriestley <git@epriestley.com>
Wed, 6 Mar 2013 21:40:07 +0000 (13:40 -0800)
committerepriestley <git@epriestley.com>
Wed, 6 Mar 2013 21:40:07 +0000 (13:40 -0800)
Summary: These hooks allow test cases to build shared resources -- notably, database fixtures.

Test Plan: See next diff.

Reviewers: vrana

Reviewed By: vrana

CC: aran
Differential Revision: https://secure.phabricator.com/D5258

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

index 2179d5ba015adbf0de86de9046572e32ab7e20f5..1a3a110cc7dc9ef03bab5502faa906a851b69a68 100644 (file)
@@ -37,7 +37,7 @@ final class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
 
     $project_root = $this->getWorkingCopy()->getProjectRoot();
 
-    $results = array();
+    $test_cases = array();
     foreach ($run_tests as $test_class) {
       $test_case = newv($test_class, array());
       $test_case->setEnableCoverage($enable_coverage);
@@ -48,10 +48,23 @@ final class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
       if ($this->renderer) {
         $test_case->setRenderer($this->renderer);
       }
-      $results[] = $test_case->run();
+      $test_cases[] = $test_case;
     }
 
+    foreach ($test_cases as $test_case) {
+      $test_case->willRunTestCases($test_cases);
+    }
+
+    $results = array();
+    foreach ($test_cases as $test_case) {
+      $results[] = $test_case->run();
+    }
     $results = array_mergev($results);
+
+    foreach ($test_cases as $test_case) {
+      $test_case->didRunTestCases($test_cases);
+    }
+
     return $results;
   }
 
index b1cef23afc1ac3080f2943a062447216a7abade3..259aa5fe3812b20beb395313a91dadddf1b98ff2 100644 (file)
@@ -310,6 +310,29 @@ abstract class ArcanistPhutilTestCase {
   }
 
 
+  /**
+   * This hook is invoked once, before any test cases execute. It gives you
+   * an opportunity to perform setup steps for the entire suite of test cases.
+   *
+   * @return void
+   * @task hook
+   */
+  public function willRunTestCases(array $test_cases) {
+    return;
+  }
+
+
+  /**
+   * This hook is invoked once, after all test cases execute.
+   *
+   * @return void
+   * @task hook
+   */
+  public function didRunTestCases(array $test_cases) {
+    return;
+  }
+
+
 /* -(  Internals  )---------------------------------------------------------- */