From bb96115fa6a8fba41ccd2b2c81a836e10dbbb895 Mon Sep 17 00:00:00 2001 From: Edward Speyer Date: Tue, 1 May 2012 13:11:45 -0700 Subject: [PATCH] Explicitly call __destruct() in PhabricatorEnvTestCase Summary: Required in order to run tests successfully in the HipHop interpreter. Similar to D2362. Test Plan: Run the tests in an HipHop runtime. Reviewers: epriestley Reviewed By: epriestley CC: jungejason, aran, Koolvin, vrana Differential Revision: https://secure.phabricator.com/D2365 --- src/infrastructure/env/PhabricatorScopedEnv.php | 6 +++++- .../env/__tests__/PhabricatorEnvTestCase.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/env/PhabricatorScopedEnv.php b/src/infrastructure/env/PhabricatorScopedEnv.php index 4e92ac2bbe..4e441778b2 100644 --- a/src/infrastructure/env/PhabricatorScopedEnv.php +++ b/src/infrastructure/env/PhabricatorScopedEnv.php @@ -26,6 +26,7 @@ final class PhabricatorScopedEnv { private $key; + private $isPopped = false; /* -( Overriding Environment Configuration )------------------------------- */ @@ -66,7 +67,10 @@ final class PhabricatorScopedEnv { * @task internal */ public function __destruct() { - PhabricatorEnv::popEnvironment($this->key); + if (!$this->isPopped) { + PhabricatorEnv::popEnvironment($this->key); + $this->isPopped = true; + } } } diff --git a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php index a5b1814285..9a01ea313a 100644 --- a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php +++ b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php @@ -62,9 +62,15 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase { $inner = PhabricatorEnv::beginScopedEnv(); $inner->overrideEnvConfig('test.value', 2); $this->assertEqual(2, PhabricatorEnv::getEnvConfig('test.value')); + if (phutil_is_hiphop_runtime()) { + $inner->__destruct(); + } unset($inner); $this->assertEqual(1, PhabricatorEnv::getEnvConfig('test.value')); + if (phutil_is_hiphop_runtime()) { + $outer->__destruct(); + } unset($outer); } @@ -75,6 +81,9 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase { $caught = null; try { + if (phutil_is_hiphop_runtime()) { + $middle->__destruct(); + } unset($middle); } catch (Exception $ex) { $caught = $ex; @@ -88,6 +97,9 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase { $caught = null; try { + if (phutil_is_hiphop_runtime()) { + $inner->__destruct(); + } unset($inner); } catch (Exception $ex) { $caught = $ex; @@ -102,6 +114,9 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase { // Although we popped the other two out-of-order, we still expect to end // up in the right state after handling the exceptions, so this should // execute without issues. + if (phutil_is_hiphop_runtime()) { + $outer->__destruct(); + } unset($outer); }