diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index f9af13b0b8..6b5b263a8a 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -293,6 +293,7 @@ final class PhabricatorEnv { $source = self::$sourceStack->popSource(); $stack_key = spl_object_hash($source); if ($stack_key !== $key) { + self::$sourceStack->pushSource($source); throw new Exception( "Scoped environments were destroyed in a diffent order than they ". "were initialized."); diff --git a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php index 4adbe11459..13b5d9c5e2 100644 --- a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php +++ b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php @@ -130,15 +130,11 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase { public function testOverrideOrder() { $outer = PhabricatorEnv::beginScopedEnv(); - $middle = PhabricatorEnv::beginScopedEnv(); $inner = PhabricatorEnv::beginScopedEnv(); $caught = null; try { - if (phutil_is_hiphop_runtime()) { - $middle->__destruct(); - } - unset($middle); + $outer->__destruct(); } catch (Exception $ex) { $caught = $ex; } @@ -149,25 +145,11 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase { "Destroying a scoped environment which is not on the top of the stack ". "should throw."); - $caught = null; - try { - if (phutil_is_hiphop_runtime()) { - $inner->__destruct(); - } - unset($inner); - } catch (Exception $ex) { - $caught = $ex; + if (phutil_is_hiphop_runtime()) { + $inner->__destruct(); } + unset($inner); - $this->assertEqual( - true, - $caught instanceof Exception, - "Destroying a scoped environment which is not on the top of the stack ". - "should throw."); - - // 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(); } diff --git a/src/infrastructure/testing/PhabricatorTestCase.php b/src/infrastructure/testing/PhabricatorTestCase.php index 660fd17670..dbdd1ef126 100644 --- a/src/infrastructure/testing/PhabricatorTestCase.php +++ b/src/infrastructure/testing/PhabricatorTestCase.php @@ -91,6 +91,9 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase { } try { + if (phutil_is_hiphop_runtime()) { + $this->env->__destruct(); + } unset($this->env); } catch (Exception $ex) { throw new Exception(