From c8274907083a363a7764d8f1ecd4ccdf627d3407 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 6 Mar 2013 13:40:07 -0800 Subject: [PATCH] Add willRunTestCases / didRunTestCases hooks 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 | 17 ++++++++++++-- .../engine/phutil/ArcanistPhutilTestCase.php | 23 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/unit/engine/PhutilUnitTestEngine.php b/src/unit/engine/PhutilUnitTestEngine.php index 2179d5ba..1a3a110c 100644 --- a/src/unit/engine/PhutilUnitTestEngine.php +++ b/src/unit/engine/PhutilUnitTestEngine.php @@ -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; } diff --git a/src/unit/engine/phutil/ArcanistPhutilTestCase.php b/src/unit/engine/phutil/ArcanistPhutilTestCase.php index b1cef23a..259aa5fe 100644 --- a/src/unit/engine/phutil/ArcanistPhutilTestCase.php +++ b/src/unit/engine/phutil/ArcanistPhutilTestCase.php @@ -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 )---------------------------------------------------------- */